diff options
author | Andrew Trick <atrick@apple.com> | 2013-10-25 21:35:56 +0000 |
---|---|---|
committer | Andrew Trick <atrick@apple.com> | 2013-10-25 21:35:56 +0000 |
commit | 4d4bbaf997c16f9e79503bd640306d784efd090e (patch) | |
tree | dce5058bb8c237bdf493aabc2ebf4af4e9e8fbbd /test/Transforms | |
parent | 8aa8cea3e964796187f8682e502a8446b3ce02e1 (diff) | |
download | external_llvm-4d4bbaf997c16f9e79503bd640306d784efd090e.zip external_llvm-4d4bbaf997c16f9e79503bd640306d784efd090e.tar.gz external_llvm-4d4bbaf997c16f9e79503bd640306d784efd090e.tar.bz2 |
Fix SCEVExpander: don't try to expand quadratic recurrences outside a loop.
Partial fix for PR17459: wrong code at -O3 on x86_64-linux-gnu
(affecting trunk and 3.3)
When SCEV expands a recurrence outside of a loop it attempts to scale
by the stride of the recurrence. Chained recurrences don't work that
way. We could compute binomial coefficients, but would hve to
guarantee that the chained AddRec's are in a perfectly reduced form.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193438 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms')
-rw-r--r-- | test/Transforms/LoopStrengthReduce/lsr-expand-quadratic.ll | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/Transforms/LoopStrengthReduce/lsr-expand-quadratic.ll b/test/Transforms/LoopStrengthReduce/lsr-expand-quadratic.ll new file mode 100644 index 0000000..255cf41 --- /dev/null +++ b/test/Transforms/LoopStrengthReduce/lsr-expand-quadratic.ll @@ -0,0 +1,42 @@ +; RUN: opt -loop-reduce -S < %s | FileCheck %s + +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-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx" + +; PR15470: LSR miscompile. The test2 function should return '1'. +; +; SCEV expander cannot expand quadratic recurrences outside of the +; loop. This recurrence depends on %sub.us, so can't be expanded. +; +; CHECK-LABEL: @test2 +; CHECK-LABEL: test2.loop: +; CHECK: %lsr.iv = phi i32 [ %lsr.iv.next, %test2.loop ], [ -16777216, %entry ] +; CHECK: %lsr.iv.next = add nsw i32 %lsr.iv, 16777216 +; +; CHECK=LABEL: for.end: +; CHECK: %sub.cond.us = sub nsw i32 %inc1115.us, %sub.us +; CHECK: %sext.us = mul i32 %lsr.iv.next, %sub.cond.us +; CHECK: %f = ashr i32 %sext.us, 24 +; CHECK: ret i32 %f +define i32 @test2() { +entry: + br label %test2.loop + +test2.loop: + %inc1115.us = phi i32 [ 0, %entry ], [ %inc11.us, %test2.loop ] + %inc11.us = add nsw i32 %inc1115.us, 1 + %cmp.us = icmp slt i32 %inc11.us, 2 + br i1 %cmp.us, label %test2.loop, label %for.end + +for.end: + %tobool.us = icmp eq i32 %inc1115.us, 0 + %sub.us = select i1 %tobool.us, i32 0, i32 0 + %mul.us = shl i32 %inc1115.us, 24 + %sub.cond.us = sub nsw i32 %inc1115.us, %sub.us + %sext.us = mul i32 %mul.us, %sub.cond.us + %f = ashr i32 %sext.us, 24 + br label %exit + +exit: + ret i32 %f +} |