1 ; REQUIRES: x86-registered-target
2 ; RUN: opt -loop-reduce -S < %s | FileCheck %s
4 ; Strength reduction analysis here relies on IV Users analysis, that
5 ; only finds users among instructions with types that are treated as
6 ; legal by the data layout. When running this test on pure non-x86
7 ; configs (for example, ARM 64), it gets confused with the target
8 ; triple and uses a default data layout instead. This default layout
9 ; does not have any legal types (even i32), so the transformation
12 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"
13 target triple = "x86_64-apple-macosx"
15 ; PR15470: LSR miscompile. The test2 function should return '1'.
17 ; SCEV expander cannot expand quadratic recurrences outside of the
18 ; loop. This recurrence depends on %sub.us, so can't be expanded.
19 ; We cannot fold SCEVUnknown (sub.us) with recurrences since it is
20 ; declared after the loop.
23 ; CHECK-LABEL: test2.loop:
24 ; CHECK: %lsr.iv1 = phi i32 [ %lsr.iv.next2, %test2.loop ], [ -16777216, %entry ]
25 ; CHECK: %lsr.iv = phi i32 [ %lsr.iv.next, %test2.loop ], [ 1, %entry ]
26 ; CHECK: %lsr.iv.next = add nsw i32 %lsr.iv, -1
27 ; CHECK: %lsr.iv.next2 = add nsw i32 %lsr.iv1, 16777216
29 ; CHECK-LABEL: for.end:
30 ; CHECK: %tobool.us = icmp eq i32 %lsr.iv.next, 0
31 ; CHECK: %sub.us = select i1 %tobool.us, i32 0, i32 0
32 ; CHECK: %0 = sub i32 0, %sub.us
33 ; CHECK: %1 = sub i32 %0, %lsr.iv.next
34 ; CHECK: %sext.us = mul i32 %lsr.iv.next2, %1
35 ; CHECK: %f = ashr i32 %sext.us, 24
42 %inc1115.us = phi i32 [ 0, %entry ], [ %inc11.us, %test2.loop ]
43 %inc11.us = add nsw i32 %inc1115.us, 1
44 %cmp.us = icmp slt i32 %inc11.us, 2
45 br i1 %cmp.us, label %test2.loop, label %for.end
48 %tobool.us = icmp eq i32 %inc1115.us, 0
49 %sub.us = select i1 %tobool.us, i32 0, i32 0
50 %mul.us = shl i32 %inc1115.us, 24
51 %sub.cond.us = sub nsw i32 %inc1115.us, %sub.us
52 %sext.us = mul i32 %mul.us, %sub.cond.us
53 %f = ashr i32 %sext.us, 24