[llvm] [DirectX] Disable all libcalls for DXIL in TargetLibraryInfo.cpp (PR #138991)

Deric C. via llvm-commits llvm-commits at lists.llvm.org
Wed May 7 16:37:10 PDT 2025


https://github.com/Icohedron created https://github.com/llvm/llvm-project/pull/138991

Fixes #138787

To the best of my knowledge, DXIL does not (and should not) support any of the libcalls in `TargetLibraryInfo.def`.
Math libcalls are not used in HLSL and also do not have lowerings to DXIL. (The current implementation of math functions are done via intrinsics.)
If there is a mistake with disabling all libcalls, then the libcalls we need can be re-enabled in a follow-up PR.

Locally, the codegen tests for Clang HLSL and the DirectX backend appear to pass without any issues.
The offload test suite's clang-d3d12 tests are also passing locally.
The change this PR introduces also eliminates the problematic memcpy intrinsics operating with a non-constant length argument and addrspace(3) ptrs showing up when compiling DML shaders. The number of DML shaders compiling successfully is greater with this PR.


>From 007a1ae47ca554015f48412ee9677036652388e6 Mon Sep 17 00:00:00 2001
From: Icohedron <cheung.deric at gmail.com>
Date: Wed, 7 May 2025 23:17:42 +0000
Subject: [PATCH] Disable all libcalls for DXIL

---
 llvm/lib/Analysis/TargetLibraryInfo.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 3945dd4a8b55d..1934fb4e1fa26 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -205,6 +205,11 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
     return;
   }
 
+  if (T.isDXIL()) {
+    TLI.disableAllFunctions();
+    return;
+  }
+
   // memset_pattern{4,8,16} is only available on iOS 3.0 and Mac OS X 10.5 and
   // later. All versions of watchOS support it.
   if (T.isMacOSX()) {



More information about the llvm-commits mailing list