@@ -30953,6 +30953,34 @@ bool X86TargetLowering::areJTsAllowed(const Function *Fn) const {
3095330953// X86 Scheduler Hooks
3095430954//===----------------------------------------------------------------------===//
3095530955
30956+ // Returns true if EFLAG is consumed after this iterator in the rest of the
30957+ // basic block or any successors of the basic block.
30958+ static bool isEFLAGSLiveAfter(MachineBasicBlock::iterator Itr,
30959+ MachineBasicBlock *BB) {
30960+ // Scan forward through BB for a use/def of EFLAGS.
30961+ for (MachineBasicBlock::iterator miI = std::next(Itr), miE = BB->end();
30962+ miI != miE; ++miI) {
30963+ const MachineInstr& mi = *miI;
30964+ if (mi.readsRegister(X86::EFLAGS))
30965+ return true;
30966+ // If we found a def, we can stop searching.
30967+ if (mi.definesRegister(X86::EFLAGS))
30968+ return false;
30969+ }
30970+
30971+ // If we hit the end of the block, check whether EFLAGS is live into a
30972+ // successor.
30973+ for (MachineBasicBlock::succ_iterator sItr = BB->succ_begin(),
30974+ sEnd = BB->succ_end();
30975+ sItr != sEnd; ++sItr) {
30976+ MachineBasicBlock* succ = *sItr;
30977+ if (succ->isLiveIn(X86::EFLAGS))
30978+ return true;
30979+ }
30980+
30981+ return false;
30982+ }
30983+
3095630984/// Utility function to emit xbegin specifying the start of an RTM region.
3095730985static MachineBasicBlock *emitXBegin(MachineInstr &MI, MachineBasicBlock *MBB,
3095830986 const TargetInstrInfo *TII) {
@@ -30985,6 +31013,12 @@ static MachineBasicBlock *emitXBegin(MachineInstr &MI, MachineBasicBlock *MBB,
3098531013 MF->insert(I, fallMBB);
3098631014 MF->insert(I, sinkMBB);
3098731015
31016+ if (isEFLAGSLiveAfter(MI, MBB)) {
31017+ mainMBB->addLiveIn(X86::EFLAGS);
31018+ fallMBB->addLiveIn(X86::EFLAGS);
31019+ sinkMBB->addLiveIn(X86::EFLAGS);
31020+ }
31021+
3098831022 // Transfer the remainder of BB and its successor edges to sinkMBB.
3098931023 sinkMBB->splice(sinkMBB->begin(), MBB,
3099031024 std::next(MachineBasicBlock::iterator(MI)), MBB->end());
@@ -31373,27 +31407,8 @@ MachineBasicBlock *X86TargetLowering::EmitVAStartSaveXMMRegsWithCustomInserter(
3137331407static bool checkAndUpdateEFLAGSKill(MachineBasicBlock::iterator SelectItr,
3137431408 MachineBasicBlock* BB,
3137531409 const TargetRegisterInfo* TRI) {
31376- // Scan forward through BB for a use/def of EFLAGS.
31377- MachineBasicBlock::iterator miI(std::next(SelectItr));
31378- for (MachineBasicBlock::iterator miE = BB->end(); miI != miE; ++miI) {
31379- const MachineInstr& mi = *miI;
31380- if (mi.readsRegister(X86::EFLAGS))
31381- return false;
31382- if (mi.definesRegister(X86::EFLAGS))
31383- break; // Should have kill-flag - update below.
31384- }
31385-
31386- // If we hit the end of the block, check whether EFLAGS is live into a
31387- // successor.
31388- if (miI == BB->end()) {
31389- for (MachineBasicBlock::succ_iterator sItr = BB->succ_begin(),
31390- sEnd = BB->succ_end();
31391- sItr != sEnd; ++sItr) {
31392- MachineBasicBlock* succ = *sItr;
31393- if (succ->isLiveIn(X86::EFLAGS))
31394- return false;
31395- }
31396- }
31410+ if (isEFLAGSLiveAfter(SelectItr, BB))
31411+ return false;
3139731412
3139831413 // We found a def, or hit the end of the basic block and EFLAGS wasn't live
3139931414 // out. SelectMI should have a kill flag on EFLAGS.
0 commit comments