summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2016-08-16 21:53:19 +0000
committerSanjay Patel <spatel@rotateright.com>2016-08-16 21:53:19 +0000
commite47df1ac62daa5ef33488a528b14cffd18b3250e (patch)
tree169ec6bac5d4068759282fad2e773c3b1a75894c /llvm/lib/Transforms
parent41cf73ce16c016a02d875364a56e127b4cdf46e8 (diff)
downloadbcm5719-llvm-e47df1ac62daa5ef33488a528b14cffd18b3250e.tar.gz
bcm5719-llvm-e47df1ac62daa5ef33488a528b14cffd18b3250e.zip
[InstCombine] use m_APInt to allow icmp (sub X, Y), C folds for splat constant vectors
llvm-svn: 278859
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 0e5596190bf..e2e47c18fdb 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2170,32 +2170,27 @@ Instruction *InstCombiner::foldICmpDivConstant(ICmpInst &ICI, Instruction *LHSI,
/// Fold icmp (sub X, Y), C.
Instruction *InstCombiner::foldICmpSubConstant(ICmpInst &Cmp, Instruction *Sub,
const APInt *C) {
- // FIXME: This check restricts all folds under here to scalar types.
- ConstantInt *RHS = dyn_cast<ConstantInt>(Cmp.getOperand(1));
- if (!RHS)
+ const APInt *C2;
+ if (!match(Sub->getOperand(0), m_APInt(C2)) || !Sub->hasOneUse())
return nullptr;
- ConstantInt *SubC = dyn_cast<ConstantInt>(Sub->getOperand(0));
- if (!SubC)
- return nullptr;
-
- const APInt &C2 = SubC->getValue();
-
// C-X <u C2 -> (X|(C2-1)) == C
// iff C & (C2-1) == C2-1
// C2 is a power of 2
- if (Cmp.getPredicate() == ICmpInst::ICMP_ULT && Sub->hasOneUse() &&
- C->isPowerOf2() && (C2 & (*C - 1)) == (*C - 1))
+ if (Cmp.getPredicate() == ICmpInst::ICMP_ULT && C->isPowerOf2() &&
+ (*C2 & (*C - 1)) == (*C - 1))
return new ICmpInst(ICmpInst::ICMP_EQ,
- Builder->CreateOr(Sub->getOperand(1), *C - 1), SubC);
+ Builder->CreateOr(Sub->getOperand(1), *C - 1),
+ Sub->getOperand(0));
// C-X >u C2 -> (X|C2) != C
// iff C & C2 == C2
// C2+1 is a power of 2
- if (Cmp.getPredicate() == ICmpInst::ICMP_UGT && Sub->hasOneUse() &&
- (*C + 1).isPowerOf2() && (C2 & *C) == *C)
+ if (Cmp.getPredicate() == ICmpInst::ICMP_UGT && (*C + 1).isPowerOf2() &&
+ (*C2 & *C) == *C)
return new ICmpInst(ICmpInst::ICMP_NE,
- Builder->CreateOr(Sub->getOperand(1), *C), SubC);
+ Builder->CreateOr(Sub->getOperand(1), *C),
+ Sub->getOperand(0));
return nullptr;
}
OpenPOWER on IntegriCloud