[llvm-commits] [llvm] r69655 - /llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Dan Gohman gohman at apple.com
Mon Apr 20 19:26:00 PDT 2009


Author: djg
Date: Mon Apr 20 21:26:00 2009
New Revision: 69655

URL: http://llvm.org/viewvc/llvm-project?rev=69655&view=rev
Log:
Teach ScalarEvolution how to recognize zext-inreg and sext-inreg,
as they appear in LLVM IR. This isn't particularly interesting
on its own; this is just setting up some infrastructure.

Modified:
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=69655&r1=69654&r2=69655&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Mon Apr 20 21:26:00 2009
@@ -1947,6 +1947,19 @@
   case Instruction::Sub:
     return SE.getMinusSCEV(getSCEV(U->getOperand(0)),
                            getSCEV(U->getOperand(1)));
+  case Instruction::And:
+    // For an expression like x&255 that merely masks off the high bits,
+    // use zext(trunc(x)) as the SCEV expression.
+    if (ConstantInt *CI = dyn_cast<ConstantInt>(U->getOperand(1))) {
+      const APInt &A = CI->getValue();
+      unsigned Ones = A.countTrailingOnes();
+      if (APIntOps::isMask(Ones, A))
+        return
+          SE.getZeroExtendExpr(SE.getTruncateExpr(getSCEV(U->getOperand(0)),
+                                                  IntegerType::get(Ones)),
+                               U->getType());
+    }
+    break;
   case Instruction::Or:
     // If the RHS of the Or is a constant, we may have something like:
     // X*4+1 which got turned into X*4|1.  Handle this as an Add so loop
@@ -1996,6 +2009,20 @@
     }
     break;
 
+  case Instruction::AShr:
+    // For a two-shift sext-inreg, use sext(trunc(x)) as the SCEV expression.
+    if (ConstantInt *CI = dyn_cast<ConstantInt>(U->getOperand(1)))
+      if (Instruction *L = dyn_cast<Instruction>(U->getOperand(0)))
+        if (L->getOpcode() == Instruction::Shl &&
+            L->getOperand(1) == U->getOperand(1)) {
+          uint64_t Amt = CI->getZExtValue();
+          return
+            SE.getSignExtendExpr(SE.getTruncateExpr(getSCEV(L->getOperand(0)),
+                                                    IntegerType::get(Amt)),
+                                 U->getType());
+        }
+    break;
+
   case Instruction::Trunc:
     return SE.getTruncateExpr(getSCEV(U->getOperand(0)), U->getType());
 





More information about the llvm-commits mailing list