Skip to content

Commit 1e03408

Browse files
authored
[DirectX] Remove intrinsic definitions with no use (#133459)
Do cleanup in DXILFinalizeLinkage.cpp where intrinsic declares are getting orphaned. This change reduces "Unsupported intrinsic for DXIL lowering" errors when compiling DML shaders from 12218 to 415. and improves our compilation success rate from less than 1% to 44%.
1 parent 2898c3e commit 1e03408

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
using namespace llvm;
1919

2020
static bool finalizeLinkage(Module &M) {
21-
SmallPtrSet<Function *, 8> Funcs;
21+
SmallVector<Function *> Funcs;
2222

2323
// Collect non-entry and non-exported functions to set to internal linkage.
2424
for (Function &EF : M.functions()) {
2525
if (EF.isIntrinsic())
2626
continue;
2727
if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export"))
2828
continue;
29-
Funcs.insert(&EF);
29+
Funcs.push_back(&EF);
3030
}
3131

3232
for (Function *F : Funcs) {
@@ -36,6 +36,14 @@ static bool finalizeLinkage(Module &M) {
3636
M.getFunctionList().erase(F);
3737
}
3838

39+
// Do a pass over intrinsics that are no longer used and remove them.
40+
Funcs.clear();
41+
for (Function &F : M.functions())
42+
if (F.isIntrinsic() && F.use_empty())
43+
Funcs.push_back(&F);
44+
for (Function *F : Funcs)
45+
F->eraseFromParent();
46+
3947
return false;
4048
}
4149

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
; RUN: llc %s -mtriple=dxil-pc-shadermodel6.3-library --filetype=asm -o - | FileCheck %s
3+
4+
declare void @llvm.lifetime.start.p0(i64, ptr) #1
5+
declare void @llvm.lifetime.end.p0(i64, ptr) #1
6+
declare i32 @llvm.dx.udot.v4i32(<4 x i32>, <4 x i32>) #2
7+
declare void @llvm.memset.p0.i32(ptr, i8, i32, i1) #3
8+
9+
; CHECK-NOT: declare void @llvm.lifetime.start.p0(i64, ptr)
10+
; CHECK-NOT: declare void @llvm.lifetime.end.p0(i64, ptr)
11+
; CHECK-NOT: declare i32 @llvm.dx.udot.v4i32(<4 x i32>, <4 x i32>)
12+
; CHECK-NOT: declare void @llvm.memset.p0.i32(ptr, i8, i32, i1)
13+
14+
; CHECK-LABEL: empty_fn
15+
define void @empty_fn () local_unnamed_addr #0 {
16+
ret void
17+
}
18+
19+
attributes #0 = { convergent norecurse nounwind "hlsl.export"}
20+
attributes #1 = { nounwind memory(argmem: readwrite) }
21+
attributes #2 = { nounwind memory(none) }
22+
attributes #3 = { nounwind memory(argmem: write) }

0 commit comments

Comments
 (0)