[llvm] r277752 - [InstCombine] use m_APInt to allow icmp eq (or X, C1), C2 folds for splat constant vectors
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 4 12:12:12 PDT 2016
Author: spatel
Date: Thu Aug 4 14:12:12 2016
New Revision: 277752
URL: http://llvm.org/viewvc/llvm-project?rev=277752&view=rev
Log:
[InstCombine] use m_APInt to allow icmp eq (or X, C1), C2 folds for splat constant vectors
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/icmp.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=277752&r1=277751&r2=277752&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Thu Aug 4 14:12:12 2016
@@ -2276,20 +2276,18 @@ Instruction *InstCombiner::foldICmpEqual
}
}
break;
- case Instruction::Or:
- // FIXME: Vectors are excluded by ConstantInt.
- if (ConstantInt *BOC = dyn_cast<ConstantInt>(BOp1)) {
+ case Instruction::Or: {
+ const APInt *BOC;
+ if (match(BOp1, m_APInt(BOC)) && BO->hasOneUse() && RHS->isAllOnesValue()) {
// Comparing if all bits outside of a constant mask are set?
// Replace (X | C) == -1 with (X & ~C) == ~C.
// This removes the -1 constant.
- if (BO->hasOneUse() && RHS->isAllOnesValue()) {
- Constant *NotBOC = ConstantExpr::getNot(BOC);
- Value *And = Builder->CreateAnd(BOp0, NotBOC);
- return new ICmpInst(ICI.getPredicate(), And, NotBOC);
- }
+ Constant *NotBOC = ConstantExpr::getNot(cast<Constant>(BOp1));
+ Value *And = Builder->CreateAnd(BOp0, NotBOC);
+ return new ICmpInst(ICI.getPredicate(), And, NotBOC);
}
break;
-
+ }
case Instruction::And:
// FIXME: Vectors are excluded by ConstantInt.
if (ConstantInt *BOC = dyn_cast<ConstantInt>(BOp1)) {
Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=277752&r1=277751&r2=277752&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Thu Aug 4 14:12:12 2016
@@ -2035,11 +2035,10 @@ define i1 @cmp_inverse_mask_bits_set_eq(
ret i1 %cmp
}
-; FIXME: Vectors should fold the same way.
define <2 x i1> @cmp_inverse_mask_bits_set_eq_vec(<2 x i32> %x) {
; CHECK-LABEL: @cmp_inverse_mask_bits_set_eq_vec(
-; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> %x, <i32 42, i32 42>
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[OR]], <i32 -1, i32 -1>
+; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> %x, <i32 -43, i32 -43>
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[TMP1]], <i32 -43, i32 -43>
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%or = or <2 x i32> %x, <i32 42, i32 42>
More information about the llvm-commits
mailing list