[TwoAddressInstructionPass] When looking for a 3 addr conversion after commuting...
[oota-llvm.git] / test / Transforms / LoopStrengthReduce / lsr-expand-quadratic.ll
1 ; RUN: opt -loop-reduce -S < %s | FileCheck %s
2
3 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"
4 target triple = "x86_64-apple-macosx"
5
6 ; PR15470: LSR miscompile. The test2 function should return '1'.
7 ;
8 ; SCEV expander cannot expand quadratic recurrences outside of the
9 ; loop. This recurrence depends on %sub.us, so can't be expanded.
10 ;
11 ; CHECK-LABEL: @test2
12 ; CHECK-LABEL: test2.loop:
13 ; CHECK: %lsr.iv = phi i32 [ %lsr.iv.next, %test2.loop ], [ -16777216, %entry ]
14 ; CHECK: %lsr.iv.next = add nsw i32 %lsr.iv, 16777216
15 ;
16 ; CHECK-LABEL: for.end:
17 ; CHECK: %sub.cond.us = sub nsw i32 %inc1115.us, %sub.us
18 ; CHECK: %sext.us = mul i32 %lsr.iv.next, %sub.cond.us
19 ; CHECK: %f = ashr i32 %sext.us, 24
20 ; CHECK: ret i32 %f
21 define i32 @test2() {
22 entry:
23   br label %test2.loop
24
25 test2.loop:
26   %inc1115.us = phi i32 [ 0, %entry ], [ %inc11.us, %test2.loop ]
27   %inc11.us = add nsw i32 %inc1115.us, 1
28   %cmp.us = icmp slt i32 %inc11.us, 2
29   br i1 %cmp.us, label %test2.loop, label %for.end
30
31 for.end:
32   %tobool.us = icmp eq i32 %inc1115.us, 0
33   %sub.us = select i1 %tobool.us, i32 0, i32 0
34   %mul.us = shl i32 %inc1115.us, 24
35   %sub.cond.us = sub nsw i32 %inc1115.us, %sub.us
36   %sext.us = mul i32 %mul.us, %sub.cond.us
37   %f = ashr i32 %sext.us, 24
38   br label %exit
39
40 exit:
41   ret i32 %f
42 }