Commit 0e2f0d7a authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r257730:

------------------------------------------------------------------------
r257730 | majnemer | 2016-01-13 17:20:03 -0800 (Wed, 13 Jan 2016) | 11 lines

[X86] Don't alter HasOpaqueSPAdjustment after we've relied on it

We rely on HasOpaqueSPAdjustment not changing after we've calculated
things based on it.  Things like whether or not we can use 'rep;movs' to
copy bytes around, that sort of thing.  If it changes, invariants in the
backend will quietly break.  This situation arose when we had a call to
memcpy *and* a COPY of the FLAGS register where we would attempt to
reference local variables using %esi, a register that was clobbered by
the 'rep;movs'.

This fixes PR26124.
------------------------------------------------------------------------

llvm-svn: 257779
parent 46669202
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -251,6 +251,10 @@ class MachineFrameInfo {
  /// opaque mechanism like inline assembly or Win32 EH.
  bool HasOpaqueSPAdjustment;

  /// True if the function contains operations which will lower down to
  /// instructions which manipulate the stack pointer.
  bool HasCopyImplyingStackAdjustment;

  /// True if the function contains a call to the llvm.vastart intrinsic.
  bool HasVAStart;

@@ -288,6 +292,7 @@ public:
    LocalFrameMaxAlign = 0;
    UseLocalStackAllocationBlock = false;
    HasOpaqueSPAdjustment = false;
    HasCopyImplyingStackAdjustment = false;
    HasVAStart = false;
    HasMustTailInVarArgFunc = false;
    Save = nullptr;
@@ -493,6 +498,15 @@ public:
  bool hasOpaqueSPAdjustment() const { return HasOpaqueSPAdjustment; }
  void setHasOpaqueSPAdjustment(bool B) { HasOpaqueSPAdjustment = B; }

  /// Returns true if the function contains operations which will lower down to
  /// instructions which manipulate the stack pointer.
  bool hasCopyImplyingStackAdjustment() const {
    return HasCopyImplyingStackAdjustment;
  }
  void setHasCopyImplyingStackAdjustment(bool B) {
    HasCopyImplyingStackAdjustment = B;
  }

  /// Returns true if the function calls the llvm.va_start intrinsic.
  bool hasVAStart() const { return HasVAStart; }
  void setHasVAStart(bool B) { HasVAStart = B; }
+1 −1
Original line number Diff line number Diff line
@@ -2270,7 +2270,7 @@ public:
  }

  /// Return true if the MachineFunction contains a COPY which would imply
  /// HasOpaqueSPAdjustment.
  /// HasCopyImplyingStackAdjustment.
  virtual bool hasCopyImplyingStackAdjustment(MachineFunction *MF) const {
    return false;
  }
+1 −1
Original line number Diff line number Diff line
@@ -634,7 +634,7 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
  }

  if (TLI->hasCopyImplyingStackAdjustment(MF))
    MFI->setHasOpaqueSPAdjustment(true);
    MFI->setHasCopyImplyingStackAdjustment(true);

  // Freeze the set of reserved registers now that MachineFrameInfo has been
  // set up. All the information required by getReservedRegs() should be
+7 −6
Original line number Diff line number Diff line
@@ -91,7 +91,8 @@ bool X86FrameLowering::hasFP(const MachineFunction &MF) const {
          MFI->isFrameAddressTaken() || MFI->hasOpaqueSPAdjustment() ||
          MF.getInfo<X86MachineFunctionInfo>()->getForceFramePointer() ||
          MMI.callsUnwindInit() || MMI.hasEHFunclets() || MMI.callsEHReturn() ||
          MFI->hasStackMap() || MFI->hasPatchPoint());
          MFI->hasStackMap() || MFI->hasPatchPoint() ||
          MFI->hasCopyImplyingStackAdjustment());
}

static unsigned getSUBriOpcode(unsigned IsLP64, int64_t Imm) {
@@ -946,7 +947,7 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF,
      !MFI->hasVarSizedObjects() &&             // No dynamic alloca.
      !MFI->adjustsStack() &&                   // No calls.
      !IsWin64CC &&                             // Win64 has no Red Zone
      !MFI->hasOpaqueSPAdjustment() && // Don't push and pop.
      !MFI->hasCopyImplyingStackAdjustment() && // Don't push and pop.
      !MF.shouldSplitStack()) {                 // Regular stack
    uint64_t MinSize = X86FI->getCalleeSavedFrameSize();
    if (HasFP) MinSize += SlotSize;
+1 −1
Original line number Diff line number Diff line
@@ -17458,7 +17458,7 @@ static SDValue LowerINTRINSIC_W_CHAIN(SDValue Op, const X86Subtarget *Subtarget,
      // We need a frame pointer because this will get lowered to a PUSH/POP
      // sequence.
      MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
      MFI->setHasOpaqueSPAdjustment(true);
      MFI->setHasCopyImplyingStackAdjustment(true);
      // Don't do anything here, we will expand these intrinsics out later
      // during ExpandISelPseudos in EmitInstrWithCustomInserter.
      return SDValue();
Loading