[llvm] [AMDGPU] Account for inline asm size in inst_pref_size calculation (PR #192306)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 02:00:28 PDT 2026


================
@@ -99,29 +103,30 @@ static int64_t op(AMDGPUMCExpr::VariantKind Kind, int64_t Arg1, int64_t Arg2) {
   }
 }
 
-bool AMDGPUMCExpr::evaluateExtraSGPRs(MCValue &Res,
-                                      const MCAssembler *Asm) const {
-  auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) {
+/// Evaluate an array of MCExpr to an array of uint64_t constants.
+/// Returns false if any expression fails to evaluate.
+static bool evaluateMCExprs(ArrayRef<const MCExpr *> Exprs,
+                            const MCAssembler *Asm,
+                            SmallVectorImpl<uint64_t> &Vals) {
+  for (const MCExpr *Expr : Exprs) {
     MCValue MCVal;
-    if (!Arg->evaluateAsRelocatable(MCVal, Asm) || !MCVal.isAbsolute())
+    if (!Expr->evaluateAsRelocatable(MCVal, Asm) || !MCVal.isAbsolute())
       return false;
+    Vals.push_back(MCVal.getConstant());
+  }
+  return true;
+}
 
-    ConstantValue = MCVal.getConstant();
-    return true;
-  };
-
+bool AMDGPUMCExpr::evaluateExtraSGPRs(MCValue &Res,
+                                      const MCAssembler *Asm) const {
   assert(Args.size() == 3 &&
          "AMDGPUMCExpr Argument count incorrect for ExtraSGPRs");
   const MCSubtargetInfo *STI = Ctx.getSubtargetInfo();
-  uint64_t VCCUsed = 0, FlatScrUsed = 0, XNACKUsed = 0;
-
-  bool Success = TryGetMCExprValue(Args[2], XNACKUsed);
 
-  assert(Success && "Arguments 3 for ExtraSGPRs should be a known constant");
-  if (!Success || !TryGetMCExprValue(Args[0], VCCUsed) ||
-      !TryGetMCExprValue(Args[1], FlatScrUsed))
+  SmallVector<uint64_t, 3> Vals;
+  if (!evaluateMCExprs(Args, Asm, Vals))
----------------
jayfoad wrote:

Maybe you can redesign `evaluateMCExprs` so you write this more like:
```
  uint64_t VCCUsed, FlatScrUsed, XNACKUsed;
  if (!evaluateMCExprs(Args, Asm, {VCCUsed, FlatScrUsed, XNACKUsed}))
```
?

Also if you're using this to refactor existing code then it really ought to go in a separate PR.

https://github.com/llvm/llvm-project/pull/192306


More information about the llvm-commits mailing list