Skip to content

Commit f47c406

Browse files
committed
[PhaseOrder] Add test where indvars dropping NSW prevents vectorization.
End-to-end test for #71517, testing IndVars/LoopVectorize interaction
1 parent 1652d44 commit f47c406

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt -passes='default<O3>' -S -o - %s | FileCheck %s
3+
4+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
5+
target triple = "arm64-apple-macosx14.0.0"
6+
7+
define void @s172(i32 noundef %xa, i32 noundef %xb, ptr noundef %a, ptr noundef %b) {
8+
; CHECK-LABEL: define void @s172(
9+
; CHECK-SAME: i32 noundef [[XA:%.*]], i32 noundef [[XB:%.*]], ptr nocapture noundef [[A:%.*]], ptr nocapture noundef readonly [[B:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
10+
; CHECK-NEXT: entry:
11+
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[XA]], 32001
12+
; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]]
13+
; CHECK: for.body.preheader:
14+
; CHECK-NEXT: [[SUB:%.*]] = add i32 [[XA]], -1
15+
; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[SUB]] to i64
16+
; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[XB]] to i64
17+
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
18+
; CHECK: for.body:
19+
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[TMP0]], [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
20+
; CHECK-NEXT: [[GEP_B:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[INDVARS_IV]]
21+
; CHECK-NEXT: [[L_B:%.*]] = load i32, ptr [[GEP_B]], align 4
22+
; CHECK-NEXT: [[GEP_A:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[INDVARS_IV]]
23+
; CHECK-NEXT: [[L_A:%.*]] = load i32, ptr [[GEP_A]], align 4
24+
; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[L_A]], [[L_B]]
25+
; CHECK-NEXT: store i32 [[ADD]], ptr [[GEP_A]], align 4
26+
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], [[TMP1]]
27+
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[INDVARS_IV_NEXT]], 32000
28+
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP0:![0-9]+]]
29+
; CHECK: for.end:
30+
; CHECK-NEXT: ret void
31+
;
32+
entry:
33+
%sub = sub nsw i32 %xa, 1
34+
br label %for.cond
35+
36+
for.cond:
37+
%i.0 = phi i32 [ %sub, %entry ], [ %add3, %for.inc ]
38+
%cmp = icmp slt i32 %i.0, 32000
39+
br i1 %cmp, label %for.body, label %for.cond.cleanup
40+
41+
for.body:
42+
%idxprom = sext i32 %i.0 to i64
43+
%gep.b = getelementptr inbounds i32, ptr %b, i64 %idxprom
44+
%l.b = load i32, ptr %gep.b, align 4
45+
%idxprom1 = sext i32 %i.0 to i64
46+
%gep.a = getelementptr inbounds i32, ptr %a, i64 %idxprom1
47+
%l.a = load i32, ptr %gep.a , align 4
48+
%add = add nsw i32 %l.a, %l.b
49+
store i32 %add, ptr %gep.a, align 4
50+
br label %for.inc
51+
52+
for.inc:
53+
%add3 = add nsw i32 %i.0, %xb
54+
br label %for.cond, !llvm.loop !0
55+
56+
for.cond.cleanup:
57+
br label %for.end
58+
59+
for.end:
60+
ret void
61+
}
62+
63+
!0 = distinct !{!0, !1}
64+
!1 = !{!"llvm.loop.mustprogress"}
65+
;.
66+
; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]]}
67+
; CHECK: [[META1]] = !{!"llvm.loop.mustprogress"}
68+
;.

0 commit comments

Comments
 (0)