Skip to content

Commit 416084c

Browse files
committed
drop tbaa and memparallelloopaccess, add 3 dx mds, simplify test
1 parent 19de155 commit 416084c

File tree

2 files changed

+30
-52
lines changed

2 files changed

+30
-52
lines changed

llvm/lib/Target/DirectX/DXILPrepare.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ class DXILPrepareModule : public ModulePass {
161161
Builder.getPtrTy(PtrTy->getAddressSpace())));
162162
}
163163

164+
static llvm::SmallVector<unsigned> getCompatibleInstructionMDs(Module &M) {
165+
llvm::SmallVector<unsigned, 16> ret = {
166+
M.getMDKindID("dx.nonuniform"),
167+
M.getMDKindID("dx.controlflow.hints"),
168+
M.getMDKindID("dx.precise"),
169+
LLVMContext::MD_prof,
170+
LLVMContext::MD_fpmath,
171+
LLVMContext::MD_range,
172+
LLVMContext::MD_tbaa_struct,
173+
LLVMContext::MD_invariant_load,
174+
LLVMContext::MD_alias_scope,
175+
LLVMContext::MD_noalias,
176+
LLVMContext::MD_nontemporal,
177+
LLVMContext::MD_nonnull,
178+
LLVMContext::MD_dereferenceable,
179+
LLVMContext::MD_dereferenceable_or_null};
180+
181+
return ret;
182+
}
183+
164184
public:
165185
bool runOnModule(Module &M) override {
166186
PointerTypeMap PointerTypes = PointerTypeAnalysis::run(M);
@@ -176,6 +196,10 @@ class DXILPrepareModule : public ModulePass {
176196
VersionTuple ValVer = MetadataInfo.ValidatorVersion;
177197
bool SkipValidation = ValVer.getMajor() == 0 && ValVer.getMinor() == 0;
178198

199+
// construct whitelist of valid metadata node kinds
200+
llvm::SmallVector<unsigned> DXILCompatibleMDs =
201+
getCompatibleInstructionMDs(M);
202+
179203
for (auto &F : M.functions()) {
180204
F.removeFnAttrs(AttrMask);
181205
F.removeRetAttrs(AttrMask);
@@ -190,23 +214,6 @@ class DXILPrepareModule : public ModulePass {
190214
IRBuilder<> Builder(&BB);
191215
for (auto &I : make_early_inc_range(BB)) {
192216

193-
// TODO: Audit this list - is it enough? Too much?
194-
static unsigned DXILCompatibleMDs[] = {
195-
LLVMContext::MD_dbg,
196-
LLVMContext::MD_tbaa,
197-
LLVMContext::MD_prof,
198-
LLVMContext::MD_fpmath,
199-
LLVMContext::MD_range,
200-
LLVMContext::MD_tbaa_struct,
201-
LLVMContext::MD_invariant_load,
202-
LLVMContext::MD_alias_scope,
203-
LLVMContext::MD_noalias,
204-
LLVMContext::MD_nontemporal,
205-
LLVMContext::MD_mem_parallel_loop_access,
206-
LLVMContext::MD_nonnull,
207-
LLVMContext::MD_dereferenceable,
208-
LLVMContext::MD_dereferenceable_or_null,
209-
};
210217
I.dropUnknownNonDebugMetadata(DXILCompatibleMDs);
211218

212219
if (I.getOpcode() == Instruction::FNeg) {

llvm/test/CodeGen/DirectX/metadata-stripping.ll

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,18 @@ target triple = "dxilv1.0-unknown-shadermodel6.0-compute"
1717

1818
; Function Attrs: noinline nounwind memory(readwrite, inaccessiblemem: none)
1919
define void @main() local_unnamed_addr #0 {
20-
entry:
21-
%_ZL1X_h.i.i3 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 0, i32 0, i1 false) #1
22-
%0 = call i32 @dx.op.threadId.i32(i32 93, i32 0) #2
23-
%1 = call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68, %dx.types.Handle %_ZL1X_h.i.i3, i32 %0, i32 0) #1
24-
%2 = extractvalue %dx.types.ResRet.i32 %1, 0
25-
%cmp.i1.not = icmp eq i32 %2, 0
26-
br i1 %cmp.i1.not, label %_Z4mainDv3_j.exit, label %for.body.i.lr.ph
27-
28-
for.body.i.lr.ph: ; preds = %entry
29-
%_ZL3Out_h.i.i5 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 0, i32 0, i1 false) #1
30-
%_ZL2In_h.i.i4 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 1, i32 1, i1 false) #1
31-
%3 = call %dx.types.ResRet.f32 @dx.op.bufferLoad.f32(i32 68, %dx.types.Handle %_ZL2In_h.i.i4, i32 %0, i32 0) #1
32-
%4 = extractvalue %dx.types.ResRet.f32 %3, 0
33-
%5 = extractvalue %dx.types.ResRet.f32 %3, 1
34-
%6 = extractvalue %dx.types.ResRet.f32 %3, 2
35-
%7 = extractvalue %dx.types.ResRet.f32 %3, 3
36-
br label %for.body.i
37-
38-
for.body.i: ; preds = %for.body.i.lr.ph, %for.body.i
39-
%I.0.i2 = phi i32 [ 0, %for.body.i.lr.ph ], [ %inc.i, %for.body.i ]
40-
call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %_ZL3Out_h.i.i5, i32 %0, i32 0, float %4, float %5, float %6, float %7, i8 15)
41-
%inc.i = add nuw i32 %I.0.i2, 1
42-
%8 = call %dx.types.ResRet.i32 @dx.op.bufferLoad.i32(i32 68, %dx.types.Handle %_ZL1X_h.i.i3, i32 %0, i32 0) #1
43-
%9 = extractvalue %dx.types.ResRet.i32 %8, 0
44-
; CHECK: %cmp.i = icmp ult i32 %inc.i, %9
45-
; CHECK-NEXT: br i1 %cmp.i, label %for.body.i, label %_Z4mainDv3_j.exit
46-
%cmp.i = icmp ult i32 %inc.i, %9
20+
entry:
21+
%cmp.i1.not = icmp eq i32 1, 0
22+
br i1 %cmp.i1.not, label %_Z4mainDv3_j.exit, label %for.body.i
23+
24+
for.body.i: ; preds = %entry
25+
%cmp.i = icmp ult i32 1, 2
4726
br i1 %cmp.i, label %for.body.i, label %_Z4mainDv3_j.exit, !llvm.loop !16
4827

4928
_Z4mainDv3_j.exit: ; preds = %for.body.i, %entry
5029
ret void
5130

5231
; uselistorder directives
53-
uselistorder %dx.types.Handle %_ZL1X_h.i.i3, { 1, 0 }
54-
uselistorder i32 %0, { 3, 0, 1, 2 }
5532
uselistorder label %for.body.i, { 1, 0 }
5633
}
5734

@@ -66,12 +43,6 @@ declare %dx.types.ResRet.f32 @dx.op.bufferLoad.f32(i32, %dx.types.Handle, i32, i
6643
declare void @dx.op.bufferStore.f32(i32, %dx.types.Handle, i32, i32, float, float, float, float, i8)
6744

6845
; uselistorder directives
69-
uselistorder i32 57, { 1, 0, 2 }
70-
uselistorder i32 0, { 3, 0, 10, 1, 5, 6, 9, 2, 4, 7, 8 }
71-
uselistorder i1 false, { 1, 0, 2 }
72-
uselistorder i32 68, { 2, 0, 1 }
73-
uselistorder i32 1, { 2, 0, 1 }
74-
uselistorder ptr @dx.op.createHandle, { 2, 0, 1 }
7546

7647
attributes #0 = { noinline nounwind memory(readwrite, inaccessiblemem: none) }
7748
attributes #1 = { memory(read) }

0 commit comments

Comments
 (0)