@@ -30953,6 +30953,34 @@ bool X86TargetLowering::areJTsAllowed(const Function *Fn) const {
30953
30953
// X86 Scheduler Hooks
30954
30954
//===----------------------------------------------------------------------===//
30955
30955
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
+
30956
30984
/// Utility function to emit xbegin specifying the start of an RTM region.
30957
30985
static MachineBasicBlock *emitXBegin(MachineInstr &MI, MachineBasicBlock *MBB,
30958
30986
const TargetInstrInfo *TII) {
@@ -30985,6 +31013,12 @@ static MachineBasicBlock *emitXBegin(MachineInstr &MI, MachineBasicBlock *MBB,
30985
31013
MF->insert(I, fallMBB);
30986
31014
MF->insert(I, sinkMBB);
30987
31015
31016
+ if (isEFLAGSLiveAfter(MI, MBB)) {
31017
+ mainMBB->addLiveIn(X86::EFLAGS);
31018
+ fallMBB->addLiveIn(X86::EFLAGS);
31019
+ sinkMBB->addLiveIn(X86::EFLAGS);
31020
+ }
31021
+
30988
31022
// Transfer the remainder of BB and its successor edges to sinkMBB.
30989
31023
sinkMBB->splice(sinkMBB->begin(), MBB,
30990
31024
std::next(MachineBasicBlock::iterator(MI)), MBB->end());
@@ -31373,27 +31407,8 @@ MachineBasicBlock *X86TargetLowering::EmitVAStartSaveXMMRegsWithCustomInserter(
31373
31407
static bool checkAndUpdateEFLAGSKill(MachineBasicBlock::iterator SelectItr,
31374
31408
MachineBasicBlock* BB,
31375
31409
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;
31397
31412
31398
31413
// We found a def, or hit the end of the basic block and EFLAGS wasn't live
31399
31414
// out. SelectMI should have a kill flag on EFLAGS.
0 commit comments