Skip to content

Commit 72d5740

Browse files
committed
[ConstraintElim] Add test for mis-compile with adjacent loops.
In the added test case, the AddRec from the first loop is used incorrectly in the second loop. (cherry-picked from 0d48a46)
1 parent d28b524 commit 72d5740

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
3+
4+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
5+
6+
declare void @use(i16)
7+
8+
define void @test_loop_add_rec_used_in_adjacent_loop(i8 %len.n, i16 %a) {
9+
; CHECK-LABEL: @test_loop_add_rec_used_in_adjacent_loop(
10+
; CHECK-NEXT: entry:
11+
; CHECK-NEXT: [[LEN:%.*]] = zext i8 [[LEN_N:%.*]] to i16
12+
; CHECK-NEXT: [[LEN_NEG:%.*]] = icmp uge i16 [[LEN]], [[A:%.*]]
13+
; CHECK-NEXT: br i1 [[LEN_NEG]], label [[EXIT:%.*]], label [[LOOP_1_PH:%.*]]
14+
; CHECK: loop.1.ph:
15+
; CHECK-NEXT: br label [[LOOP_1:%.*]]
16+
; CHECK: loop.1:
17+
; CHECK-NEXT: [[IV:%.*]] = phi i16 [ 0, [[LOOP_1_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP_1]] ]
18+
; CHECK-NEXT: [[C_0:%.*]] = icmp eq i16 [[IV]], [[A]]
19+
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i16 [[IV]], 1
20+
; CHECK-NEXT: br i1 [[C_0]], label [[LOOP_2_HEADER:%.*]], label [[LOOP_1]]
21+
; CHECK: loop.2.header:
22+
; CHECK-NEXT: [[IV_2:%.*]] = phi i16 [ [[IV]], [[LOOP_1]] ], [ [[IV]], [[LOOP_2_LATCH:%.*]] ]
23+
; CHECK-NEXT: [[C:%.*]] = icmp eq i16 [[IV_2]], [[LEN]]
24+
; CHECK-NEXT: br i1 [[C]], label [[EXIT]], label [[FOR_BODY:%.*]]
25+
; CHECK: for.body:
26+
; CHECK-NEXT: [[AND:%.*]] = and i1 true, true
27+
; CHECK-NEXT: br i1 [[AND]], label [[LOOP_2_LATCH]], label [[EXIT]]
28+
; CHECK: loop.2.latch:
29+
; CHECK-NEXT: call void @use(i16 [[IV_2]])
30+
; CHECK-NEXT: br label [[LOOP_2_HEADER]]
31+
; CHECK: exit:
32+
; CHECK-NEXT: ret void
33+
;
34+
entry:
35+
%len = zext i8 %len.n to i16
36+
%len.neg = icmp uge i16 %len, %a
37+
br i1 %len.neg, label %exit, label %loop.1.ph
38+
39+
loop.1.ph:
40+
br label %loop.1
41+
42+
loop.1:
43+
%iv = phi i16 [ 0, %loop.1.ph ], [ %iv.next, %loop.1 ]
44+
%c.0 = icmp eq i16 %iv, %a
45+
%iv.next = add nuw nsw i16 %iv, 1
46+
br i1 %c.0, label %loop.2.header, label %loop.1
47+
48+
loop.2.header:
49+
%iv.2 = phi i16 [ %iv, %loop.1 ], [ %iv, %loop.2.latch ]
50+
%c = icmp eq i16 %iv.2, %len
51+
br i1 %c, label %exit, label %for.body
52+
53+
for.body:
54+
%t.1 = icmp uge i16 %iv.2, 0
55+
%t.2 = icmp ult i16 %iv.2, %a
56+
%and = and i1 %t.1, %t.2
57+
br i1 %and, label %loop.2.latch, label %exit
58+
59+
loop.2.latch:
60+
call void @use(i16 %iv.2)
61+
br label %loop.2.header
62+
63+
exit:
64+
ret void
65+
}

0 commit comments

Comments
 (0)