[llvm] [AMDGPU] Fix DynamicCallStack remark reporting unknown state as False (PR #192233)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 15 03:45:09 PDT 2026


https://github.com/StevenYangCC created https://github.com/llvm/llvm-project/pull/192233

When the DynamicCallStack MCExpr cannot be evaluated as an absolute value (e.g., for functions with unresolved callee dependencies), the kernel-resource-usage remark previously defaulted to reporting "Dynamic Stack: False". This is semantically incorrect and non-conservative, as it reports no dynamic stack when the status is actually unknown.

Fix by falling back to printing the symbolic MCExpr representation when the expression cannot be evaluated, consistent with how other unresolvable resource usage fields (TotalSGPRs, Occupancy) are reported.

>From 863ff4d37c9a52e89be8b8f4719bf1c73df36e05 Mon Sep 17 00:00:00 2001
From: "chengcang.yang" <yangchengcang at gmail.com>
Date: Wed, 15 Apr 2026 17:15:27 +0800
Subject: [PATCH] [AMDGPU] Fix DynamicCallStack remark reporting unknown state
 as False

When the DynamicCallStack MCExpr cannot be evaluated as an absolute
value (e.g., for functions with unresolved callee dependencies), the
kernel-resource-usage remark previously defaulted to reporting
"Dynamic Stack: False". This is semantically incorrect and
non-conservative, as it reports no dynamic stack when the status is
actually unknown.

Fix by falling back to printing the symbolic MCExpr representation
when the expression cannot be evaluated, consistent with how other
unresolvable resource usage fields (TotalSGPRs, Occupancy) are
reported.
---
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index 856b734ec91e5..59a9c34108ce5 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -1765,11 +1765,12 @@ void AMDGPUAsmPrinter::emitResourceUsageRemarks(
   EmitResourceUsageRemark("ScratchSize", "ScratchSize [bytes/lane]",
                           getMCExprStr(CurrentProgramInfo.ScratchSize));
   int64_t DynStack;
-  bool DynStackEvaluatable =
-      CurrentProgramInfo.DynamicCallStack->evaluateAsAbsolute(DynStack);
-  StringRef DynamicStackStr =
-      DynStackEvaluatable && DynStack ? "True" : "False";
-  EmitResourceUsageRemark("DynamicStack", "Dynamic Stack", DynamicStackStr);
+  if (CurrentProgramInfo.DynamicCallStack->evaluateAsAbsolute(DynStack))
+    EmitResourceUsageRemark("DynamicStack", "Dynamic Stack",
+                            StringRef(DynStack ? "True" : "False"));
+  else
+    EmitResourceUsageRemark("DynamicStack", "Dynamic Stack",
+                            getMCExprStr(CurrentProgramInfo.DynamicCallStack));
   EmitResourceUsageRemark("Occupancy", "Occupancy [waves/SIMD]",
                           getMCExprStr(CurrentProgramInfo.Occupancy));
   EmitResourceUsageRemark("SGPRSpill", "SGPRs Spill",



More information about the llvm-commits mailing list