Skip to content

Commit f204886

Browse files
committed
[CVP] Add test with nested cycle (NFC)
This is a regression test for a miscompile that would have been introduced by an upcoming patch.
1 parent 9cd4128 commit f204886

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt -S -passes=jump-threading,correlated-propagation < %s | FileCheck %s
3+
4+
; This runs both jump threading and CVP to query values in the right order.
5+
; The comparison should not fold.
6+
7+
define void @test(i32 %n, i1 %c, i1 %c2) {
8+
; CHECK-LABEL: define void @test(
9+
; CHECK-SAME: i32 [[N:%.*]], i1 [[C:%.*]], i1 [[C2:%.*]]) {
10+
; CHECK-NEXT: entry:
11+
; CHECK-NEXT: br label [[LOOP:%.*]]
12+
; CHECK: loop:
13+
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ]
14+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[IV]], 0
15+
; CHECK-NEXT: call void @use(i1 [[CMP]])
16+
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
17+
; CHECK-NEXT: br label [[LOOP2:%.*]]
18+
; CHECK: loop2:
19+
; CHECK-NEXT: br i1 [[C]], label [[LOOP2_LATCH:%.*]], label [[LOOP2_LATCH]]
20+
; CHECK: loop2.latch:
21+
; CHECK-NEXT: br i1 [[C2]], label [[LOOP_LATCH]], label [[LOOP2]]
22+
; CHECK: loop.latch:
23+
; CHECK-NEXT: [[EXIT_COND:%.*]] = icmp eq i32 [[IV_NEXT]], [[N]]
24+
; CHECK-NEXT: br i1 [[EXIT_COND]], label [[EXIT:%.*]], label [[LOOP]]
25+
; CHECK: exit:
26+
; CHECK-NEXT: ret void
27+
;
28+
entry:
29+
br label %loop
30+
31+
loop:
32+
%iv = phi i32 [ %iv.next, %loop.latch ], [ 0, %entry ]
33+
%cmp = icmp eq i32 %iv, 0
34+
call void @use(i1 %cmp)
35+
%iv.next = add nuw nsw i32 %iv, 1
36+
br label %loop2
37+
38+
loop2:
39+
br i1 %c, label %loop2.latch, label %loop2.split
40+
41+
loop2.split:
42+
br label %loop2.latch
43+
44+
loop2.latch:
45+
br i1 %c2, label %loop.latch, label %loop2
46+
47+
loop.latch:
48+
%exit.cond = icmp eq i32 %iv.next, %n
49+
br i1 %exit.cond, label %exit, label %loop
50+
51+
exit:
52+
ret void
53+
}
54+
55+
declare void @use(i1)

0 commit comments

Comments
 (0)