Skip to content

Commit 815a9b2

Browse files
committed
[X86] Remove isSafeToClobberEFLAGS helper and just inline it into the call sites.
This is just a thin wrapper around computeRegisterLivness which we can just call directly. The only real difference is that isSafeToClobberEFLAGS returns a bool and computeRegisterLivness returns an enum. So we need to check for the specific enum value that isSafeToClobberEFLAGS was hiding. I've also adjusted which sites pass an explicit value for Neighborhood since the default for computeRegisterLivness is 10.
1 parent c888694 commit 815a9b2

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

llvm/lib/Target/X86/X86FixupLEAs.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ bool FixupLEAPass::optTwoAddrLEA(MachineBasicBlock::iterator &I,
376376
const MachineOperand &Segment = MI.getOperand(1 + X86::AddrSegmentReg);
377377

378378
if (Segment.getReg() != 0 || !Disp.isImm() || Scale.getImm() > 1 ||
379-
!TII->isSafeToClobberEFLAGS(MBB, I, 10))
379+
MBB.computeRegisterLiveness(TRI, X86::EFLAGS, I) !=
380+
MachineBasicBlock::LQR_Dead)
380381
return false;
381382

382383
Register DestReg = MI.getOperand(0).getReg();
@@ -505,7 +506,8 @@ void FixupLEAPass::processInstructionForSlowLEA(MachineBasicBlock::iterator &I,
505506
const MachineOperand &Segment = MI.getOperand(1 + X86::AddrSegmentReg);
506507

507508
if (Segment.getReg() != 0 || !Offset.isImm() ||
508-
!TII->isSafeToClobberEFLAGS(MBB, I))
509+
MBB.computeRegisterLiveness(TRI, X86::EFLAGS, I, 4) !=
510+
MachineBasicBlock::LQR_Dead)
509511
return;
510512
const Register DstR = Dst.getReg();
511513
const Register SrcR1 = Base.getReg();
@@ -555,7 +557,8 @@ void FixupLEAPass::processInstrForSlow3OpLEA(MachineBasicBlock::iterator &I,
555557
const MachineOperand &Segment = MI.getOperand(1 + X86::AddrSegmentReg);
556558

557559
if (!(TII->isThreeOperandsLEA(MI) || hasInefficientLEABaseReg(Base, Index)) ||
558-
!TII->isSafeToClobberEFLAGS(MBB, MI) ||
560+
MBB.computeRegisterLiveness(TRI, X86::EFLAGS, I, 4) !=
561+
MachineBasicBlock::LQR_Dead ||
559562
Segment.getReg() != X86::NoRegister)
560563
return;
561564

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,8 @@ void X86InstrInfo::reMaterialize(MachineBasicBlock &MBB,
11271127
const MachineInstr &Orig,
11281128
const TargetRegisterInfo &TRI) const {
11291129
bool ClobbersEFLAGS = Orig.modifiesRegister(X86::EFLAGS, &TRI);
1130-
if (ClobbersEFLAGS && !isSafeToClobberEFLAGS(MBB, I, 10)) {
1130+
if (ClobbersEFLAGS && MBB.computeRegisterLiveness(&TRI, X86::EFLAGS, I) !=
1131+
MachineBasicBlock::LQR_Dead) {
11311132
// The instruction clobbers EFLAGS. Re-materialize as MOV32ri to avoid side
11321133
// effects.
11331134
int Value;

llvm/lib/Target/X86/X86InstrInfo.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -437,17 +437,6 @@ class X86InstrInfo final : public X86GenInstrInfo {
437437
/// instruction that defines the specified register class.
438438
bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const override;
439439

440-
/// isSafeToClobberEFLAGS - Return true if it's safe insert an instruction tha
441-
/// would clobber the EFLAGS condition register. Note the result may be
442-
/// conservative. If it cannot definitely determine the safety after visiting
443-
/// a few instructions in each direction it assumes it's not safe.
444-
bool isSafeToClobberEFLAGS(MachineBasicBlock &MBB,
445-
MachineBasicBlock::iterator I,
446-
unsigned Neighborhood = 4) const {
447-
return MBB.computeRegisterLiveness(&RI, X86::EFLAGS, I, Neighborhood) ==
448-
MachineBasicBlock::LQR_Dead;
449-
}
450-
451440
/// True if MI has a condition code def, e.g. EFLAGS, that is
452441
/// not marked dead.
453442
bool hasLiveCondCodeDef(MachineInstr &MI) const;

0 commit comments

Comments
 (0)