Skip to content

Commit 5ce954c

Browse files
authored
Removing dx.temp for lib target, since it's disallowed by the validator (microsoft#5832)
This change makes `DxilFinalizeModule` remove `dx.temp` metadata regardless of target profile. `DxilFinalizeModule` pass removes metadata that the validator disallows in the final DXIL. These metadata are only removed for non-lib target, however dx.temp is something that the validator does not allow even in lib target. There is no reason to keep this metadata because it's only used for inserting nops and that's not something we do when linking libraries.
1 parent 769b504 commit 5ce954c

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

lib/HLSL/DxilPreparePasses.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -800,28 +800,26 @@ class DxilFinalizeModule : public ModulePass {
800800
unsigned DxilMinor = 0;
801801
DM.GetDxilVersion(DxilMajor, DxilMinor);
802802

803-
bool IsLib = DM.GetShaderModel()->IsLib();
803+
DenseSet<unsigned> IllegalMDSet;
804+
unsigned DxilTempMDKind =
805+
M.getContext().getMDKindID(DxilMDHelper::kDxilTempAllocaMDName);
806+
IllegalMDSet.insert(DxilTempMDKind);
807+
804808
// Skip validation patch for lib.
809+
bool IsLib = DM.GetShaderModel()->IsLib();
805810
if (!IsLib) {
806-
unsigned DxilTempMDKind =
807-
M.getContext().getMDKindID(DxilMDHelper::kDxilTempAllocaMDName);
808811
if (DXIL::CompareVersions(ValMajor, ValMinor, 1, 1) <= 0) {
809-
DenseSet<unsigned> IllegalMDSet;
810812
IllegalMDSet.insert(LLVMContext::MD_tbaa);
811813
IllegalMDSet.insert(LLVMContext::MD_prof);
812814
for (unsigned I = LLVMContext::MD_fpmath + 1;
813815
I <= LLVMContext::MD_dereferenceable_or_null; ++I) {
814816
IllegalMDSet.insert(I);
815817
}
816-
IllegalMDSet.insert(DxilTempMDKind);
817-
patchInstructionMetadata(M, IllegalMDSet);
818-
} else {
819-
DenseSet<unsigned> IllegalMDSet;
820-
IllegalMDSet.insert(DxilTempMDKind);
821-
patchInstructionMetadata(M, IllegalMDSet);
822818
}
823819
}
824820

821+
patchInstructionMetadata(M, IllegalMDSet);
822+
825823
// Replace lifetime intrinsics if requested or necessary.
826824
const bool forceZeroStoreLifetimes = DM.GetForceZeroStoreLifetimes();
827825
if (forceZeroStoreLifetimes ||
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; RUN: opt -hlsl-dxil-module-init -hlsl-dxilfinalize %s -S | FileCheck %s
2+
3+
; Make sure !dx.temp is removed even for lib targets.
4+
5+
; CHECK-LABEL:define void @main
6+
; CHECK-NOT:!dx.temp
7+
8+
target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64"
9+
target triple = "dxil-ms-dx"
10+
11+
; Function Attrs: nounwind
12+
define void @main(float* noalias nocapture readnone) #0 {
13+
entry:
14+
call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 0, float 0.000000e+00), !dx.temp !9
15+
ret void
16+
}
17+
18+
; Function Attrs: nounwind
19+
declare void @dx.op.storeOutput.f32(i32, i32, i32, i8, float) #0
20+
21+
attributes #0 = { nounwind }
22+
23+
!llvm.module.flags = !{!0}
24+
!pauseresume = !{!1}
25+
!llvm.ident = !{!2}
26+
!dx.version = !{!3}
27+
!dx.valver = !{!4}
28+
!dx.shaderModel = !{!5}
29+
!dx.typeAnnotations = !{!6}
30+
!dx.entryPoints = !{!13, !14}
31+
32+
!0 = !{i32 2, !"Debug Info Version", i32 3}
33+
!1 = !{!"hlsl-dxilemit", !"hlsl-dxilload"}
34+
!2 = !{!"dxc(private) 1.7.0.14005 (main, 96e13a0e0-dirty)"}
35+
!3 = !{i32 1, i32 3}
36+
!4 = !{i32 1, i32 7}
37+
!5 = !{!"lib", i32 6, i32 3}
38+
!6 = !{i32 1, void (float*)* @main, !7}
39+
!7 = !{!8, !10}
40+
!8 = !{i32 0, !9, !9}
41+
!9 = !{}
42+
!10 = !{i32 1, !11, !12}
43+
!11 = !{i32 4, !"SV_Target", i32 7, i32 9}
44+
!12 = !{i32 0}
45+
!13 = !{null, !"", null, null, null}
46+
!14 = !{void (float*)* @main, !"main", !15, null, !18}
47+
!15 = !{null, !16, null}
48+
!16 = !{!17}
49+
!17 = !{i32 0, !"SV_Target", i8 9, i8 16, !12, i8 0, i32 1, i8 1, i32 0, i8 0, null}
50+
!18 = !{i32 8, i32 0, i32 5, !12}

0 commit comments

Comments
 (0)