[llvm-branch-commits] [llvm] [TargetLowering][X86] Prefer 'r' over 'm' for foldable "rm" inline asm operands (PR #229632)

Nick Desaulniers via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Oct 8 12:48:37 PDT 2026


================
@@ -6234,6 +6234,42 @@ unsigned TargetLowering::AsmOperandInfo::getMatchedOperand() const {
   return atoi(ConstraintCode.c_str());
 }
 
+/// Return true if \p OpInfo is an "rm" operand that should prefer a register,
+/// leaving the register allocator to fold it to a stack slot if it runs out of
+/// registers (see AsmOperandInfo::MayFoldRegister).
+static bool
+shouldPreferFoldableRegister(const TargetLowering &TLI,
+                             const TargetRegisterInfo *TRI,
+                             const TargetLowering::AsmOperandInfo &OpInfo) {
+  // Codes stays empty for a constraint with alternatives ("r|m") until one is
+  // selected, so this only ever matches a plain "rm".
+  if (OpInfo.Codes.size() != 2 || !is_contained(OpInfo.Codes, "r") ||
+      !is_contained(OpInfo.Codes, "m"))
----------------
nickdesaulniers wrote:

This doesn't look right to me.

"g" is shorthand for "imr" (or as I like to think of it "I don't give a shit")(expanded in the front end).  This is pretty common IMO.

https://godbolt.org/z/ddPbTGsbY

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


More information about the llvm-branch-commits mailing list