Skip to content

[DirectX] Validator is erroring with Internal declaration '.*' is unused #139023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
farzonl opened this issue May 8, 2025 · 1 comment
Open

Comments

@farzonl
Copy link
Member

farzonl commented May 8, 2025

Three examples. In all three its happeing on array flattened values.

96x error: Internal declaration 'bTile.scalarized.1dim' is unused.
64x error: Internal declaration 'aTile.1dim' is unused.
32x error: Internal declaration 'aTile.scalarized.1dim' is unused.

Its curious that there was anything to flatten in these cases since we flatten after optimizations. I suspect these two types were used in a function that was cleaned up by Finalize Linkage but the global lived on.

looking at:

clang-dxc DirectML/Product/Shaders/Generated/ConvolutionIntegerFastPathShortGemm4_int_TRUE.hlsl -E CSMain -T cs_6_4  -enable-16bit-types  -O3 -D DXC_COMPILER=1 -D __SHADER_TARGET_MAJOR=6 -D __SHADER_TARGET_MINOR=4 -I DirectML/Product/Shaders/

I see these two and they are defined but not used. We should probably delete them if this is the case.

@aTile.1dim = local_unnamed_addr addrspace(3) global [64 x i32] zeroinitializer, align 4
@bTile.scalarized.1dim = local_unnamed_addr addrspace(3) global [512 x i32] zeroinitializer, align 4

We could add a check for uses to both DXILDataScalarization.cpp and DXILFlattenArrays.cpp. If there are no uses then we just delete and don't do transformations.

this is fixed by:

diff --git a/llvm/lib/Target/DirectX/DXILFlattenArrays.cpp b/llvm/lib/Target/DirectX/DXILFlattenArrays.cpp
index a3163a896964..88e4b64e1b43 100644
--- a/llvm/lib/Target/DirectX/DXILFlattenArrays.cpp
+++ b/llvm/lib/Target/DirectX/DXILFlattenArrays.cpp
@@ -380,7 +380,14 @@ static void
flattenGlobalArrays(Module &M,
                     DenseMap<GlobalVariable *, GlobalVariable *> &GlobalMap) {
   LLVMContext &Ctx = M.getContext();
+  SmallVector<GlobalVariable *> ToErase;
   for (GlobalVariable &G : M.globals()) {
+    
+    if (G.use_empty()) {
+      ToErase.push_back(&G);
+      continue;
+    }
+
     Type *OrigType = G.getValueType();
     if (!DXILFlattenArraysVisitor::isMultiDimensionalArray(OrigType))
       continue;
@@ -412,6 +419,9 @@ flattenGlobalArrays(Module &M,
     }
     GlobalMap[&G] = NewGlobal;
   }
+  for (GlobalVariable *GV : ToErase) {
+    GV->eraseFromParent();
+  }
}

However maybe this code should live at the start of our lowering pipeline. I think it makes the most sense to do something like this in DXILFinalizeLinkage. Alternatively we could wait for: llvm/wg-hlsl#272

@farzonl farzonl moved this to Planning in HLSL Support May 8, 2025
@bogner
Copy link
Contributor

bogner commented May 8, 2025

We should wait for llvm/wg-hlsl#272 and do this once it's done to avoid extra work

@damyanp damyanp removed the status in HLSL Support May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants