summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2015-12-01 19:49:31 +0000
committerQuentin Colombet <qcolombet@apple.com>2015-12-01 19:49:31 +0000
commit9cb01aa30a42c78248fea0a5c7335292718706b2 (patch)
tree98e699b530c3f38c10a14aad1fecfebd04181a03 /llvm/lib/Target
parent0e6a36e17e07485ee511756e022263a59101c79a (diff)
downloadbcm5719-llvm-9cb01aa30a42c78248fea0a5c7335292718706b2.tar.gz
bcm5719-llvm-9cb01aa30a42c78248fea0a5c7335292718706b2.zip
[X86] Make sure the prologue does not clobber EFLAGS when it lives accross it.
This fixes PR25629. llvm-svn: 254448
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r--llvm/lib/Target/X86/X86FrameLowering.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp
index f4f7f0cf33b..4ce3dfe0dcb 100644
--- a/llvm/lib/Target/X86/X86FrameLowering.cpp
+++ b/llvm/lib/Target/X86/X86FrameLowering.cpp
@@ -297,6 +297,28 @@ void X86FrameLowering::emitSPUpdate(MachineBasicBlock &MBB,
}
}
+// Check if \p MBB defines the flags register before the first terminator.
+static bool flagsDefinedLocally(const MachineBasicBlock &MBB) {
+ MachineBasicBlock::const_iterator FirstTerminator = MBB.getFirstTerminator();
+ for (MachineBasicBlock::const_iterator MII : MBB) {
+ if (MII == FirstTerminator)
+ return false;
+
+ for (const MachineOperand &MO : MII->operands()) {
+ if (!MO.isReg())
+ continue;
+ unsigned Reg = MO.getReg();
+ if (Reg != X86::EFLAGS)
+ continue;
+
+ // This instruction sets the eflag.
+ if (MO.isDef())
+ return true;
+ }
+ }
+ return false;
+}
+
MachineInstrBuilder X86FrameLowering::BuildStackAdjustment(
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, DebugLoc DL,
int64_t Offset, bool InEpilogue) const {
@@ -306,7 +328,16 @@ MachineInstrBuilder X86FrameLowering::BuildStackAdjustment(
// is tricky.
bool UseLEA;
if (!InEpilogue) {
- UseLEA = STI.useLeaForSP();
+ // Check if inserting the prologue at the beginning
+ // of MBB would require to use LEA operations.
+ // We need to use LEA operations if both conditions are true:
+ // 1. One of the terminators need the flags.
+ // 2. The flags are not defined after the insertion point of the prologue.
+ // Note: Checking for the predecessors is a shortcut when obviously nothing
+ // will live accross the prologue.
+ UseLEA = STI.useLeaForSP() ||
+ (!MBB.pred_empty() && terminatorsNeedFlagsAsInput(MBB) &&
+ !flagsDefinedLocally(MBB));
} else {
// If we can use LEA for SP but we shouldn't, check that none
// of the terminators uses the eflags. Otherwise we will insert
OpenPOWER on IntegriCloud