[PATCH] Handle cast instructions in complete loop unroll heuristic.

Michael Zolotukhin mzolotukhin at apple.com
Wed Jun 3 21:54:02 PDT 2015


- Don't try to const-prop casts if the simplified value is just an offset from a base pointer.


http://reviews.llvm.org/D10207

Files:
  lib/Transforms/Scalar/LoopUnrollPass.cpp

Index: lib/Transforms/Scalar/LoopUnrollPass.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -424,6 +424,29 @@
     return true;
   }
 
+  bool visitCastInst(CastInst &I) {
+    if (SCEVSimplify(&I))
+      return true;
+    // If we've already visited the operand and found a base pointer for it, we
+    // can't const-fold it other than when used in a load.
+    if (auto *Op0 = dyn_cast<Instruction>(I.getOperand(0)))
+      if (GEPPointerBases.lookup(Op0))
+        return false;
+
+    // Propagate constants through ptrtoint.
+    Constant *COp = dyn_cast<Constant>(I.getOperand(0));
+    if (!COp)
+      COp = SimplifiedValues.lookup(I.getOperand(0));
+    if (COp)
+      if (Constant *C =
+              ConstantExpr::getCast(I.getOpcode(), COp, I.getType())) {
+        SimplifiedValues[&I] = C;
+        return true;
+      }
+
+    return false;
+  }
+
   bool visitCmpInst(CmpInst &I) {
     if (SCEVSimplify(&I))
       return true;

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10207.27091.patch
Type: text/x-patch
Size: 1065 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150604/03919f55/attachment.bin>


More information about the llvm-commits mailing list