1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2 ; This test makes sure that all icmp instructions are eliminated. 3 ; RUN: opt < %s -instcombine -S | FileCheck %s 4 5 @X = external global i32 6 7 define i1 @test1(i32 %A) { 8 ; CHECK-LABEL: @test1( 9 ; CHECK-NEXT: ret i1 false 10 ; 11 %B = icmp eq i32 %A, %A 12 ; Never true 13 %C = icmp eq i32* @X, null 14 %D = and i1 %B, %C 15 ret i1 %D 16 } 17 18 define i1 @test2(i32 %A) { 19 ; CHECK-LABEL: @test2( 20 ; CHECK-NEXT: ret i1 true 21 ; 22 %B = icmp ne i32 %A, %A 23 ; Never false 24 %C = icmp ne i32* @X, null 25 %D = or i1 %B, %C 26 ret i1 %D 27 } 28 29 define i1 @test3(i32 %A) { 30 ; CHECK-LABEL: @test3( 31 ; CHECK-NEXT: ret i1 false 32 ; 33 %B = icmp slt i32 %A, %A 34 ret i1 %B 35 } 36 37 38 define i1 @test4(i32 %A) { 39 ; CHECK-LABEL: @test4( 40 ; CHECK-NEXT: ret i1 false 41 ; 42 %B = icmp sgt i32 %A, %A 43 ret i1 %B 44 } 45 46 define i1 @test5(i32 %A) { 47 ; CHECK-LABEL: @test5( 48 ; CHECK-NEXT: ret i1 true 49 ; 50 %B = icmp sle i32 %A, %A 51 ret i1 %B 52 } 53 54 define i1 @test6(i32 %A) { 55 ; CHECK-LABEL: @test6( 56 ; CHECK-NEXT: ret i1 true 57 ; 58 %B = icmp sge i32 %A, %A 59 ret i1 %B 60 } 61 62 define i1 @test7(i32 %A) { 63 ; CHECK-LABEL: @test7( 64 ; CHECK-NEXT: ret i1 true 65 ; 66 %B = icmp uge i32 %A, 0 67 ret i1 %B 68 } 69 70 define i1 @test8(i32 %A) { 71 ; CHECK-LABEL: @test8( 72 ; CHECK-NEXT: ret i1 false 73 ; 74 %B = icmp ult i32 %A, 0 75 ret i1 %B 76 } 77 78 ;; test operations on boolean values these should all be eliminated$a 79 define i1 @test9(i1 %A) { 80 ; CHECK-LABEL: @test9( 81 ; CHECK-NEXT: ret i1 false 82 ; 83 %B = icmp ult i1 %A, false 84 ret i1 %B 85 } 86 87 define i1 @test10(i1 %A) { 88 ; CHECK-LABEL: @test10( 89 ; CHECK-NEXT: ret i1 false 90 ; 91 %B = icmp ugt i1 %A, true 92 ret i1 %B 93 } 94 95 define i1 @test11(i1 %A) { 96 ; CHECK-LABEL: @test11( 97 ; CHECK-NEXT: ret i1 true 98 ; 99 %B = icmp ule i1 %A, true 100 ret i1 %B 101 } 102 103 define i1 @test12(i1 %A) { 104 ; CHECK-LABEL: @test12( 105 ; CHECK-NEXT: ret i1 true 106 ; 107 %B = icmp uge i1 %A, false 108 ret i1 %B 109 } 110 111 define i1 @test13(i1 %A, i1 %B) { 112 ; CHECK-LABEL: @test13( 113 ; CHECK-NEXT: [[CTMP:%.*]] = xor i1 %B, true 114 ; CHECK-NEXT: [[C:%.*]] = or i1 [[CTMP]], %A 115 ; CHECK-NEXT: ret i1 [[C]] 116 ; 117 %C = icmp uge i1 %A, %B 118 ret i1 %C 119 } 120 121 define <2 x i1> @test13vec(<2 x i1> %A, <2 x i1> %B) { 122 ; CHECK-LABEL: @test13vec( 123 ; CHECK-NEXT: [[CTMP:%.*]] = xor <2 x i1> %B, <i1 true, i1 true> 124 ; CHECK-NEXT: [[C:%.*]] = or <2 x i1> [[CTMP]], %A 125 ; CHECK-NEXT: ret <2 x i1> [[C]] 126 ; 127 %C = icmp uge <2 x i1> %A, %B 128 ret <2 x i1> %C 129 } 130 131 define i1 @test14(i1 %A, i1 %B) { 132 ; CHECK-LABEL: @test14( 133 ; CHECK-NEXT: [[CTMP:%.*]] = xor i1 %A, %B 134 ; CHECK-NEXT: [[C:%.*]] = xor i1 [[CTMP]], true 135 ; CHECK-NEXT: ret i1 [[C]] 136 ; 137 %C = icmp eq i1 %A, %B 138 ret i1 %C 139 } 140 141 define <3 x i1> @test14vec(<3 x i1> %A, <3 x i1> %B) { 142 ; CHECK-LABEL: @test14vec( 143 ; CHECK-NEXT: [[CTMP:%.*]] = xor <3 x i1> %A, %B 144 ; CHECK-NEXT: [[C:%.*]] = xor <3 x i1> [[CTMP]], <i1 true, i1 true, i1 true> 145 ; CHECK-NEXT: ret <3 x i1> [[C]] 146 ; 147 %C = icmp eq <3 x i1> %A, %B 148 ret <3 x i1> %C 149 } 150 151 define i1 @test16(i32 %A) { 152 ; CHECK-LABEL: @test16( 153 ; CHECK-NEXT: ret i1 false 154 ; 155 %B = and i32 %A, 5 156 ; Is never true 157 %C = icmp eq i32 %B, 8 158 ret i1 %C 159 } 160 161 define i1 @test17(i8 %A) { 162 ; CHECK-LABEL: @test17( 163 ; CHECK-NEXT: ret i1 false 164 ; 165 %B = or i8 %A, 1 166 ; Always false 167 %C = icmp eq i8 %B, 2 168 ret i1 %C 169 } 170 171 define i1 @test18(i1 %C, i32 %a) { 172 ; CHECK-LABEL: @test18( 173 ; CHECK-NEXT: entry: 174 ; CHECK-NEXT: br i1 %C, label %endif, label %else 175 ; CHECK: else: 176 ; CHECK-NEXT: br label %endif 177 ; CHECK: endif: 178 ; CHECK-NEXT: ret i1 true 179 ; 180 entry: 181 br i1 %C, label %endif, label %else 182 183 else: 184 br label %endif 185 186 endif: 187 %b.0 = phi i32 [ 0, %entry ], [ 1, %else ] 188 %tmp.4 = icmp slt i32 %b.0, 123 189 ret i1 %tmp.4 190 } 191 192 define i1 @test19(i1 %A, i1 %B) { 193 ; CHECK-LABEL: @test19( 194 ; CHECK-NEXT: [[CTMP:%.*]] = xor i1 %A, %B 195 ; CHECK-NEXT: [[C:%.*]] = xor i1 [[CTMP]], true 196 ; CHECK-NEXT: ret i1 [[C]] 197 ; 198 %a = zext i1 %A to i32 199 %b = zext i1 %B to i32 200 %C = icmp eq i32 %a, %b 201 ret i1 %C 202 } 203 204 define i32 @test20(i32 %A) { 205 ; CHECK-LABEL: @test20( 206 ; CHECK-NEXT: [[B:%.*]] = and i32 %A, 1 207 ; CHECK-NEXT: ret i32 [[B]] 208 ; 209 %B = and i32 %A, 1 210 %C = icmp ne i32 %B, 0 211 %D = zext i1 %C to i32 212 ret i32 %D 213 } 214 215 define i32 @test21(i32 %a) { 216 ; CHECK-LABEL: @test21( 217 ; CHECK-NEXT: [[TMP_6:%.*]] = lshr i32 %a, 2 218 ; CHECK-NEXT: [[TMP_6_LOBIT:%.*]] = and i32 [[TMP_6]], 1 219 ; CHECK-NEXT: ret i32 [[TMP_6_LOBIT]] 220 ; 221 %tmp.6 = and i32 %a, 4 222 %not.tmp.7 = icmp ne i32 %tmp.6, 0 223 %retval = zext i1 %not.tmp.7 to i32 224 ret i32 %retval 225 } 226 227 define i1 @test22(i32 %A, i32 %X) { 228 ; CHECK-LABEL: @test22( 229 ; CHECK-NEXT: ret i1 true 230 ; 231 %B = and i32 %A, 100663295 232 %C = icmp ult i32 %B, 268435456 233 %Y = and i32 %X, 7 234 %Z = icmp sgt i32 %Y, -1 235 %R = or i1 %C, %Z 236 ret i1 %R 237 } 238 239 define i32 @test23(i32 %a) { 240 ; CHECK-LABEL: @test23( 241 ; CHECK-NEXT: [[TMP_1:%.*]] = and i32 %a, 1 242 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[TMP_1]], 1 243 ; CHECK-NEXT: ret i32 [[TMP1]] 244 ; 245 %tmp.1 = and i32 %a, 1 246 %tmp.2 = icmp eq i32 %tmp.1, 0 247 %tmp.3 = zext i1 %tmp.2 to i32 248 ret i32 %tmp.3 249 } 250 251 define i32 @test24(i32 %a) { 252 ; CHECK-LABEL: @test24( 253 ; CHECK-NEXT: [[TMP_1:%.*]] = lshr i32 %a, 2 254 ; CHECK-NEXT: [[TMP_1_LOBIT:%.*]] = and i32 [[TMP_1]], 1 255 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[TMP_1_LOBIT]], 1 256 ; CHECK-NEXT: ret i32 [[TMP1]] 257 ; 258 %tmp1 = and i32 %a, 4 259 %tmp.1 = lshr i32 %tmp1, 2 260 %tmp.2 = icmp eq i32 %tmp.1, 0 261 %tmp.3 = zext i1 %tmp.2 to i32 262 ret i32 %tmp.3 263 } 264 265 define i1 @test25(i32 %A) { 266 ; CHECK-LABEL: @test25( 267 ; CHECK-NEXT: ret i1 false 268 ; 269 %B = and i32 %A, 2 270 %C = icmp ugt i32 %B, 2 271 ret i1 %C 272 } 273 274