[llvm] r254518 - Do (A == C1 || A == C2) -> (A & ~(C1 ^ C2)) == C1 rather than (A == C1 || A == C2) -> (A | (C1 ^ C2)) == C2 when C1 ^ C2 is a power of 2.
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 2 08:15:08 PST 2015
Author: majnemer
Date: Wed Dec 2 10:15:07 2015
New Revision: 254518
URL: http://llvm.org/viewvc/llvm-project?rev=254518&view=rev
Log:
Do (A == C1 || A == C2) -> (A & ~(C1 ^ C2)) == C1 rather than (A == C1 || A == C2) -> (A | (C1 ^ C2)) == C2 when C1 ^ C2 is a power of 2.
Differential Revision: http://reviews.llvm.org/D14223
Patch by Amaury SECHET!
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/trunk/test/Transforms/InstCombine/icmp.ll
llvm/trunk/test/Transforms/InstCombine/load-cmp.ll
llvm/trunk/test/Transforms/InstCombine/or.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=254518&r1=254517&r2=254518&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Wed Dec 2 10:15:07 2015
@@ -1962,14 +1962,14 @@ Value *InstCombiner::FoldOrOfICmps(ICmpI
case ICmpInst::ICMP_EQ:
if (LHS->getOperand(0) == RHS->getOperand(0)) {
// if LHSCst and RHSCst differ only by one bit:
- // (A == C1 || A == C2) -> (A & ~(C1 ^ C2)) == C1
+ // (A == C1 || A == C2) -> (A | (C1 ^ C2)) == C2
assert(LHSCst->getValue().ule(LHSCst->getValue()));
APInt Xor = LHSCst->getValue() ^ RHSCst->getValue();
if (Xor.isPowerOf2()) {
- Value *NegCst = Builder->getInt(~Xor);
- Value *And = Builder->CreateAnd(LHS->getOperand(0), NegCst);
- return Builder->CreateICmp(ICmpInst::ICMP_EQ, And, LHSCst);
+ Value *Cst = Builder->getInt(Xor);
+ Value *Or = Builder->CreateOr(LHS->getOperand(0), Cst);
+ return Builder->CreateICmp(ICmpInst::ICMP_EQ, Or, RHSCst);
}
}
Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=254518&r1=254517&r2=254518&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Wed Dec 2 10:15:07 2015
@@ -819,8 +819,8 @@ define i1 @test68(i32 %x) nounwind uwtab
; PR14708
; CHECK-LABEL: @test69(
-; CHECK: %1 = and i32 %c, -33
-; CHECK: %2 = icmp eq i32 %1, 65
+; CHECK: %1 = or i32 %c, 32
+; CHECK: %2 = icmp eq i32 %1, 97
; CHECK: ret i1 %2
define i1 @test69(i32 %c) nounwind uwtable {
%1 = icmp eq i32 %c, 97
Modified: llvm/trunk/test/Transforms/InstCombine/load-cmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/load-cmp.ll?rev=254518&r1=254517&r2=254518&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/load-cmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/load-cmp.ll Wed Dec 2 10:15:07 2015
@@ -148,8 +148,8 @@ define i1 @test8(i32 %X) {
%S = icmp eq i16 %R, 0
ret i1 %S
; CHECK-LABEL: @test8(
-; CHECK-NEXT: and i32 %X, -2
-; CHECK-NEXT: icmp eq i32 {{.*}}, 8
+; CHECK-NEXT: or i32 %X, 1
+; CHECK-NEXT: icmp eq i32 {{.*}}, 9
; CHECK-NEXT: ret i1
}
Modified: llvm/trunk/test/Transforms/InstCombine/or.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or.ll?rev=254518&r1=254517&r2=254518&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/or.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/or.ll Wed Dec 2 10:15:07 2015
@@ -182,7 +182,7 @@ define i1 @test19(i32 %A) {
%D = or i1 %B, %C
ret i1 %D
; CHECK-LABEL: @test19(
-; CHECK: and i32
+; CHECK: or i32
; CHECK: icmp eq
; CHECK: ret i1
}
More information about the llvm-commits
mailing list