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