From: Sanjay Patel Date: Thu, 13 Apr 2017 15:46:39 +0000 (+0000) Subject: [InstCombine] add/move tests for or-of-icmps; NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=718498681fb464f86d9b3adcf2157b3735ec4dda;p=llvm [InstCombine] add/move tests for or-of-icmps; NFC If we had these tests, the bug caused by https://reviews.llvm.org/rL299851 would have been caught sooner. There's also an assert in the code that should have caught that bug, but the assert line itself has a bug. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300201 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Transforms/InstCombine/icmp.ll b/test/Transforms/InstCombine/icmp.ll index b1dc395b3d9..edfa9a10291 100644 --- a/test/Transforms/InstCombine/icmp.ll +++ b/test/Transforms/InstCombine/icmp.ll @@ -1123,19 +1123,6 @@ define i1 @test68(i32 %x) { ret i1 %cmp } -; PR14708 -define i1 @test69(i32 %c) { -; CHECK-LABEL: @test69( -; CHECK-NEXT: [[TMP1:%.*]] = or i32 %c, 32 -; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 97 -; CHECK-NEXT: ret i1 [[TMP2]] -; - %1 = icmp eq i32 %c, 97 - %2 = icmp eq i32 %c, 65 - %3 = or i1 %1, %2 - ret i1 %3 -} - ; PR15940 define i1 @test70(i32 %X) { ; CHECK-LABEL: @test70( diff --git a/test/Transforms/InstCombine/or.ll b/test/Transforms/InstCombine/or.ll index 2ac6f5b1104..bf575418ce9 100644 --- a/test/Transforms/InstCombine/or.ll +++ b/test/Transforms/InstCombine/or.ll @@ -207,31 +207,79 @@ define <2 x i1> @test18vec(<2 x i32> %A) { ret <2 x i1> %D } -define i1 @test19(i32 %A) { -; CHECK-LABEL: @test19( -; CHECK-NEXT: [[TMP1:%.*]] = or i32 %A, 1 +; if LHSC and RHSC differ only by one bit: +; (A == C1 || A == C2) -> (A | (C1 ^ C2)) == C2 +; PR14708: https://bugs.llvm.org/show_bug.cgi?id=14708 + +define i1 @cmp_eq_with_one_bit_diff_constants1(i32 %x) { +; CHECK-LABEL: @cmp_eq_with_one_bit_diff_constants1( +; CHECK-NEXT: [[TMP1:%.*]] = or i32 %x, 1 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 51 ; CHECK-NEXT: ret i1 [[TMP2]] ; - %B = icmp eq i32 %A, 50 - %C = icmp eq i32 %A, 51 - %D = or i1 %B, %C - ret i1 %D + %cmp1 = icmp eq i32 %x, 50 + %cmp2 = icmp eq i32 %x, 51 + %or = or i1 %cmp1, %cmp2 + ret i1 %or +} + +; The constants are not necessarily off-by-one, just off-by-one-bit. + +define i1 @cmp_eq_with_one_bit_diff_constants2(i32 %x) { +; CHECK-LABEL: @cmp_eq_with_one_bit_diff_constants2( +; CHECK-NEXT: [[TMP1:%.*]] = or i32 %x, 32 +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 97 +; CHECK-NEXT: ret i1 [[TMP2]] +; + %cmp1 = icmp eq i32 %x, 97 + %cmp2 = icmp eq i32 %x, 65 + %or = or i1 %cmp1, %cmp2 + ret i1 %or +} + +; Make sure the constants are treated as unsigned when comparing them. + +define i1 @cmp_eq_with_one_bit_diff_constants3(i8 %x) { +; CHECK-LABEL: @cmp_eq_with_one_bit_diff_constants3( +; CHECK-NEXT: [[TMP1:%.*]] = or i8 %x, -128 +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i8 [[TMP1]], -2 +; CHECK-NEXT: ret i1 [[TMP2]] +; + %cmp1 = icmp eq i8 %x, 254 + %cmp2 = icmp eq i8 %x, 126 + %or = or i1 %cmp1, %cmp2 + ret i1 %or +} + +; Use an 'add' to eliminate an icmp if the constants are off-by-one (not off-by-one-bit). +; (X == 13 | X == 14) -> X-13