diff options
author | Dan Gohman <gohman@apple.com> | 2009-09-17 18:05:20 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-09-17 18:05:20 +0000 |
commit | 1f96e67f78110d0ac5b30a32375097a28f869c63 (patch) | |
tree | 0d7e9d9548abac5b768f7bc42fabb8da8d8f0a96 /test/Analysis/ScalarEvolution | |
parent | f9ca50e3dce88b2f9e2f2f0cac2d3ed78afda841 (diff) | |
download | llvm-1f96e67f78110d0ac5b30a32375097a28f869c63.tar.gz llvm-1f96e67f78110d0ac5b30a32375097a28f869c63.tar.bz2 llvm-1f96e67f78110d0ac5b30a32375097a28f869c63.tar.xz |
Teach ScalarEvolution how to reason about no-wrap flags on loops
where the induction variable has a non-unit stride, such as {0,+,2}, and
there are expressions such as {1,+,2} inside the loop formed with
or or add nsw operators.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82151 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/ScalarEvolution')
-rw-r--r-- | test/Analysis/ScalarEvolution/nsw-offset.ll | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/test/Analysis/ScalarEvolution/nsw-offset.ll b/test/Analysis/ScalarEvolution/nsw-offset.ll new file mode 100644 index 0000000000..1e165bf622 --- /dev/null +++ b/test/Analysis/ScalarEvolution/nsw-offset.ll @@ -0,0 +1,76 @@ +; RUN: opt < %s -S -analyze -scalar-evolution -disable-output | FileCheck %s + +; ScalarEvolution should be able to fold away the sign-extensions +; on this loop with a primary induction variable incremented with +; a nsw add of 2. + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128" + +define void @foo(i32 %n, double* nocapture %d, double* nocapture %q) nounwind { +entry: + %0 = icmp sgt i32 %n, 0 ; <i1> [#uses=1] + br i1 %0, label %bb.nph, label %return + +bb.nph: ; preds = %entry + br label %bb + +bb: ; preds = %bb.nph, %bb1 + %i.01 = phi i32 [ %16, %bb1 ], [ 0, %bb.nph ] ; <i32> [#uses=5] + +; CHECK: %1 = sext i32 %i.01 to i64 +; CHECK: --> {0,+,2}<bb> + %1 = sext i32 %i.01 to i64 ; <i64> [#uses=1] + +; CHECK: %2 = getelementptr inbounds double* %d, i64 %1 +; CHECK: --> {%d,+,16}<bb> + %2 = getelementptr inbounds double* %d, i64 %1 ; <double*> [#uses=1] + + %3 = load double* %2, align 8 ; <double> [#uses=1] + %4 = sext i32 %i.01 to i64 ; <i64> [#uses=1] + %5 = getelementptr inbounds double* %q, i64 %4 ; <double*> [#uses=1] + %6 = load double* %5, align 8 ; <double> [#uses=1] + %7 = or i32 %i.01, 1 ; <i32> [#uses=1] + +; CHECK: %8 = sext i32 %7 to i64 +; CHECK: --> {1,+,2}<bb> + %8 = sext i32 %7 to i64 ; <i64> [#uses=1] + +; CHECK: %9 = getelementptr inbounds double* %q, i64 %8 +; CHECK: {(8 + %q),+,16}<bb> + %9 = getelementptr inbounds double* %q, i64 %8 ; <double*> [#uses=1] + +; Artificially repeat the above three instructions, this time using +; add nsw instead of or. + %t7 = add nsw i32 %i.01, 1 ; <i32> [#uses=1] + +; CHECK: %t8 = sext i32 %t7 to i64 +; CHECK: --> {1,+,2}<bb> + %t8 = sext i32 %t7 to i64 ; <i64> [#uses=1] + +; CHECK: %t9 = getelementptr inbounds double* %q, i64 %t8 +; CHECK: {(8 + %q),+,16}<bb> + %t9 = getelementptr inbounds double* %q, i64 %t8 ; <double*> [#uses=1] + + %10 = load double* %9, align 8 ; <double> [#uses=1] + %11 = fadd double %6, %10 ; <double> [#uses=1] + %12 = fadd double %11, 3.200000e+00 ; <double> [#uses=1] + %13 = fmul double %3, %12 ; <double> [#uses=1] + %14 = sext i32 %i.01 to i64 ; <i64> [#uses=1] + %15 = getelementptr inbounds double* %d, i64 %14 ; <double*> [#uses=1] + store double %13, double* %15, align 8 + %16 = add nsw i32 %i.01, 2 ; <i32> [#uses=2] + br label %bb1 + +bb1: ; preds = %bb + %17 = icmp slt i32 %16, %n ; <i1> [#uses=1] + br i1 %17, label %bb, label %bb1.return_crit_edge + +bb1.return_crit_edge: ; preds = %bb1 + br label %return + +return: ; preds = %bb1.return_crit_edge, %entry + ret void +} + +; CHECK: Loop bb: backedge-taken count is ((-1 + %n) /u 2) +; CHECK: Loop bb: max backedge-taken count is 1073741823 |