aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2007-04-07 02:30:14 +0000
committerNick Lewycky <nicholas@mxc.ca>2007-04-07 02:30:14 +0000
commit8ac40dd747f288dfbee273bd0e634696d1fa450f (patch)
treeaa634c291da046de29e2a331a76b5865ea22db1a /lib/Transforms/Scalar
parentc4625da483ff9e835aef886864e37dd68fb7a03c (diff)
downloadexternal_llvm-8ac40dd747f288dfbee273bd0e634696d1fa450f.zip
external_llvm-8ac40dd747f288dfbee273bd0e634696d1fa450f.tar.gz
external_llvm-8ac40dd747f288dfbee273bd0e634696d1fa450f.tar.bz2
Strengthen icmp snuggling by doing 'compare-or-equal-to' to 'compare'
first and then range testing second. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35715 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r--lib/Transforms/Scalar/PredicateSimplifier.cpp39
1 files changed, 23 insertions, 16 deletions
diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp
index 6ac309a..ac8ceb2 100644
--- a/lib/Transforms/Scalar/PredicateSimplifier.cpp
+++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp
@@ -2182,11 +2182,33 @@ namespace {
// Eg., if x = [0, 4) and we're being asked icmp uge %x, 3 then change
// the predicate to eq.
+ // XXX: once we do full PHI handling, modifying the instruction in the
+ // Forwards visitor will cause missed optimizations.
+
ICmpInst::Predicate Pred = IC.getPredicate();
+ switch (Pred) {
+ default: break;
+ case ICmpInst::ICMP_ULE: Pred = ICmpInst::ICMP_ULT; break;
+ case ICmpInst::ICMP_UGE: Pred = ICmpInst::ICMP_UGT; break;
+ case ICmpInst::ICMP_SLE: Pred = ICmpInst::ICMP_SLT; break;
+ case ICmpInst::ICMP_SGE: Pred = ICmpInst::ICMP_SGT; break;
+ }
+ if (Pred != IC.getPredicate()) {
+ VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, &IC);
+ if (VRP.isRelatedBy(IC.getOperand(1), IC.getOperand(0),
+ ICmpInst::ICMP_NE)) {
+ ++NumSnuggle;
+ PS->modified = true;
+ IC.setPredicate(Pred);
+ }
+ }
+
+ Pred = IC.getPredicate();
+
if (ConstantInt *Op1 = dyn_cast<ConstantInt>(IC.getOperand(1))) {
ConstantInt *NextVal = 0;
- switch(Pred) {
+ switch (Pred) {
default: break;
case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_ULT:
@@ -2214,24 +2236,9 @@ namespace {
IC.eraseFromParent();
++NumSnuggle;
PS->modified = true;
- return;
}
}
}
-
- switch(Pred) {
- default: return;
- case ICmpInst::ICMP_ULE: Pred = ICmpInst::ICMP_ULT; break;
- case ICmpInst::ICMP_UGE: Pred = ICmpInst::ICMP_UGT; break;
- case ICmpInst::ICMP_SLE: Pred = ICmpInst::ICMP_SLT; break;
- case ICmpInst::ICMP_SGE: Pred = ICmpInst::ICMP_SGT; break;
- }
- VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, &IC);
- if (VRP.isRelatedBy(IC.getOperand(1), IC.getOperand(0), Pred)) {
- ++NumSnuggle;
- PS->modified = true;
- IC.setPredicate(Pred);
- }
}
RegisterPass<PredicateSimplifier> X("predsimplify",