diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-05-30 18:32:23 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-05-30 18:32:23 +0000 |
commit | 6cf07a80ff5ee8ef7dc336f954aae17c7e8d83d4 (patch) | |
tree | a47c39f352c87564a19069dc27f70320e4611319 /test/Transforms/IndVarSimplify | |
parent | f186df0d3e64d1b6f61da39ce882530bf387029e (diff) | |
download | external_llvm-6cf07a80ff5ee8ef7dc336f954aae17c7e8d83d4.zip external_llvm-6cf07a80ff5ee8ef7dc336f954aae17c7e8d83d4.tar.gz external_llvm-6cf07a80ff5ee8ef7dc336f954aae17c7e8d83d4.tar.bz2 |
Teach SCEV's icmp simplification logic that a-b == 0 is equivalent to a == b.
This also required making recursive simplifications until
nothing changes or a hard limit (currently 3) is hit.
With the simplification in place indvars can canonicalize
loops of the form
for (unsigned i = 0; i < a-b; ++i)
into
for (unsigned i = 0; i != a-b; ++i)
which used to fail because SCEV created a weird umax expr
for the backedge taken count.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157701 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/IndVarSimplify')
-rw-r--r-- | test/Transforms/IndVarSimplify/ult-sub-to-eq.ll | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/Transforms/IndVarSimplify/ult-sub-to-eq.ll b/test/Transforms/IndVarSimplify/ult-sub-to-eq.ll new file mode 100644 index 0000000..c58a3af --- /dev/null +++ b/test/Transforms/IndVarSimplify/ult-sub-to-eq.ll @@ -0,0 +1,42 @@ +; RUN: opt -S -indvars < %s | FileCheck %s + +define void @test1(float* nocapture %autoc, float* nocapture %data, float %d, i32 %data_len, i32 %sample) nounwind { +entry: + %sub = sub i32 %data_len, %sample + %cmp4 = icmp eq i32 %data_len, %sample + br i1 %cmp4, label %for.end, label %for.body + +for.body: ; preds = %entry, %for.body + %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] + %0 = trunc i64 %indvars.iv to i32 + %add = add i32 %0, %sample + %idxprom = zext i32 %add to i64 + %arrayidx = getelementptr inbounds float* %data, i64 %idxprom + %1 = load float* %arrayidx, align 4 + %mul = fmul float %1, %d + %arrayidx2 = getelementptr inbounds float* %autoc, i64 %indvars.iv + %2 = load float* %arrayidx2, align 4 + %add3 = fadd float %2, %mul + store float %add3, float* %arrayidx2, align 4 + %indvars.iv.next = add i64 %indvars.iv, 1 + %3 = trunc i64 %indvars.iv.next to i32 + %cmp = icmp ult i32 %3, %sub + br i1 %cmp, label %for.body, label %for.end + +for.end: ; preds = %for.body, %entry + ret void + +; CHECK: @test1 + +; First check that we move the sub into the preheader, it doesn't have to be +; executed if %cmp4 == false +; CHECK: for.body.preheader: +; CHECK: sub i32 %data_len, %sample +; CHECK: br label %for.body + +; Second, check that we turn the IV test into an eq. +; CHECK: %lftr.wideiv = trunc i64 %indvars.iv.next to i32 +; CHECK: %exitcond = icmp ne i32 %lftr.wideiv, %0 +; CHECK: br i1 %exitcond, label %for.body, label %for.end.loopexit +} + |