From 1e03408d4b17a792da5fd01b30f05ff055cfbd79 Mon Sep 17 00:00:00 2001 From: Farzon Lotfi Date: Sat, 29 Mar 2025 00:45:11 -0400 Subject: [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%. --- llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'llvm/lib') diff --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp index 91ac758..7651617 100644 --- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp +++ b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp @@ -18,7 +18,7 @@ using namespace llvm; static bool finalizeLinkage(Module &M) { - SmallPtrSet Funcs; + SmallVector Funcs; // Collect non-entry and non-exported functions to set to internal linkage. for (Function &EF : M.functions()) { @@ -26,7 +26,7 @@ static bool finalizeLinkage(Module &M) { continue; if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export")) continue; - Funcs.insert(&EF); + Funcs.push_back(&EF); } for (Function *F : Funcs) { @@ -36,6 +36,14 @@ static bool finalizeLinkage(Module &M) { M.getFunctionList().erase(F); } + // Do a pass over intrinsics that are no longer used and remove them. + Funcs.clear(); + for (Function &F : M.functions()) + if (F.isIntrinsic() && F.use_empty()) + Funcs.push_back(&F); + for (Function *F : Funcs) + F->eraseFromParent(); + return false; } -- cgit v1.1