Skip to content

Commit 0fe905d

Browse files
committed
[IndVars] Add test for llvm#66986 (NFC)
1 parent bccaf93 commit 0fe905d

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2+
; RUN: opt -S -passes=indvars < %s | FileCheck %s
3+
4+
target datalayout = "n8:16:32:64"
5+
6+
; FIXME: This is a miscompile.
7+
; The udiv should not get hoisted into the preheader (past a conditional).
8+
define i32 @test(i1 %c, i32 %arg1, i32 %arg2) {
9+
; CHECK-LABEL: define i32 @test(
10+
; CHECK-SAME: i1 [[C:%.*]], i32 [[ARG1:%.*]], i32 [[ARG2:%.*]]) {
11+
; CHECK-NEXT: entry:
12+
; CHECK-NEXT: [[TMP0:%.*]] = udiv i32 [[ARG1]], [[ARG2]]
13+
; CHECK-NEXT: br label [[LOOP:%.*]]
14+
; CHECK: loop:
15+
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ], [ [[TMP0]], [[ENTRY:%.*]] ]
16+
; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[LOOP_LATCH]]
17+
; CHECK: if:
18+
; CHECK-NEXT: br label [[LOOP2:%.*]]
19+
; CHECK: loop2:
20+
; CHECK-NEXT: [[PHI6:%.*]] = phi i64 [ [[ADD7:%.*]], [[LOOP2]] ], [ 0, [[IF]] ]
21+
; CHECK-NEXT: [[ADD7]] = add nuw nsw i64 [[PHI6]], 1
22+
; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[INDVARS_IV]] to i64
23+
; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
24+
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[ADD7]], [[TMP2]]
25+
; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP2]], label [[LOOP_LATCH_LOOPEXIT:%.*]]
26+
; CHECK: loop.latch.loopexit:
27+
; CHECK-NEXT: br label [[LOOP_LATCH]]
28+
; CHECK: loop.latch:
29+
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i32 [[INDVARS_IV]], 1
30+
; CHECK-NEXT: br label [[LOOP]]
31+
;
32+
entry:
33+
br label %loop
34+
35+
loop:
36+
%phi = phi i32 [ %add9, %loop.latch ], [ 0, %entry ]
37+
br i1 %c, label %if, label %loop.latch
38+
39+
if:
40+
%udiv = udiv i32 %arg1, %arg2
41+
%add = add i32 %udiv, %phi
42+
%zext = zext i32 %add to i64
43+
br label %loop2
44+
45+
loop2:
46+
%phi6 = phi i64 [ %add7, %loop2 ], [ 0, %if ]
47+
%add7 = add i64 %phi6, 1
48+
%icmp = icmp slt i64 %phi6, %zext
49+
br i1 %icmp, label %loop2, label %loop.latch
50+
51+
loop.latch:
52+
%add9 = add i32 %phi, 1
53+
br label %loop
54+
}

0 commit comments

Comments
 (0)