[llvm] [X86] Don't fold loads from non-fixed stack objects into tail calls (PR #221243)
Akash Manna via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 7 01:30:33 PDT 2026
================
@@ -3682,7 +3683,40 @@ static bool mayUseCarryFlag(X86::CondCode CC) {
return true;
}
+/// Return true if \p Addr may be matched with a non-fixed frame index as base.
+static bool addrMayUseNonFixedFrameIndex(SDValue Addr,
+ const MachineFrameInfo &MFI,
+ unsigned Depth = 0) {
+ if (auto *FI = dyn_cast<FrameIndexSDNode>(Addr))
+ return !MFI.isFixedObjectIndex(FI->getIndex());
+ // Assume the worst if we can't see the whole address expression.
+ if (Depth >= SelectionDAG::MaxRecursionDepth)
+ return true;
+ switch (Addr.getOpcode()) {
+ case ISD::ADD:
+ case ISD::OR:
+ case ISD::XOR:
+ return addrMayUseNonFixedFrameIndex(Addr.getOperand(0), MFI, Depth + 1) ||
+ addrMayUseNonFixedFrameIndex(Addr.getOperand(1), MFI, Depth + 1);
+ case ISD::SUB:
+ return addrMayUseNonFixedFrameIndex(Addr.getOperand(0), MFI, Depth + 1);
+ default:
+ // Only add-like nodes and the LHS of a SUB can fold a frame index into the
+ // base; anything else is matched as a register or symbol base.
+ return false;
+ }
+}
+
bool X86DAGToDAGISel::checkTCRetEnoughRegs(SDNode *N) const {
+ assert(N->getOpcode() == X86ISD::TC_RETURN);
+ // X86tcret args: (*chain, ptr, imm, regs..., glue)
+ auto *Load = cast<LoadSDNode>(N->getOperand(1));
----------------
akash-manna-sky wrote:
moved the original `BasePtr` line up and dropped the `Load` temporary.
https://github.com/llvm/llvm-project/pull/221243
More information about the llvm-commits
mailing list