quadradic-exit-value.ll
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
; This test ensures that IVUsers works correctly in the legacy pass manager
; without LCSSA and in the specific ways that some of its users (LSR) require.
;
; FIXME: We need some way to match the precision here in the new PM where loop
; passes *always* work on LCSSA. This should stop using a different set of
; checks at that point.
; RUN: opt < %s -analyze -iv-users | FileCheck %s --check-prefixes=CHECK,CHECK-NO-LCSSA
; RUN: opt < %s -disable-output -passes='print<iv-users>' 2>&1 | FileCheck %s
; Provide legal integer types.
target datalayout = "n8:16:32:64"
; The value of %r is dependent on a polynomial iteration expression.
;
; CHECK-LABEL: IV Users for loop %foo.loop
; CHECK-NO-LCSSA: {1,+,3,+,2}<%foo.loop>
define i64 @foo(i64 %n) {
entry:
br label %foo.loop
foo.loop:
%indvar = phi i64 [ 0, %entry ], [ %indvar.next, %foo.loop ]
%indvar.next = add i64 %indvar, 1
%c = icmp eq i64 %indvar.next, %n
br i1 %c, label %exit, label %foo.loop
exit:
%r = mul i64 %indvar.next, %indvar.next
ret i64 %r
}
; PR15470: LSR miscompile. The test1 function should return '1'.
; It is valid to fold SCEVUnknown into the recurrence because it
; was defined before the loop.
;
; SCEV does not know how to denormalize chained recurrences, so make
; sure they aren't marked as post-inc users.
;
; CHECK-LABEL: IV Users for loop %test1.loop
; CHECK-NO-LCSSA: %sext.us = {0,+,(16777216 + (-16777216 * %sub.us))<nuw><nsw>,+,33554432}<%test1.loop> (post-inc with loop %test1.loop) in %f = ashr i32 %sext.us, 24
define i32 @test1(i1 %cond) {
entry:
%sub.us = select i1 %cond, i32 0, i32 0
br label %test1.loop
test1.loop:
%inc1115.us = phi i32 [ 0, %entry ], [ %inc11.us, %test1.loop ]
%inc11.us = add nsw i32 %inc1115.us, 1
%cmp.us = icmp slt i32 %inc11.us, 2
br i1 %cmp.us, label %test1.loop, label %for.end
for.end:
%tobool.us = icmp eq i32 %inc1115.us, 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
}
; PR15470: LSR miscompile. The test2 function should return '1'.
; It is illegal to fold SCEVUnknown (sext.us) into the recurrence
; because it is defined after the loop where this recurrence belongs.
;
; SCEV does not know how to denormalize chained recurrences, so make
; sure they aren't marked as post-inc users.
;
; CHECK-LABEL: IV Users for loop %test2.loop
; CHECK-NO-LCSSA: %sub.cond.us = ((-1 * %sub.us)<nuw><nsw> + {0,+,1}<nuw><nsw><%test2.loop>) (post-inc with loop %test2.loop) in %sext.us = mul i32 %mul.us, %sub.cond.us
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
}