[clang] [llvm] [SystemZ] Global Stackprotector and associated location section (PR #169317)
Dominik Steenken via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 12 05:08:45 PST 2026
================
@@ -3545,6 +3546,45 @@ static Comparison getIntrinsicCmp(SelectionDAG &DAG, unsigned Opcode,
return C;
}
+namespace {
+// Check if a given Compare is a check of the stack guard against a stack
+// guard instance on the stack. Specifically, this checks if:
+// - The operands are a load of the stack guard, and a load from a stack slot
+// - Those operand values are not used elsewhere <-- asserts if this is not
+// true!
+// This function sets ShouldSwap to true, iff a swap would put the load from
+// the stack slot in the position 0.
+bool isStackGuardCompare(SDValue CmpOp0, SDValue CmpOp1, bool &ShouldSwap) {
+ SDValue StackGuardLoad;
+ LoadSDNode *FILoad;
+
+ if (CmpOp0.isMachineOpcode() &&
+ CmpOp0.getMachineOpcode() == SystemZ::LOAD_STACK_GUARD &&
+ ISD::isNormalLoad(CmpOp1.getNode()) &&
+ dyn_cast<FrameIndexSDNode>(CmpOp1.getOperand(1))) {
+ StackGuardLoad = CmpOp0;
+ FILoad = cast<LoadSDNode>(CmpOp1);
+ ShouldSwap = true;
+ } else if ((CmpOp1.isMachineOpcode() &&
+ CmpOp1.getMachineOpcode() == SystemZ::LOAD_STACK_GUARD &&
+ ISD::isNormalLoad(CmpOp0.getNode()) &&
+ dyn_cast<FrameIndexSDNode>(CmpOp0.getOperand(1)))) {
+ StackGuardLoad = CmpOp1;
+ FILoad = cast<LoadSDNode>(CmpOp0);
+ } else {
+ return false;
+ }
+ // Assert that the values of the loads are not used elsewhere.
+ // Bail for now. TODO: What is the proper response here?
+ assert(
+ SDValue(FILoad, 0).hasOneUse() &&
+ "Value of stackguard loaded from stack must be used for compare only!");
+ assert(StackGuardLoad.hasOneUse() &&
+ "Value of reference stackguard must be used for compare only!");
----------------
dominik-steenken wrote:
I suppose the idea here was that if these loads are uised somewhere else, then what we have is a different pattern than the one we expected, e.g. the load of the value of the stackguard from the stack should really only be used once, in the compare - if something else uses it, something weird is going on.
https://github.com/llvm/llvm-project/pull/169317
More information about the cfe-commits
mailing list