[llvm-commits] [llvm] r144173 - in /llvm/trunk: lib/Analysis/ScalarEvolution.cpp test/Analysis/ScalarEvolution/trip-count12.ll

Nick Lewycky nicholas at mxc.ca
Tue Nov 8 23:11:37 PST 2011


Author: nicholas
Date: Wed Nov  9 01:11:37 2011
New Revision: 144173

URL: http://llvm.org/viewvc/llvm-project?rev=144173&view=rev
Log:
Don't forget to check FlagNW when determining whether an AddRecExpr will wrap
or not. Patch by Brendon Cahoon!

Added:
    llvm/trunk/test/Analysis/ScalarEvolution/trip-count12.ll
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=144173&r1=144172&r2=144173&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed Nov  9 01:11:37 2011
@@ -6228,8 +6228,9 @@
     return getCouldNotCompute();
 
   // Check to see if we have a flag which makes analysis easy.
-  bool NoWrap = isSigned ? AddRec->getNoWrapFlags(SCEV::FlagNSW) :
-                           AddRec->getNoWrapFlags(SCEV::FlagNUW);
+  bool NoWrap = isSigned ?
+    AddRec->getNoWrapFlags((SCEV::NoWrapFlags)(SCEV::FlagNSW | SCEV::FlagNW)) :
+    AddRec->getNoWrapFlags((SCEV::NoWrapFlags)(SCEV::FlagNUW | SCEV::FlagNW));
 
   if (AddRec->isAffine()) {
     unsigned BitWidth = getTypeSizeInBits(AddRec->getType());

Added: llvm/trunk/test/Analysis/ScalarEvolution/trip-count12.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/trip-count12.ll?rev=144173&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/trip-count12.ll (added)
+++ llvm/trunk/test/Analysis/ScalarEvolution/trip-count12.ll Wed Nov  9 01:11:37 2011
@@ -0,0 +1,35 @@
+; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s
+
+; CHECK: Determining loop execution counts for: @test
+; CHECK: Loop %for.body: backedge-taken count is ((-2 + %len) /u 2)
+; CHECK: Loop %for.body: max backedge-taken count is 1073741823
+
+define zeroext i16 @test(i16* nocapture %p, i32 %len) nounwind readonly {
+entry:
+  %cmp2 = icmp sgt i32 %len, 1
+  br i1 %cmp2, label %for.body.preheader, label %for.end
+
+for.body.preheader:                               ; preds = %entry
+  br label %for.body
+
+for.body:                                         ; preds = %for.body, %for.body.preheader
+  %p.addr.05 = phi i16* [ %incdec.ptr, %for.body ], [ %p, %for.body.preheader ]
+  %len.addr.04 = phi i32 [ %sub, %for.body ], [ %len, %for.body.preheader ]
+  %res.03 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ]
+  %incdec.ptr = getelementptr inbounds i16* %p.addr.05, i32 1
+  %0 = load i16* %p.addr.05, align 2
+  %conv = zext i16 %0 to i32
+  %add = add i32 %conv, %res.03
+  %sub = add nsw i32 %len.addr.04, -2
+  %cmp = icmp sgt i32 %sub, 1
+  br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
+
+for.cond.for.end_crit_edge:                       ; preds = %for.body
+  %extract.t = trunc i32 %add to i16
+  br label %for.end
+
+for.end:                                          ; preds = %for.cond.for.end_crit_edge, %entry
+  %res.0.lcssa.off0 = phi i16 [ %extract.t, %for.cond.for.end_crit_edge ], [ 0, %entry ]
+  ret i16 %res.0.lcssa.off0
+}
+





More information about the llvm-commits mailing list