================
@@ -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!");
----------------
uweigand wrote:

Why do we need those asserts?  The correctness of the transformation doesn't 
depend on it, does it?

https://github.com/llvm/llvm-project/pull/169317
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to