[llvm-commits] CVS: llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp

Nick Lewycky nicholas at mxc.ca
Fri Apr 6 19:30:31 PDT 2007



Changes in directory llvm/lib/Transforms/Scalar:

PredicateSimplifier.cpp updated: 1.61 -> 1.62
---
Log message:

Strengthen icmp snuggling by doing 'compare-or-equal-to' to 'compare'
first and then range testing second.


---
Diffs of the changes:  (+23 -16)

 PredicateSimplifier.cpp |   39 +++++++++++++++++++++++----------------
 1 files changed, 23 insertions(+), 16 deletions(-)


Index: llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp
diff -u llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp:1.61 llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp:1.62
--- llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp:1.61	Wed Mar 21 21:02:51 2007
+++ llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp	Fri Apr  6 21:30:14 2007
@@ -2182,11 +2182,33 @@
     // 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 @@
           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",






More information about the llvm-commits mailing list