[llvm-commits] [llvm] r123842 - in /llvm/trunk: lib/Analysis/ScalarEvolution.cpp test/Analysis/ScalarEvolution/fold.ll

Nick Lewycky nicholas at mxc.ca
Wed Jan 19 10:56:00 PST 2011


Author: nicholas
Date: Wed Jan 19 12:56:00 2011
New Revision: 123842

URL: http://llvm.org/viewvc/llvm-project?rev=123842&view=rev
Log:
Similarly, analyze truncate through multiply.

Modified:
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp
    llvm/trunk/test/Analysis/ScalarEvolution/fold.ll

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=123842&r1=123841&r2=123842&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed Jan 19 12:56:00 2011
@@ -833,6 +833,20 @@
       return getAddExpr(Operands, false, false);
   }
 
+  // trunc(x1*x2*...*xN) --> trunc(x1)*trunc(x2)*...*trunc(xN) if we can
+  // eliminate all the truncates.
+  if (const SCEVMulExpr *SM = dyn_cast<SCEVMulExpr>(Op)) {
+    SmallVector<const SCEV *, 4> Operands;
+    bool hasTrunc = false;
+    for (unsigned i = 0, e = SM->getNumOperands(); i != e && !hasTrunc; ++i) {
+      const SCEV *S = getTruncateExpr(SM->getOperand(i), Ty);
+      hasTrunc = isa<SCEVTruncateExpr>(S);
+      Operands.push_back(S);
+    }
+    if (!hasTrunc)
+      return getMulExpr(Operands, false, false);
+  }
+
   // If the input value is a chrec scev, truncate the chrec's operands.
   if (const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(Op)) {
     SmallVector<const SCEV *, 4> Operands;

Modified: llvm/trunk/test/Analysis/ScalarEvolution/fold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/fold.ll?rev=123842&r1=123841&r2=123842&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/fold.ll (original)
+++ llvm/trunk/test/Analysis/ScalarEvolution/fold.ll Wed Jan 19 12:56:00 2011
@@ -14,3 +14,11 @@
 ; CHECK: (1 + %x)
   ret i8 %C
 }
+
+define i8 @test3(i8 %x) {
+  %A = zext i8 %x to i16
+  %B = mul i16 %A, 1027
+  %C = trunc i16 %B to i8
+; CHECK: (3 * %x)
+  ret i8 %C
+}





More information about the llvm-commits mailing list