Skip to content

Commit f027a93

Browse files
committed
review: add additional checks for full/disable
1 parent b3bf5cb commit f027a93

File tree

3 files changed

+129
-5
lines changed

3 files changed

+129
-5
lines changed

llvm/lib/Target/DirectX/DXILValidateMetadata.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,14 @@ static void validateLoopMetadata(Module &M, MDNode *LoopMD) {
129129
return false;
130130
};
131131

132-
if (HintStr->getString() == "llvm.loop.unroll.count" &&
133-
!ValidCountNode(LoopMD)) {
134-
reportLoopError(M, "Second operand of \"llvm.loop.unroll.count\" "
135-
"must be a constant integer");
132+
if (HintStr->getString() == "llvm.loop.unroll.count") {
133+
if (!ValidCountNode(LoopMD)) {
134+
reportLoopError(M, "Second operand of \"llvm.loop.unroll.count\" "
135+
"must be a constant integer");
136+
return;
137+
}
138+
} else if (LoopMD->getNumOperands() != 1) {
139+
reportLoopError(M, "Can't have a second operand");
136140
return;
137141
}
138142
}

llvm/test/CodeGen/DirectX/Metadata/loop-md-errs.ll

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
; RUN: not opt -S --dxil-validate-metadata %t/not-md.ll 2>&1 | FileCheck %t/not-md.ll
55
; RUN: not opt -S --dxil-validate-metadata %t/not-str.ll 2>&1 | FileCheck %t/not-str.ll
66
; RUN: not opt -S --dxil-validate-metadata %t/bad-count.ll 2>&1 | FileCheck %t/bad-count.ll
7+
; RUN: not opt -S --dxil-validate-metadata %t/invalid-disable.ll 2>&1 | FileCheck %t/invalid-disable.ll
8+
; RUN: not opt -S --dxil-validate-metadata %t/invalid-full.ll 2>&1 | FileCheck %t/invalid-full.ll
79

810
; Test that loop metadata is validated as with the DXIL validator
911

@@ -133,3 +135,56 @@ exit:
133135

134136
!1 = !{!1, !2}
135137
!2 = !{!"llvm.loop.unroll.count", !"not an int"} ; invalid count parameters
138+
139+
;--- invalid-disable.ll
140+
141+
; CHECK: Invalid "llvm.loop" metadata: Can't have a second operand
142+
143+
target triple = "dxilv1.0-unknown-shadermodel6.0-library"
144+
145+
define void @example_loop(i32 %n) {
146+
entry:
147+
br label %loop.header
148+
149+
loop.header:
150+
%i = phi i32 [ 0, %entry ], [ %i.next, %loop.body ]
151+
%cmp = icmp slt i32 %i, %n
152+
br i1 %cmp, label %loop.body, label %exit
153+
154+
loop.body:
155+
%i.next = add nsw i32 %i, 1
156+
br label %loop.header, !llvm.loop !1
157+
158+
exit:
159+
ret void
160+
}
161+
162+
!1 = !{!1, !2}
163+
!2 = !{!"llvm.loop.unroll.disable", i32 0} ; invalid second operand
164+
165+
166+
;--- invalid-full.ll
167+
168+
; CHECK: Invalid "llvm.loop" metadata: Can't have a second operand
169+
170+
target triple = "dxilv1.0-unknown-shadermodel6.0-library"
171+
172+
define void @example_loop(i32 %n) {
173+
entry:
174+
br label %loop.header
175+
176+
loop.header:
177+
%i = phi i32 [ 0, %entry ], [ %i.next, %loop.body ]
178+
%cmp = icmp slt i32 %i, %n
179+
br i1 %cmp, label %loop.body, label %exit
180+
181+
loop.body:
182+
%i.next = add nsw i32 %i, 1
183+
br label %loop.header, !llvm.loop !1
184+
185+
exit:
186+
ret void
187+
}
188+
189+
!1 = !{!1, !2}
190+
!2 = !{!"llvm.loop.unroll.full", i32 0} ; invalid second operand

llvm/test/CodeGen/DirectX/Metadata/loop-md-valid.ll

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
; RUN: opt -S --dxil-validate-metadata %s | FileCheck %s
1+
; RUN: split-file %s %t
2+
; RUN: opt -S --dxil-validate-metadata %t/count.ll | FileCheck %t/count.ll
3+
; RUN: opt -S --dxil-validate-metadata %t/disable.ll | FileCheck %t/disable.ll
4+
; RUN: opt -S --dxil-validate-metadata %t/full.ll | FileCheck %t/full.ll
5+
6+
;--- count.ll
27

38
; Test that we allow a self-referential chain and a constant integer in count
49

@@ -29,3 +34,63 @@ exit:
2934
!0 = !{!0, !1}
3035
!1 = !{!1, !2}
3136
!2 = !{!"llvm.loop.unroll.count", i6 4}
37+
38+
;--- disable.ll
39+
40+
; Test that we allow a disable hint
41+
42+
target triple = "dxilv1.0-unknown-shadermodel6.0-library"
43+
44+
define void @example_loop(i32 %n) {
45+
entry:
46+
br label %loop.header
47+
48+
loop.header:
49+
%i = phi i32 [ 0, %entry ], [ %i.next, %loop.body ]
50+
%cmp = icmp slt i32 %i, %n
51+
br i1 %cmp, label %loop.body, label %exit
52+
53+
loop.body:
54+
%i.next = add nsw i32 %i, 1
55+
; CHECK: br label %loop.header, !llvm.loop ![[#LOOP_MD:]]
56+
br label %loop.header, !llvm.loop !0
57+
58+
exit:
59+
ret void
60+
}
61+
62+
; CHECK: ![[#LOOP_MD]] = distinct !{![[#LOOP_MD]], ![[#DISABLE:]]}
63+
; CHECK: ![[#DISABLE]] = !{!"llvm.loop.unroll.disable"}
64+
65+
!0 = !{!0, !1}
66+
!1 = !{!"llvm.loop.unroll.disable"}
67+
68+
;--- full.ll
69+
70+
; Test that we allow a full hint
71+
72+
target triple = "dxilv1.0-unknown-shadermodel6.0-library"
73+
74+
define void @example_loop(i32 %n) {
75+
entry:
76+
br label %loop.header
77+
78+
loop.header:
79+
%i = phi i32 [ 0, %entry ], [ %i.next, %loop.body ]
80+
%cmp = icmp slt i32 %i, %n
81+
br i1 %cmp, label %loop.body, label %exit
82+
83+
loop.body:
84+
%i.next = add nsw i32 %i, 1
85+
; CHECK: br label %loop.header, !llvm.loop ![[#LOOP_MD:]]
86+
br label %loop.header, !llvm.loop !0
87+
88+
exit:
89+
ret void
90+
}
91+
92+
; CHECK: ![[#LOOP_MD]] = distinct !{![[#LOOP_MD]], ![[#FULL:]]}
93+
; CHECK: ![[#FULL]] = !{!"llvm.loop.unroll.full"}
94+
95+
!0 = !{!0, !1}
96+
!1 = !{!"llvm.loop.unroll.full"}

0 commit comments

Comments
 (0)