1 ; This test case tests the InstructionCombining optimization that 2 ; reduces things like: 3 ; %Y = sext i8 %X to i32 4 ; %C = icmp ult i32 %Y, 1024 5 ; to 6 ; %C = i1 true 7 ; It includes test cases for different constant values, signedness of the 8 ; cast operands, and types of setCC operators. In all cases, the cast should 9 ; be eliminated. In many cases the setCC is also eliminated based on the 10 ; constant value and the range of the casted value. 11 ; 12 ; RUN: opt < %s -instcombine -S | FileCheck %s 13 ; END. 14 define i1 @lt_signed_to_large_unsigned(i8 %SB) { 15 %Y = sext i8 %SB to i32 ; <i32> [#uses=1] 16 %C = icmp ult i32 %Y, 1024 ; <i1> [#uses=1] 17 ret i1 %C 18 ; CHECK: %C1 = icmp sgt i8 %SB, -1 19 ; CHECK: ret i1 %C1 20 } 21 22 define i1 @lt_signed_to_large_signed(i8 %SB) { 23 %Y = sext i8 %SB to i32 ; <i32> [#uses=1] 24 %C = icmp slt i32 %Y, 1024 ; <i1> [#uses=1] 25 ret i1 %C 26 ; CHECK: ret i1 true 27 } 28 29 define i1 @lt_signed_to_large_negative(i8 %SB) { 30 %Y = sext i8 %SB to i32 ; <i32> [#uses=1] 31 %C = icmp slt i32 %Y, -1024 ; <i1> [#uses=1] 32 ret i1 %C 33 ; CHECK: ret i1 false 34 } 35 36 define i1 @lt_signed_to_small_unsigned(i8 %SB) { 37 %Y = sext i8 %SB to i32 38 %C = icmp ult i32 %Y, 17 39 ret i1 %C 40 ; CHECK: %C = icmp ult i8 %SB, 17 41 ; CHECK: ret i1 %C 42 } 43 44 define i1 @lt_signed_to_small_signed(i8 %SB) { 45 %Y = sext i8 %SB to i32 ; <i32> [#uses=1] 46 %C = icmp slt i32 %Y, 17 ; <i1> [#uses=1] 47 ret i1 %C 48 ; CHECK: %C = icmp slt i8 %SB, 17 49 ; CHECK: ret i1 %C 50 } 51 define i1 @lt_signed_to_small_negative(i8 %SB) { 52 %Y = sext i8 %SB to i32 ; <i32> [#uses=1] 53 %C = icmp slt i32 %Y, -17 ; <i1> [#uses=1] 54 ret i1 %C 55 ; CHECK: %C = icmp slt i8 %SB, -17 56 ; CHECK: ret i1 %C 57 } 58 59 define i1 @lt_unsigned_to_large_unsigned(i8 %SB) { 60 %Y = zext i8 %SB to i32 ; <i32> [#uses=1] 61 %C = icmp ult i32 %Y, 1024 ; <i1> [#uses=1] 62 ret i1 %C 63 ; CHECK: ret i1 true 64 } 65 66 define i1 @lt_unsigned_to_large_signed(i8 %SB) { 67 %Y = zext i8 %SB to i32 ; <i32> [#uses=1] 68 %C = icmp slt i32 %Y, 1024 ; <i1> [#uses=1] 69 ret i1 %C 70 ; CHECK: ret i1 true 71 } 72 73 define i1 @lt_unsigned_to_large_negative(i8 %SB) { 74 %Y = zext i8 %SB to i32 ; <i32> [#uses=1] 75 %C = icmp slt i32 %Y, -1024 ; <i1> [#uses=1] 76 ret i1 %C 77 ; CHECK: ret i1 false 78 } 79 80 define i1 @lt_unsigned_to_small_unsigned(i8 %SB) { 81 %Y = zext i8 %SB to i32 ; <i32> [#uses=1] 82 %C = icmp ult i32 %Y, 17 ; <i1> [#uses=1] 83 ret i1 %C 84 ; CHECK: %C = icmp ult i8 %SB, 17 85 ; CHECK: ret i1 %C 86 } 87 88 define i1 @lt_unsigned_to_small_signed(i8 %SB) { 89 %Y = zext i8 %SB to i32 90 %C = icmp slt i32 %Y, 17 91 ret i1 %C 92 ; CHECK: %C = icmp ult i8 %SB, 17 93 ; CHECK: ret i1 %C 94 } 95 96 define i1 @lt_unsigned_to_small_negative(i8 %SB) { 97 %Y = zext i8 %SB to i32 ; <i32> [#uses=1] 98 %C = icmp slt i32 %Y, -17 ; <i1> [#uses=1] 99 ret i1 %C 100 ; CHECK: ret i1 false 101 } 102 103 define i1 @gt_signed_to_large_unsigned(i8 %SB) { 104 %Y = sext i8 %SB to i32 ; <i32> [#uses=1] 105 %C = icmp ugt i32 %Y, 1024 ; <i1> [#uses=1] 106 ret i1 %C 107 ; CHECK: %C = icmp slt i8 %SB, 0 108 ; CHECK: ret i1 %C 109 } 110 111 define i1 @gt_signed_to_large_signed(i8 %SB) { 112 %Y = sext i8 %SB to i32 ; <i32> [#uses=1] 113 %C = icmp sgt i32 %Y, 1024 ; <i1> [#uses=1] 114 ret i1 %C 115 ; CHECK: ret i1 false 116 } 117 118 define i1 @gt_signed_to_large_negative(i8 %SB) { 119 %Y = sext i8 %SB to i32 ; <i32> [#uses=1] 120 %C = icmp sgt i32 %Y, -1024 ; <i1> [#uses=1] 121 ret i1 %C 122 ; CHECK: ret i1 true 123 } 124 125 define i1 @gt_signed_to_small_unsigned(i8 %SB) { 126 %Y = sext i8 %SB to i32 127 %C = icmp ugt i32 %Y, 17 128 ret i1 %C 129 ; CHECK: %C = icmp ugt i8 %SB, 17 130 ; CHECK: ret i1 %C 131 } 132 133 define i1 @gt_signed_to_small_signed(i8 %SB) { 134 %Y = sext i8 %SB to i32 ; <i32> [#uses=1] 135 %C = icmp sgt i32 %Y, 17 ; <i1> [#uses=1] 136 ret i1 %C 137 ; CHECK: %C = icmp sgt i8 %SB, 17 138 ; CHECK: ret i1 %C 139 } 140 141 define i1 @gt_signed_to_small_negative(i8 %SB) { 142 %Y = sext i8 %SB to i32 ; <i32> [#uses=1] 143 %C = icmp sgt i32 %Y, -17 ; <i1> [#uses=1] 144 ret i1 %C 145 ; CHECK: %C = icmp sgt i8 %SB, -17 146 ; CHECK: ret i1 %C 147 } 148 149 define i1 @gt_unsigned_to_large_unsigned(i8 %SB) { 150 %Y = zext i8 %SB to i32 ; <i32> [#uses=1] 151 %C = icmp ugt i32 %Y, 1024 ; <i1> [#uses=1] 152 ret i1 %C 153 ; CHECK: ret i1 false 154 } 155 156 define i1 @gt_unsigned_to_large_signed(i8 %SB) { 157 %Y = zext i8 %SB to i32 ; <i32> [#uses=1] 158 %C = icmp sgt i32 %Y, 1024 ; <i1> [#uses=1] 159 ret i1 %C 160 ; CHECK: ret i1 false 161 } 162 163 define i1 @gt_unsigned_to_large_negative(i8 %SB) { 164 %Y = zext i8 %SB to i32 ; <i32> [#uses=1] 165 %C = icmp sgt i32 %Y, -1024 ; <i1> [#uses=1] 166 ret i1 %C 167 ; CHECK: ret i1 true 168 } 169 170 define i1 @gt_unsigned_to_small_unsigned(i8 %SB) { 171 %Y = zext i8 %SB to i32 ; <i32> [#uses=1] 172 %C = icmp ugt i32 %Y, 17 ; <i1> [#uses=1] 173 ret i1 %C 174 ; CHECK: %C = icmp ugt i8 %SB, 17 175 ; CHECK: ret i1 %C 176 } 177 178 define i1 @gt_unsigned_to_small_signed(i8 %SB) { 179 %Y = zext i8 %SB to i32 180 %C = icmp sgt i32 %Y, 17 181 ret i1 %C 182 ; CHECK: %C = icmp ugt i8 %SB, 17 183 ; CHECK: ret i1 %C 184 } 185 186 define i1 @gt_unsigned_to_small_negative(i8 %SB) { 187 %Y = zext i8 %SB to i32 ; <i32> [#uses=1] 188 %C = icmp sgt i32 %Y, -17 ; <i1> [#uses=1] 189 ret i1 %C 190 ; CHECK: ret i1 true 191 } 192 193