Skip to content

Commit faffc9f

Browse files
kasuga-fjgithub-actions[bot]
authored andcommitted
Automerge: [LoopVectorize] Add test for follow-up metadata for loops (NFC) (#131337)
When pragma of loop transformations are encoded in LLVM IR, follow-up metadata is used if multiple transformations are specified. They are used to explicitly express the order of the transformations. However, they are not properly processed on each transformation pass, so now only the first one is attempted to be applied. This is a pre-commit to add a test that causes the problem. ref: llvm/llvm-project#127474 (comment)
2 parents a28e760 + e24e523 commit faffc9f

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -passes='loop-vectorize,loop-unroll' -force-vector-width=4 -S < %s | FileCheck %s
3+
4+
; Test if the follow-up metadata for loops works fine. The original code is
5+
; something like below. In this case, unrolling should be applied after
6+
; vectorization.
7+
;
8+
; void f(float *a, float x) {
9+
; #pragma clang loop vectorize(enable) unroll_count(8)
10+
; for (int i = 0; i < 1024; i++) {
11+
; a[i] *= x;
12+
; }
13+
; }
14+
;
15+
; FIXME: Currently unrolling is not applied. This is because the new Loop ID
16+
; created after vectorization does not directly contain unroll metadata.
17+
; Unexpected nests have been created.
18+
define void @f(ptr noundef captures(none) %a, float noundef %x) {
19+
; CHECK-LABEL: define void @f(
20+
; CHECK-SAME: ptr noundef captures(none) [[A:%.*]], float noundef [[X:%.*]]) {
21+
; CHECK-NEXT: [[ENTRY:.*]]:
22+
; CHECK-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
23+
; CHECK: [[VECTOR_PH]]:
24+
; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x float> poison, float [[X]], i64 0
25+
; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x float> [[BROADCAST_SPLATINSERT]], <4 x float> poison, <4 x i32> zeroinitializer
26+
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
27+
; CHECK: [[VECTOR_BODY]]:
28+
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
29+
; CHECK-NEXT: [[INDEX_NEXT_6:%.*]] = add i64 [[INDEX]], 0
30+
; CHECK-NEXT: [[TMP14:%.*]] = getelementptr inbounds nuw float, ptr [[A]], i64 [[INDEX_NEXT_6]]
31+
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds nuw float, ptr [[TMP14]], i32 0
32+
; CHECK-NEXT: [[WIDE_LOAD_7:%.*]] = load <4 x float>, ptr [[TMP2]], align 4
33+
; CHECK-NEXT: [[TMP15:%.*]] = fmul <4 x float> [[BROADCAST_SPLAT]], [[WIDE_LOAD_7]]
34+
; CHECK-NEXT: store <4 x float> [[TMP15]], ptr [[TMP2]], align 4
35+
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
36+
; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
37+
; CHECK-NEXT: br i1 [[TMP4]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
38+
; CHECK: [[MIDDLE_BLOCK]]:
39+
; CHECK-NEXT: br i1 true, label %[[EXIT:.*]], label %[[SCALAR_PH]]
40+
; CHECK: [[SCALAR_PH]]:
41+
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1024, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
42+
; CHECK-NEXT: br label %[[FOR_BODY:.*]]
43+
; CHECK: [[FOR_BODY]]:
44+
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[FOR_BODY]] ]
45+
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds nuw float, ptr [[A]], i64 [[IV]]
46+
; CHECK-NEXT: [[LOAD:%.*]] = load float, ptr [[ARRAYIDX]], align 4
47+
; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[LOAD]]
48+
; CHECK-NEXT: store float [[MUL]], ptr [[ARRAYIDX]], align 4
49+
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
50+
; CHECK-NEXT: [[COMP:%.*]] = icmp eq i64 [[IV_NEXT]], 1024
51+
; CHECK-NEXT: br i1 [[COMP]], label %[[EXIT_LOOPEXIT:.*]], label %[[FOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
52+
; CHECK: [[EXIT_LOOPEXIT]]:
53+
; CHECK-NEXT: br label %[[EXIT]]
54+
; CHECK: [[EXIT]]:
55+
; CHECK-NEXT: ret void
56+
;
57+
entry:
58+
br label %for.body
59+
60+
for.body:
61+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
62+
%arrayidx = getelementptr inbounds nuw float, ptr %a, i64 %iv
63+
%load = load float, ptr %arrayidx, align 4
64+
%mul = fmul float %x, %load
65+
store float %mul, ptr %arrayidx, align 4
66+
%iv.next = add nuw nsw i64 %iv, 1
67+
%comp = icmp eq i64 %iv.next, 1024
68+
br i1 %comp, label %exit, label %for.body, !llvm.loop !0
69+
70+
exit:
71+
ret void
72+
}
73+
74+
!0 = distinct !{!0, !1, !2}
75+
!1 = !{!"llvm.loop.vectorize.enable", i1 true}
76+
!2 = !{!"llvm.loop.vectorize.followup_all", !3}
77+
!3 = distinct !{!3, !4, !5}
78+
!4 = !{!"llvm.loop.isvectorized"}
79+
!5 = !{!"llvm.loop.unroll.count", i32 8}
80+
;.
81+
; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META4:![0-9]+]]}
82+
; CHECK: [[META1]] = distinct !{[[META1]], [[META2:![0-9]+]], [[META3:![0-9]+]]}
83+
; CHECK: [[META2]] = !{!"llvm.loop.isvectorized"}
84+
; CHECK: [[META3]] = !{!"llvm.loop.unroll.count", i32 8}
85+
; CHECK: [[META4]] = !{!"llvm.loop.unroll.runtime.disable"}
86+
; CHECK: [[LOOP5]] = distinct !{[[LOOP5]], [[META1]]}
87+
;.

0 commit comments

Comments
 (0)