1 ; RUN: opt < %s -passes=jump-threading -print-lvi-after-jump-threading -disable-output 2>&1 | FileCheck %s
2 ; RUN: opt < %s -passes=jump-threading -print-lvi-after-jump-threading -disable-output 2>&1 | FileCheck %s
4 ; Testing LVI cache after jump-threading
6 ; Jump-threading transforms the IR below to one where
7 ; loop and backedge basic blocks are merged into one.
8 ; basic block (named backedge) with the branch being:
9 ; %cont = icmp slt i32 %iv.next, 400
10 ; br i1 %cont, label %backedge, label %exit
11 define i8 @test1(i32 %a, i32 %length) {
12 ; CHECK-LABEL: LVI for function 'test1':
15 ; CHECK-NEXT: ; LatticeVal for: 'i32 %a' is: overdefined
16 ; CHECK-NEXT: ; LatticeVal for: 'i32 %length' is: overdefined
19 ; CHECK-LABEL: backedge:
20 ; CHECK-NEXT: ; LatticeVal for: 'i32 %a' is: overdefined
21 ; CHECK-NEXT: ; LatticeVal for: 'i32 %length' is: overdefined
22 ; CHECK-NEXT: ; LatticeVal for: ' %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]' in BB: '%backedge' is: constantrange<0, 400>
23 ; CHECK-NEXT: ; LatticeVal for: ' %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]' in BB: '%exit' is: constantrange<399, 400>
24 ; CHECK-NEXT: %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]
25 ; CHECK-NEXT: ; LatticeVal for: ' %iv.next = add nsw i32 %iv, 1' in BB: '%backedge' is: constantrange<1, 401>
26 ; CHECK-NEXT: ; LatticeVal for: ' %iv.next = add nsw i32 %iv, 1' in BB: '%exit' is: constantrange<400, 401>
27 ; CHECK-NEXT: %iv.next = add nsw i32 %iv, 1
28 ; CHECK-NEXT: ; LatticeVal for: ' %cont = icmp slt i32 %iv.next, 400' in BB: '%backedge' is: overdefined
29 ; CHECK-NEXT: ; LatticeVal for: ' %cont = icmp slt i32 %iv.next, 400' in BB: '%exit' is: constantrange<0, -1>
30 ; CHECK-NEXT: %cont = icmp slt i32 %iv.next, 400
33 %iv = phi i32 [0, %entry], [%iv.next, %backedge]
34 %cnd = icmp sge i32 %iv, 0
35 br i1 %cnd, label %backedge, label %exit
38 %iv.next = add nsw i32 %iv, 1
39 %cont = icmp slt i32 %iv.next, 400
40 br i1 %cont, label %loop, label %exit
46 ; Here JT does not transform the code, but LVICache is populated during the processing of blocks.
47 define i8 @test2(i32 %n) {
48 ; CHECK-LABEL: LVI for function 'test2':
50 ; CHECK-NEXT: ; LatticeVal for: 'i32 %n' is: overdefined
51 ; CHECK-NEXT: br label %loop
56 ; CHECK-NEXT: ; LatticeVal for: 'i32 %n' is: overdefined
57 ; CHECK-NEXT: ; LatticeVal for: ' %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]' in BB: '%loop' is: constantrange<0, 400>
58 ; CHECK-DAG: ; LatticeVal for: ' %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]' in BB: '%backedge' is: constantrange<0, -2147483648>
59 ; CHECK-DAG: ; LatticeVal for: ' %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]' in BB: '%exit' is: constantrange<0, -2147483648>
60 ; CHECK-NEXT: %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]
62 %iv = phi i32 [0, %entry], [%iv.next, %backedge]
63 ; CHECK-NEXT: ; LatticeVal for: ' %iv2 = phi i32 [ %n, %entry ], [ %iv2.next, %backedge ]' in BB: '%loop' is: overdefined
64 ; CHECK-DAG: ; LatticeVal for: ' %iv2 = phi i32 [ %n, %entry ], [ %iv2.next, %backedge ]' in BB: '%backedge' is: constantrange<1, -2147483648>
65 ; CHECK-DAG: ; LatticeVal for: ' %iv2 = phi i32 [ %n, %entry ], [ %iv2.next, %backedge ]' in BB: '%exit' is: overdefined
66 ; CHECK-NEXT: %iv2 = phi i32 [ %n, %entry ], [ %iv2.next, %backedge ]
67 %iv2 = phi i32 [%n, %entry], [%iv2.next, %backedge]
69 ; CHECK-NEXT: ; LatticeVal for: ' %cnd1 = icmp sge i32 %iv, 0' in BB: '%loop' is: overdefined
70 ; CHECK-DAG: ; LatticeVal for: ' %cnd1 = icmp sge i32 %iv, 0' in BB: '%backedge' is: overdefined
71 ; CHECK-DAG: ; LatticeVal for: ' %cnd1 = icmp sge i32 %iv, 0' in BB: '%exit' is: overdefined
72 ; CHECK-NEXT: %cnd1 = icmp sge i32 %iv, 0
73 %cnd1 = icmp sge i32 %iv, 0
74 %cnd2 = icmp sgt i32 %iv2, 0
75 ; CHECK: %cnd2 = icmp sgt i32 %iv2, 0
76 ; CHECK: ; LatticeVal for: ' %cnd = and i1 %cnd1, %cnd2' in BB: '%loop' is: overdefined
77 ; CHECK-DAG: ; LatticeVal for: ' %cnd = and i1 %cnd1, %cnd2' in BB: '%backedge' is: constantrange<-1, 0>
78 ; CHECK-DAG: ; LatticeVal for: ' %cnd = and i1 %cnd1, %cnd2' in BB: '%exit' is: overdefined
79 ; CHECK-NEXT: %cnd = and i1 %cnd1, %cnd2
80 %cnd = and i1 %cnd1, %cnd2
81 br i1 %cnd, label %backedge, label %exit
83 ; CHECK-LABEL: backedge:
84 ; CHECK-NEXT: ; LatticeVal for: 'i32 %n' is: overdefined
85 ; CHECK-NEXT: ; LatticeVal for: ' %iv.next = add nsw i32 %iv, 1' in BB: '%backedge' is: constantrange<1, -2147483648>
86 ; CHECK-NEXT: %iv.next = add nsw i32 %iv, 1
88 %iv.next = add nsw i32 %iv, 1
89 %iv2.next = sub nsw i32 %iv2, 1
90 ; CHECK: ; LatticeVal for: ' %cont1 = icmp slt i32 %iv.next, 400' in BB: '%backedge' is: overdefined
91 ; CHECK-NEXT: %cont1 = icmp slt i32 %iv.next, 400
92 %cont1 = icmp slt i32 %iv.next, 400
93 ; CHECK-NEXT: ; LatticeVal for: ' %cont2 = icmp sgt i32 %iv2.next, 0' in BB: '%backedge' is: overdefined
94 ; CHECK-NEXT: %cont2 = icmp sgt i32 %iv2.next, 0
95 %cont2 = icmp sgt i32 %iv2.next, 0
96 ; CHECK-NEXT: ; LatticeVal for: ' %cont = and i1 %cont1, %cont2' in BB: '%backedge' is: overdefined
97 ; CHECK-NEXT: %cont = and i1 %cont1, %cont2
98 %cont = and i1 %cont1, %cont2
99 br i1 %cont, label %loop, label %exit
105 ; Merging cont block into do block. Make sure that we do not incorrectly have the cont
106 ; LVI info as LVI info for the beginning of do block. LVI info for %i is Range[0,1)
107 ; at beginning of cont Block, which is incorrect at the beginning of do block.
108 define i32 @test3(i32 %i, i1 %f, i32 %n) {
109 ; CHECK-LABEL: LVI for function 'test3':
111 ; CHECK: ; LatticeVal for: 'i32 %i' is: overdefined
112 ; CHECK: %c = icmp ne i32 %i, -2134
113 ; CHECK: br i1 %c, label %cont, label %exit
115 %c = icmp ne i32 %i, -2134
116 br i1 %c, label %do, label %exit
119 %c1 = icmp ne i32 %i, -42
120 br i1 %c1, label %exit2, label %exit
123 ; Here cont is merged to do and i is any value except -2134.
124 ; i is not the single value: zero.
125 ; CHECK-NOT: ; LatticeVal for: 'i32 %i' is: constantrange<0, 1>
126 ; CHECK: ; LatticeVal for: 'i32 %i' is: constantrange<-2133, -2134>
127 ; CHECK: ; LatticeVal for: ' %cond.0 = icmp sgt i32 %i, 0' in BB: '%cont' is: overdefined
128 ; CHECK: %cond.0 = icmp sgt i32 %i, 0
129 ; CHECK: %consume = call i32 @consume
130 ; CHECK: %cond = icmp eq i32 %i, 0
131 ; CHECK: call void (i1, ...) @llvm.experimental.guard(i1 %cond)
132 ; CHECK: %cond.3 = icmp sgt i32 %i, %n
133 ; CHECK: br i1 %cond.3, label %exit2, label %exit
135 %cond.3 = icmp sgt i32 %i, %n
136 br i1 %cond.3, label %exit2, label %exit
139 %cond.0 = icmp sgt i32 %i, 0
140 %consume = call i32 @consume(i1 %cond.0)
141 %cond = icmp eq i32 %i, 0
142 call void (i1, ...) @llvm.experimental.guard(i1 %cond) [ "deopt"() ]
143 %cond.2 = icmp sgt i32 %i, 0
144 br i1 %cond.2, label %exit, label %cont
147 ; CHECK-LABEL: exit2:
148 ; LatticeVal for: 'i32 %i' is: constantrange<-2134, 1>
152 ; FIXME: We should be able to merge cont into do.
153 ; When we do so, LVI for cont cannot be the one for the merged do block.
154 define i32 @test4(i32 %i, i1 %f, i32 %n) {
155 ; CHECK-LABEL: LVI for function 'test4':
157 %c = icmp ne i32 %i, -2134
158 br i1 %c, label %do, label %exit
160 exit: ; preds = %do, %cont, %exit, %entry
161 %c1 = icmp ne i32 %i, -42
162 br i1 %c1, label %exit2, label %exit
166 ; CHECK: ; LatticeVal for: 'i1 %f' is: constantrange<-1, 0>
167 ; CHECK: call void @dummy(i1 %f)
168 call void @dummy(i1 %f)
173 ; CHECK: ; LatticeVal for: 'i1 %f' is: overdefined
174 ; CHECK: call void @dummy(i1 %f)
175 ; CHECK: br i1 %cond, label %exit, label %cont
176 call void @dummy(i1 %f)
177 %consume = call i32 @exit()
178 call void @llvm.assume(i1 %f)
179 %cond = icmp eq i1 %f, false
180 br i1 %cond, label %exit, label %cont
182 exit2: ; preds = %cont, %exit
187 declare i32 @consume(i1)
188 declare void @llvm.assume(i1) nounwind
189 declare void @dummy(i1) nounwind
190 declare void @llvm.experimental.guard(i1, ...)