Description
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
Metadata
Metadata
Assignees
Type
Projects
Status
Activity
bogner commentedon May 8, 2025
We should wait for llvm/wg-hlsl#272 and do this once it's done to avoid extra work