8 changes: 4 additions & 4 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ bool AArch64InstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
if (I == MBB.end())
return false;

if (!isUnpredicatedTerminator(I))
if (!isUnpredicatedTerminator(*I))
return false;

// Get the last instruction in the block.
MachineInstr *LastInst = I;

// If there is only one terminator instruction, process it.
unsigned LastOpc = LastInst->getOpcode();
if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
if (I == MBB.begin() || !isUnpredicatedTerminator(*--I)) {
if (isUncondBranchOpcode(LastOpc)) {
TBB = LastInst->getOperand(0).getMBB();
return false;
Expand All @@ -131,7 +131,7 @@ bool AArch64InstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
LastInst->eraseFromParent();
LastInst = SecondLastInst;
LastOpc = LastInst->getOpcode();
if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
if (I == MBB.begin() || !isUnpredicatedTerminator(*--I)) {
// Return now the only terminator is an unconditional branch.
TBB = LastInst->getOperand(0).getMBB();
return false;
Expand All @@ -143,7 +143,7 @@ bool AArch64InstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
}

// If there are three terminators, we don't know what sort of block this is.
if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(--I))
if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(*--I))
return true;

// If the block ends with a B and a Bcc, handle it.
Expand Down
57 changes: 26 additions & 31 deletions llvm/lib/Target/AMDGPU/R600InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,13 +876,12 @@ R600InstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
return 2;
}

bool
R600InstrInfo::isPredicated(const MachineInstr *MI) const {
int idx = MI->findFirstPredOperandIdx();
bool R600InstrInfo::isPredicated(const MachineInstr &MI) const {
int idx = MI.findFirstPredOperandIdx();
if (idx < 0)
return false;

unsigned Reg = MI->getOperand(idx).getReg();
unsigned Reg = MI.getOperand(idx).getReg();
switch (Reg) {
default: return false;
case AMDGPU::PRED_SEL_ONE:
Expand All @@ -892,25 +891,24 @@ R600InstrInfo::isPredicated(const MachineInstr *MI) const {
}
}

bool
R600InstrInfo::isPredicable(MachineInstr *MI) const {
bool R600InstrInfo::isPredicable(MachineInstr &MI) const {
// XXX: KILL* instructions can be predicated, but they must be the last
// instruction in a clause, so this means any instructions after them cannot
// be predicated. Until we have proper support for instruction clauses in the
// backend, we will mark KILL* instructions as unpredicable.

if (MI->getOpcode() == AMDGPU::KILLGT) {
if (MI.getOpcode() == AMDGPU::KILLGT) {
return false;
} else if (MI->getOpcode() == AMDGPU::CF_ALU) {
} else if (MI.getOpcode() == AMDGPU::CF_ALU) {
// If the clause start in the middle of MBB then the MBB has more
// than a single clause, unable to predicate several clauses.
if (MI->getParent()->begin() != MachineBasicBlock::iterator(MI))
if (MI.getParent()->begin() != MachineBasicBlock::iterator(MI))
return false;
// TODO: We don't support KC merging atm
if (MI->getOperand(3).getImm() != 0 || MI->getOperand(4).getImm() != 0)
if (MI.getOperand(3).getImm() != 0 || MI.getOperand(4).getImm() != 0)
return false;
return true;
} else if (isVector(*MI)) {
} else if (isVector(MI)) {
return false;
} else {
return AMDGPUInstrInfo::isPredicable(MI);
Expand Down Expand Up @@ -986,10 +984,9 @@ R600InstrInfo::ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) con
return false;
}

bool
R600InstrInfo::DefinesPredicate(MachineInstr *MI,
std::vector<MachineOperand> &Pred) const {
return isPredicateSetter(MI->getOpcode());
bool R600InstrInfo::DefinesPredicate(MachineInstr &MI,
std::vector<MachineOperand> &Pred) const {
return isPredicateSetter(MI.getOpcode());
}


Expand All @@ -999,43 +996,41 @@ R600InstrInfo::SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
return false;
}

bool R600InstrInfo::PredicateInstruction(MachineInstr &MI,
ArrayRef<MachineOperand> Pred) const {
int PIdx = MI.findFirstPredOperandIdx();

bool
R600InstrInfo::PredicateInstruction(MachineInstr *MI,
ArrayRef<MachineOperand> Pred) const {
int PIdx = MI->findFirstPredOperandIdx();

if (MI->getOpcode() == AMDGPU::CF_ALU) {
MI->getOperand(8).setImm(0);
if (MI.getOpcode() == AMDGPU::CF_ALU) {
MI.getOperand(8).setImm(0);
return true;
}

if (MI->getOpcode() == AMDGPU::DOT_4) {
MI->getOperand(getOperandIdx(*MI, AMDGPU::OpName::pred_sel_X))
if (MI.getOpcode() == AMDGPU::DOT_4) {
MI.getOperand(getOperandIdx(MI, AMDGPU::OpName::pred_sel_X))
.setReg(Pred[2].getReg());
MI->getOperand(getOperandIdx(*MI, AMDGPU::OpName::pred_sel_Y))
MI.getOperand(getOperandIdx(MI, AMDGPU::OpName::pred_sel_Y))
.setReg(Pred[2].getReg());
MI->getOperand(getOperandIdx(*MI, AMDGPU::OpName::pred_sel_Z))
MI.getOperand(getOperandIdx(MI, AMDGPU::OpName::pred_sel_Z))
.setReg(Pred[2].getReg());
MI->getOperand(getOperandIdx(*MI, AMDGPU::OpName::pred_sel_W))
MI.getOperand(getOperandIdx(MI, AMDGPU::OpName::pred_sel_W))
.setReg(Pred[2].getReg());
MachineInstrBuilder MIB(*MI->getParent()->getParent(), MI);
MachineInstrBuilder MIB(*MI.getParent()->getParent(), MI);
MIB.addReg(AMDGPU::PREDICATE_BIT, RegState::Implicit);
return true;
}

if (PIdx != -1) {
MachineOperand &PMO = MI->getOperand(PIdx);
MachineOperand &PMO = MI.getOperand(PIdx);
PMO.setReg(Pred[2].getReg());
MachineInstrBuilder MIB(*MI->getParent()->getParent(), MI);
MachineInstrBuilder MIB(*MI.getParent()->getParent(), MI);
MIB.addReg(AMDGPU::PREDICATE_BIT, RegState::Implicit);
return true;
}

return false;
}

unsigned int R600InstrInfo::getPredicationCost(const MachineInstr *) const {
unsigned int R600InstrInfo::getPredicationCost(const MachineInstr &) const {
return 2;
}

Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Target/AMDGPU/R600InstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ namespace llvm {

unsigned RemoveBranch(MachineBasicBlock &MBB) const override;

bool isPredicated(const MachineInstr *MI) const override;
bool isPredicated(const MachineInstr &MI) const override;

bool isPredicable(MachineInstr *MI) const override;
bool isPredicable(MachineInstr &MI) const override;

bool
isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCyles,
Expand All @@ -187,19 +187,19 @@ namespace llvm {
unsigned NumFCycles, unsigned ExtraFCycles,
BranchProbability Probability) const override;

bool DefinesPredicate(MachineInstr *MI,
std::vector<MachineOperand> &Pred) const override;
bool DefinesPredicate(MachineInstr &MI,
std::vector<MachineOperand> &Pred) const override;

bool SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
ArrayRef<MachineOperand> Pred2) const override;

bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
MachineBasicBlock &FMBB) const override;

bool PredicateInstruction(MachineInstr *MI,
bool PredicateInstruction(MachineInstr &MI,
ArrayRef<MachineOperand> Pred) const override;

unsigned int getPredicationCost(const MachineInstr *) const override;
unsigned int getPredicationCost(const MachineInstr &) const override;

unsigned int getInstrLatency(const InstrItineraryData *ItinData,
const MachineInstr *MI,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/R600Packetizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class R600PacketizerList : public VLIWPacketizerList {
if (LastDstChan >= BISlot)
isTrans = true;
LastDstChan = BISlot;
if (TII->isPredicated(&*BI))
if (TII->isPredicated(*BI))
continue;
int OperandIdx = TII->getOperandIdx(BI->getOpcode(), AMDGPU::OpName::write);
if (OperandIdx > -1 && BI->getOperand(OperandIdx).getImm() == 0)
Expand Down
96 changes: 48 additions & 48 deletions llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ ARMBaseInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,

// Walk backwards from the end of the basic block until the branch is
// analyzed or we give up.
while (isPredicated(I) || I->isTerminator() || I->isDebugValue()) {
while (isPredicated(*I) || I->isTerminator() || I->isDebugValue()) {

// Flag to be raised on unanalyzeable instructions. This is useful in cases
// where we want to clean up on the end of the basic block before we bail
Expand Down Expand Up @@ -322,15 +322,15 @@ ARMBaseInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
Cond.push_back(I->getOperand(2));
} else if (I->isReturn()) {
// Returns can't be analyzed, but we should run cleanup.
CantAnalyze = !isPredicated(I);
CantAnalyze = !isPredicated(*I);
} else {
// We encountered other unrecognized terminator. Bail out immediately.
return true;
}

// Cleanup code - to be run for unpredicated unconditional branches and
// returns.
if (!isPredicated(I) &&
if (!isPredicated(*I) &&
(isUncondBranchOpcode(I->getOpcode()) ||
isIndirectBranchOpcode(I->getOpcode()) ||
isJumpTableBranchOpcode(I->getOpcode()) ||
Expand Down Expand Up @@ -438,10 +438,10 @@ ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
return false;
}

bool ARMBaseInstrInfo::isPredicated(const MachineInstr *MI) const {
if (MI->isBundle()) {
MachineBasicBlock::const_instr_iterator I = MI->getIterator();
MachineBasicBlock::const_instr_iterator E = MI->getParent()->instr_end();
bool ARMBaseInstrInfo::isPredicated(const MachineInstr &MI) const {
if (MI.isBundle()) {
MachineBasicBlock::const_instr_iterator I = MI.getIterator();
MachineBasicBlock::const_instr_iterator E = MI.getParent()->instr_end();
while (++I != E && I->isInsideBundle()) {
int PIdx = I->findFirstPredOperandIdx();
if (PIdx != -1 && I->getOperand(PIdx).getImm() != ARMCC::AL)
Expand All @@ -450,26 +450,26 @@ bool ARMBaseInstrInfo::isPredicated(const MachineInstr *MI) const {
return false;
}

int PIdx = MI->findFirstPredOperandIdx();
return PIdx != -1 && MI->getOperand(PIdx).getImm() != ARMCC::AL;
int PIdx = MI.findFirstPredOperandIdx();
return PIdx != -1 && MI.getOperand(PIdx).getImm() != ARMCC::AL;
}

bool ARMBaseInstrInfo::
PredicateInstruction(MachineInstr *MI, ArrayRef<MachineOperand> Pred) const {
unsigned Opc = MI->getOpcode();
bool ARMBaseInstrInfo::PredicateInstruction(
MachineInstr &MI, ArrayRef<MachineOperand> Pred) const {
unsigned Opc = MI.getOpcode();
if (isUncondBranchOpcode(Opc)) {
MI->setDesc(get(getMatchingCondBranchOpcode(Opc)));
MachineInstrBuilder(*MI->getParent()->getParent(), MI)
MI.setDesc(get(getMatchingCondBranchOpcode(Opc)));
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
.addImm(Pred[0].getImm())
.addReg(Pred[1].getReg());
return true;
}

int PIdx = MI->findFirstPredOperandIdx();
int PIdx = MI.findFirstPredOperandIdx();
if (PIdx != -1) {
MachineOperand &PMO = MI->getOperand(PIdx);
MachineOperand &PMO = MI.getOperand(PIdx);
PMO.setImm(Pred[0].getImm());
MI->getOperand(PIdx+1).setReg(Pred[1].getReg());
MI.getOperand(PIdx+1).setReg(Pred[1].getReg());
return true;
}
return false;
Expand Down Expand Up @@ -501,11 +501,11 @@ bool ARMBaseInstrInfo::SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
}
}

bool ARMBaseInstrInfo::DefinesPredicate(MachineInstr *MI,
std::vector<MachineOperand> &Pred) const {
bool ARMBaseInstrInfo::DefinesPredicate(
MachineInstr &MI, std::vector<MachineOperand> &Pred) const {
bool Found = false;
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
const MachineOperand &MO = MI->getOperand(i);
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
const MachineOperand &MO = MI.getOperand(i);
if ((MO.isRegMask() && MO.clobbersPhysReg(ARM::CPSR)) ||
(MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR)) {
Pred.push_back(MO);
Expand Down Expand Up @@ -555,21 +555,21 @@ static bool isEligibleForITBlock(const MachineInstr *MI) {
/// isPredicable - Return true if the specified instruction can be predicated.
/// By default, this returns true for every instruction with a
/// PredicateOperand.
bool ARMBaseInstrInfo::isPredicable(MachineInstr *MI) const {
if (!MI->isPredicable())
bool ARMBaseInstrInfo::isPredicable(MachineInstr &MI) const {
if (!MI.isPredicable())
return false;

if (!isEligibleForITBlock(MI))
if (!isEligibleForITBlock(&MI))
return false;

ARMFunctionInfo *AFI =
MI->getParent()->getParent()->getInfo<ARMFunctionInfo>();
MI.getParent()->getParent()->getInfo<ARMFunctionInfo>();

if (AFI->isThumb2Function()) {
if (getSubtarget().restrictIT())
return isV8EligibleForIT(MI);
return isV8EligibleForIT(&MI);
} else { // non-Thumb
if ((MI->getDesc().TSFlags & ARMII::DomainMask) == ARMII::DomainNEON)
if ((MI.getDesc().TSFlags & ARMII::DomainMask) == ARMII::DomainNEON)
return false;
}

Expand Down Expand Up @@ -1718,7 +1718,7 @@ isProfitableToIfCvt(MachineBasicBlock &MBB,
CmpMI->getOpcode() == ARM::t2CMPri) {
unsigned Reg = CmpMI->getOperand(0).getReg();
unsigned PredReg = 0;
ARMCC::CondCodes P = getInstrPredicate(CmpMI, PredReg);
ARMCC::CondCodes P = getInstrPredicate(*CmpMI, PredReg);
if (P == ARMCC::AL && CmpMI->getOperand(1).getImm() == 0 &&
isARMLowRegister(Reg))
return false;
Expand Down Expand Up @@ -1773,16 +1773,16 @@ ARMBaseInstrInfo::isProfitableToUnpredicate(MachineBasicBlock &TMBB,
/// getInstrPredicate - If instruction is predicated, returns its predicate
/// condition, otherwise returns AL. It also returns the condition code
/// register by reference.
ARMCC::CondCodes
llvm::getInstrPredicate(const MachineInstr *MI, unsigned &PredReg) {
int PIdx = MI->findFirstPredOperandIdx();
ARMCC::CondCodes llvm::getInstrPredicate(const MachineInstr &MI,
unsigned &PredReg) {
int PIdx = MI.findFirstPredOperandIdx();
if (PIdx == -1) {
PredReg = 0;
return ARMCC::AL;
}

PredReg = MI->getOperand(PIdx+1).getReg();
return (ARMCC::CondCodes)MI->getOperand(PIdx).getImm();
PredReg = MI.getOperand(PIdx+1).getReg();
return (ARMCC::CondCodes)MI.getOperand(PIdx).getImm();
}


Expand All @@ -1806,7 +1806,7 @@ MachineInstr *ARMBaseInstrInfo::commuteInstructionImpl(MachineInstr *MI,
case ARM::t2MOVCCr: {
// MOVCC can be commuted by inverting the condition.
unsigned PredReg = 0;
ARMCC::CondCodes CC = getInstrPredicate(MI, PredReg);
ARMCC::CondCodes CC = getInstrPredicate(*MI, PredReg);
// MOVCC AL can't be inverted. Shouldn't happen.
if (CC == ARMCC::AL || PredReg != ARM::CPSR)
return nullptr;
Expand Down Expand Up @@ -2395,15 +2395,15 @@ optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, unsigned SrcReg2,

// Masked compares sometimes use the same register as the corresponding 'and'.
if (CmpMask != ~0) {
if (!isSuitableForMask(MI, SrcReg, CmpMask, false) || isPredicated(MI)) {
if (!isSuitableForMask(MI, SrcReg, CmpMask, false) || isPredicated(*MI)) {
MI = nullptr;
for (MachineRegisterInfo::use_instr_iterator
UI = MRI->use_instr_begin(SrcReg), UE = MRI->use_instr_end();
UI != UE; ++UI) {
if (UI->getParent() != CmpInstr->getParent()) continue;
MachineInstr *PotentialAND = &*UI;
if (!isSuitableForMask(PotentialAND, SrcReg, CmpMask, true) ||
isPredicated(PotentialAND))
isPredicated(*PotentialAND))
continue;
MI = PotentialAND;
break;
Expand Down Expand Up @@ -2471,7 +2471,7 @@ optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, unsigned SrcReg2,
if (!MI) MI = Sub;

// We can't use a predicated instruction - it doesn't always write the flags.
if (isPredicated(MI))
if (isPredicated(*MI))
return false;

switch (MI->getOpcode()) {
Expand Down Expand Up @@ -2618,7 +2618,7 @@ optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, unsigned SrcReg2,
// Toggle the optional operand to CPSR.
MI->getOperand(5).setReg(ARM::CPSR);
MI->getOperand(5).setIsDef(true);
assert(!isPredicated(MI) && "Can't use flags from predicated instruction");
assert(!isPredicated(*MI) && "Can't use flags from predicated instruction");
CmpInstr->eraseFromParent();

// Modify the condition code of operands in OperandsToUpdate.
Expand Down Expand Up @@ -3946,15 +3946,15 @@ ARMBaseInstrInfo::getOperandLatency(const InstrItineraryData *ItinData,
return Latency;
}

unsigned ARMBaseInstrInfo::getPredicationCost(const MachineInstr *MI) const {
if (MI->isCopyLike() || MI->isInsertSubreg() ||
MI->isRegSequence() || MI->isImplicitDef())
unsigned ARMBaseInstrInfo::getPredicationCost(const MachineInstr &MI) const {
if (MI.isCopyLike() || MI.isInsertSubreg() || MI.isRegSequence() ||
MI.isImplicitDef())
return 0;

if (MI->isBundle())
if (MI.isBundle())
return 0;

const MCInstrDesc &MCID = MI->getDesc();
const MCInstrDesc &MCID = MI.getDesc();

if (MCID.isCall() || MCID.hasImplicitDefOfPhysReg(ARM::CPSR)) {
// When predicated, CPSR is an additional source operand for CPSR updating
Expand Down Expand Up @@ -4152,12 +4152,12 @@ ARMBaseInstrInfo::getExecutionDomain(const MachineInstr *MI) const {
if (Subtarget.hasNEON()) {
// VMOVD, VMOVRS and VMOVSR are VFP instructions, but can be changed to NEON
// if they are not predicated.
if (MI->getOpcode() == ARM::VMOVD && !isPredicated(MI))
if (MI->getOpcode() == ARM::VMOVD && !isPredicated(*MI))
return std::make_pair(ExeVFP, (1 << ExeVFP) | (1 << ExeNEON));

// CortexA9 is particularly picky about mixing the two and wants these
// converted.
if (Subtarget.isCortexA9() && !isPredicated(MI) &&
if (Subtarget.isCortexA9() && !isPredicated(*MI) &&
(MI->getOpcode() == ARM::VMOVRS || MI->getOpcode() == ARM::VMOVSR ||
MI->getOpcode() == ARM::VMOVS))
return std::make_pair(ExeVFP, (1 << ExeVFP) | (1 << ExeNEON));
Expand Down Expand Up @@ -4252,7 +4252,7 @@ ARMBaseInstrInfo::setExecutionDomain(MachineInstr *MI, unsigned Domain) const {
break;

// Zap the predicate operands.
assert(!isPredicated(MI) && "Cannot predicate a VORRd");
assert(!isPredicated(*MI) && "Cannot predicate a VORRd");

// Make sure we've got NEON instructions.
assert(Subtarget.hasNEON() && "VORRd requires NEON");
Expand All @@ -4273,7 +4273,7 @@ ARMBaseInstrInfo::setExecutionDomain(MachineInstr *MI, unsigned Domain) const {
case ARM::VMOVRS:
if (Domain != ExeNEON)
break;
assert(!isPredicated(MI) && "Cannot predicate a VGETLN");
assert(!isPredicated(*MI) && "Cannot predicate a VGETLN");

// Source instruction is %RDst = VMOVRS %SSrc, 14, %noreg (; implicits)
DstReg = MI->getOperand(0).getReg();
Expand All @@ -4299,7 +4299,7 @@ ARMBaseInstrInfo::setExecutionDomain(MachineInstr *MI, unsigned Domain) const {
case ARM::VMOVSR: {
if (Domain != ExeNEON)
break;
assert(!isPredicated(MI) && "Cannot predicate a VSETLN");
assert(!isPredicated(*MI) && "Cannot predicate a VSETLN");

// Source instruction is %SDst = VMOVSR %RSrc, 14, %noreg (; implicits)
DstReg = MI->getOperand(0).getReg();
Expand Down
20 changes: 10 additions & 10 deletions llvm/lib/Target/ARM/ARMBaseInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,24 @@ class ARMBaseInstrInfo : public ARMGenInstrInfo {
ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;

// Predication support.
bool isPredicated(const MachineInstr *MI) const override;
bool isPredicated(const MachineInstr &MI) const override;

ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
int PIdx = MI->findFirstPredOperandIdx();
return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm()
ARMCC::CondCodes getPredicate(const MachineInstr &MI) const {
int PIdx = MI.findFirstPredOperandIdx();
return PIdx != -1 ? (ARMCC::CondCodes)MI.getOperand(PIdx).getImm()
: ARMCC::AL;
}

bool PredicateInstruction(MachineInstr *MI,
ArrayRef<MachineOperand> Pred) const override;
bool PredicateInstruction(MachineInstr &MI,
ArrayRef<MachineOperand> Pred) const override;

bool SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
ArrayRef<MachineOperand> Pred2) const override;

bool DefinesPredicate(MachineInstr *MI,
bool DefinesPredicate(MachineInstr &MI,
std::vector<MachineOperand> &Pred) const override;

bool isPredicable(MachineInstr *MI) const override;
bool isPredicable(MachineInstr &MI) const override;

/// GetInstSize - Returns the size of the specified MachineInstr.
///
Expand Down Expand Up @@ -327,7 +327,7 @@ class ARMBaseInstrInfo : public ARMGenInstrInfo {
const MCInstrDesc &UseMCID,
unsigned UseIdx, unsigned UseAlign) const;

unsigned getPredicationCost(const MachineInstr *MI) const override;
unsigned getPredicationCost(const MachineInstr &MI) const override;

unsigned getInstrLatency(const InstrItineraryData *ItinData,
const MachineInstr *MI,
Expand Down Expand Up @@ -447,7 +447,7 @@ static inline bool isPushOpcode(int Opc) {
/// getInstrPredicate - If instruction is predicated, returns its predicate
/// condition, otherwise returns AL. It also returns the condition code
/// register by reference.
ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg);
ARMCC::CondCodes getInstrPredicate(const MachineInstr &MI, unsigned &PredReg);

unsigned getMatchingCondBranchOpcode(unsigned Opc);

Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1463,14 +1463,14 @@ void ARMConstantIslands::createNewWater(unsigned CPUserIndex,
// Avoid splitting an IT block.
if (LastIT) {
unsigned PredReg = 0;
ARMCC::CondCodes CC = getITInstrPredicate(MI, PredReg);
ARMCC::CondCodes CC = getITInstrPredicate(*MI, PredReg);
if (CC != ARMCC::AL)
MI = LastIT;
}

// We really must not split an IT block.
DEBUG(unsigned PredReg;
assert(!isThumb || getITInstrPredicate(MI, PredReg) == ARMCC::AL));
assert(!isThumb || getITInstrPredicate(*MI, PredReg) == ARMCC::AL));

NewMBB = splitBlockBeforeInstr(MI);
}
Expand Down Expand Up @@ -1916,7 +1916,7 @@ bool ARMConstantIslands::optimizeThumb2Branches() {

NewOpc = 0;
unsigned PredReg = 0;
ARMCC::CondCodes Pred = getInstrPredicate(Br.MI, PredReg);
ARMCC::CondCodes Pred = getInstrPredicate(*Br.MI, PredReg);
if (Pred == ARMCC::EQ)
NewOpc = ARM::tCBZ;
else if (Pred == ARMCC::NE)
Expand All @@ -1934,7 +1934,7 @@ bool ARMConstantIslands::optimizeThumb2Branches() {
--CmpMI;
if (CmpMI->getOpcode() == ARM::tCMPi8) {
unsigned Reg = CmpMI->getOperand(0).getReg();
Pred = getInstrPredicate(CmpMI, PredReg);
Pred = getInstrPredicate(*CmpMI, PredReg);
if (Pred == ARMCC::AL &&
CmpMI->getOperand(1).getImm() == 0 &&
isARMLowRegister(Reg)) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ void ARMExpandPseudo::ExpandMOV32BitImm(MachineBasicBlock &MBB,
MachineInstr &MI = *MBBI;
unsigned Opcode = MI.getOpcode();
unsigned PredReg = 0;
ARMCC::CondCodes Pred = getInstrPredicate(&MI, PredReg);
ARMCC::CondCodes Pred = getInstrPredicate(MI, PredReg);
unsigned DstReg = MI.getOperand(0).getReg();
bool DstIsDead = MI.getOperand(0).isDead();
bool isCC = Opcode == ARM::MOVCCi32imm || Opcode == ARM::t2MOVCCi32imm;
Expand Down
18 changes: 9 additions & 9 deletions llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ MachineInstr *ARMLoadStoreOpt::MergeOpsUpdate(const MergeCandidate &Cand) {
unsigned Base = getLoadStoreBaseOp(*First).getReg();
bool BaseKill = LatestMI->killsRegister(Base);
unsigned PredReg = 0;
ARMCC::CondCodes Pred = getInstrPredicate(First, PredReg);
ARMCC::CondCodes Pred = getInstrPredicate(*First, PredReg);
DebugLoc DL = First->getDebugLoc();
MachineInstr *Merged = nullptr;
if (Cand.CanMergeToLSDouble)
Expand Down Expand Up @@ -1102,7 +1102,7 @@ static int isIncrementOrDecrement(const MachineInstr &MI, unsigned Reg,
unsigned MIPredReg;
if (MI.getOperand(0).getReg() != Reg ||
MI.getOperand(1).getReg() != Reg ||
getInstrPredicate(&MI, MIPredReg) != Pred ||
getInstrPredicate(MI, MIPredReg) != Pred ||
MIPredReg != PredReg)
return 0;

Expand Down Expand Up @@ -1169,7 +1169,7 @@ bool ARMLoadStoreOpt::MergeBaseUpdateLSMultiple(MachineInstr *MI) {
unsigned Base = BaseOP.getReg();
bool BaseKill = BaseOP.isKill();
unsigned PredReg = 0;
ARMCC::CondCodes Pred = getInstrPredicate(MI, PredReg);
ARMCC::CondCodes Pred = getInstrPredicate(*MI, PredReg);
unsigned Opcode = MI->getOpcode();
DebugLoc DL = MI->getDebugLoc();

Expand Down Expand Up @@ -1291,7 +1291,7 @@ bool ARMLoadStoreOpt::MergeBaseUpdateLoadStore(MachineInstr *MI) {
return false;

unsigned PredReg = 0;
ARMCC::CondCodes Pred = getInstrPredicate(MI, PredReg);
ARMCC::CondCodes Pred = getInstrPredicate(*MI, PredReg);
int Bytes = getLSMultipleTransferSize(MI);
MachineBasicBlock &MBB = *MI->getParent();
MachineBasicBlock::iterator MBBI(MI);
Expand Down Expand Up @@ -1388,7 +1388,7 @@ bool ARMLoadStoreOpt::MergeBaseUpdateLSDouble(MachineInstr &MI) const {
return false;

unsigned PredReg;
ARMCC::CondCodes Pred = getInstrPredicate(&MI, PredReg);
ARMCC::CondCodes Pred = getInstrPredicate(MI, PredReg);
MachineBasicBlock::iterator MBBI(MI);
MachineBasicBlock &MBB = *MI.getParent();
int Offset;
Expand Down Expand Up @@ -1549,7 +1549,7 @@ bool ARMLoadStoreOpt::FixInvalidRegPairOp(MachineBasicBlock &MBB,
bool OffUndef = isT2 ? false : MI->getOperand(3).isUndef();
int OffImm = getMemoryOpOffset(MI);
unsigned PredReg = 0;
ARMCC::CondCodes Pred = getInstrPredicate(MI, PredReg);
ARMCC::CondCodes Pred = getInstrPredicate(*MI, PredReg);

if (OddRegNum > EvenRegNum && OffImm == 0) {
// Ascending register numbers and no offset. It's safe to change it to a
Expand Down Expand Up @@ -1655,7 +1655,7 @@ bool ARMLoadStoreOpt::LoadStoreMultipleOpti(MachineBasicBlock &MBB) {
unsigned Reg = MO.getReg();
unsigned Base = getLoadStoreBaseOp(*MBBI).getReg();
unsigned PredReg = 0;
ARMCC::CondCodes Pred = getInstrPredicate(MBBI, PredReg);
ARMCC::CondCodes Pred = getInstrPredicate(*MBBI, PredReg);
int Offset = getMemoryOpOffset(MBBI);
if (CurrBase == 0) {
// Start of a new chain.
Expand Down Expand Up @@ -2056,7 +2056,7 @@ ARMPreAllocLoadStoreOpt::CanFormLdStDWord(MachineInstr *Op0, MachineInstr *Op1,
if (FirstReg == SecondReg)
return false;
BaseReg = Op0->getOperand(1).getReg();
Pred = getInstrPredicate(Op0, PredReg);
Pred = getInstrPredicate(*Op0, PredReg);
dl = Op0->getDebugLoc();
return true;
}
Expand Down Expand Up @@ -2250,7 +2250,7 @@ ARMPreAllocLoadStoreOpt::RescheduleLoadStoreInstrs(MachineBasicBlock *MBB) {
if (!isMemoryOp(*MI))
continue;
unsigned PredReg = 0;
if (getInstrPredicate(MI, PredReg) != ARMCC::AL)
if (getInstrPredicate(*MI, PredReg) != ARMCC::AL)
continue;

int Opc = MI->getOpcode();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/ARMSchedule.td
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def : PredicateProlog<[{
(void)TII;
}]>;

def IsPredicatedPred : SchedPredicate<[{TII->isPredicated(MI)}]>;
def IsPredicatedPred : SchedPredicate<[{TII->isPredicated(*MI)}]>;

//===----------------------------------------------------------------------===//
// Instruction Itinerary classes used for ARM
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/ARM/Thumb2ITBlockPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Thumb2ITBlockPass::MoveCopyOutOfITBlock(MachineInstr *MI,
++I;
if (I != E) {
unsigned NPredReg = 0;
ARMCC::CondCodes NCC = getITInstrPredicate(I, NPredReg);
ARMCC::CondCodes NCC = getITInstrPredicate(*I, NPredReg);
if (NCC == CC || NCC == OCC)
return true;
}
Expand All @@ -182,7 +182,7 @@ bool Thumb2ITBlockPass::InsertITInstructions(MachineBasicBlock &MBB) {
MachineInstr *MI = &*MBBI;
DebugLoc dl = MI->getDebugLoc();
unsigned PredReg = 0;
ARMCC::CondCodes CC = getITInstrPredicate(MI, PredReg);
ARMCC::CondCodes CC = getITInstrPredicate(*MI, PredReg);
if (CC == ARMCC::AL) {
++MBBI;
continue;
Expand Down Expand Up @@ -222,7 +222,7 @@ bool Thumb2ITBlockPass::InsertITInstructions(MachineBasicBlock &MBB) {
MI = NMI;

unsigned NPredReg = 0;
ARMCC::CondCodes NCC = getITInstrPredicate(NMI, NPredReg);
ARMCC::CondCodes NCC = getITInstrPredicate(*NMI, NPredReg);
if (NCC == CC || NCC == OCC) {
Mask |= (NCC & 1) << Pos;
// Add implicit use of ITSTATE.
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Target/ARM/Thumb2InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Thumb2InstrInfo::ReplaceTailWithBranchTo(MachineBasicBlock::iterator Tail,
// If the first instruction of Tail is predicated, we may have to update
// the IT instruction.
unsigned PredReg = 0;
ARMCC::CondCodes CC = getInstrPredicate(Tail, PredReg);
ARMCC::CondCodes CC = getInstrPredicate(*Tail, PredReg);
MachineBasicBlock::iterator MBBI = Tail;
if (CC != ARMCC::AL)
// Expecting at least the t2IT instruction before it.
Expand Down Expand Up @@ -106,7 +106,7 @@ Thumb2InstrInfo::isLegalToSplitMBBAt(MachineBasicBlock &MBB,
}

unsigned PredReg = 0;
return getITInstrPredicate(MBBI, PredReg) == ARMCC::AL;
return getITInstrPredicate(*MBBI, PredReg) == ARMCC::AL;
}

void Thumb2InstrInfo::copyPhysReg(MachineBasicBlock &MBB,
Expand Down Expand Up @@ -459,7 +459,7 @@ bool llvm::rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
Offset += MI.getOperand(FrameRegIdx+1).getImm();

unsigned PredReg;
if (Offset == 0 && getInstrPredicate(&MI, PredReg) == ARMCC::AL) {
if (Offset == 0 && getInstrPredicate(MI, PredReg) == ARMCC::AL) {
// Turn it into a move.
MI.setDesc(TII.get(ARM::tMOVr));
MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false);
Expand Down Expand Up @@ -627,9 +627,9 @@ bool llvm::rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
return Offset == 0;
}

ARMCC::CondCodes
llvm::getITInstrPredicate(const MachineInstr *MI, unsigned &PredReg) {
unsigned Opc = MI->getOpcode();
ARMCC::CondCodes llvm::getITInstrPredicate(const MachineInstr &MI,
unsigned &PredReg) {
unsigned Opc = MI.getOpcode();
if (Opc == ARM::tBcc || Opc == ARM::t2Bcc)
return ARMCC::AL;
return getInstrPredicate(MI, PredReg);
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Target/ARM/Thumb2InstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ class Thumb2InstrInfo : public ARMBaseInstrInfo {
/// getITInstrPredicate - Valid only in Thumb2 mode. This function is identical
/// to llvm::getInstrPredicate except it returns AL for conditional branch
/// instructions which are "predicated", but are not in IT blocks.
ARMCC::CondCodes getITInstrPredicate(const MachineInstr *MI, unsigned &PredReg);


ARMCC::CondCodes getITInstrPredicate(const MachineInstr &MI, unsigned &PredReg);
}

#endif
6 changes: 3 additions & 3 deletions llvm/lib/Target/ARM/Thumb2SizeReduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ Thumb2SizeReduce::ReduceSpecial(MachineBasicBlock &MBB, MachineInstr *MI,
case ARM::t2ADDSri:
case ARM::t2ADDSrr: {
unsigned PredReg = 0;
if (getInstrPredicate(MI, PredReg) == ARMCC::AL) {
if (getInstrPredicate(*MI, PredReg) == ARMCC::AL) {
switch (Opc) {
default: break;
case ARM::t2ADDSri: {
Expand Down Expand Up @@ -702,7 +702,7 @@ Thumb2SizeReduce::ReduceTo2Addr(MachineBasicBlock &MBB, MachineInstr *MI,
// Check if it's possible / necessary to transfer the predicate.
const MCInstrDesc &NewMCID = TII->get(Entry.NarrowOpc2);
unsigned PredReg = 0;
ARMCC::CondCodes Pred = getInstrPredicate(MI, PredReg);
ARMCC::CondCodes Pred = getInstrPredicate(*MI, PredReg);
bool SkipPred = false;
if (Pred != ARMCC::AL) {
if (!NewMCID.isPredicable())
Expand Down Expand Up @@ -798,7 +798,7 @@ Thumb2SizeReduce::ReduceToNarrow(MachineBasicBlock &MBB, MachineInstr *MI,
// Check if it's possible / necessary to transfer the predicate.
const MCInstrDesc &NewMCID = TII->get(Entry.NarrowOpc1);
unsigned PredReg = 0;
ARMCC::CondCodes Pred = getInstrPredicate(MI, PredReg);
ARMCC::CondCodes Pred = getInstrPredicate(*MI, PredReg);
bool SkipPred = false;
if (Pred != ARMCC::AL) {
if (!NewMCID.isPredicable())
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/BPF/BPFInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bool BPFInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,

// Working from the bottom, when we see a non-terminator
// instruction, we're done.
if (!isUnpredicatedTerminator(I))
if (!isUnpredicatedTerminator(*I))
break;

// A terminator that isn't a branch can't easily be handled
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Hexagon/HexagonBitTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ bool HexagonEvaluator::evaluate(const MachineInstr *BI,

bool HexagonEvaluator::evaluateLoad(const MachineInstr *MI,
const CellMapType &Inputs, CellMapType &Outputs) const {
if (TII.isPredicated(MI))
if (TII.isPredicated(*MI))
return false;
assert(MI->mayLoad() && "A load that mayn't?");
unsigned Opc = MI->getOpcode();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Hexagon/HexagonEarlyIfConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ unsigned HexagonEarlyIfConversion::computePhiCost(MachineBasicBlock *B) const {
}
MachineInstr *Def1 = MRI->getVRegDef(RO1.getReg());
MachineInstr *Def3 = MRI->getVRegDef(RO3.getReg());
if (!TII->isPredicable(Def1) || !TII->isPredicable(Def3))
if (!TII->isPredicable(*Def1) || !TII->isPredicable(*Def3))
Cost++;
}
return Cost;
Expand Down
26 changes: 12 additions & 14 deletions llvm/lib/Target/Hexagon/HexagonExpandCondsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ void HexagonExpandCondsets::addInstrToLiveness(MachineInstr *MI) {
DEBUG(dbgs() << "adding liveness info for instr\n " << MX << " " << *MI);

MX = MX.getRegSlot();
bool Predicated = HII->isPredicated(MI);
bool Predicated = HII->isPredicated(*MI);
MachineBasicBlock *MB = MI->getParent();

// Strip all implicit uses from predicated instructions. They will be
Expand Down Expand Up @@ -748,7 +748,7 @@ bool HexagonExpandCondsets::splitInBlock(MachineBasicBlock &B) {


bool HexagonExpandCondsets::isPredicable(MachineInstr *MI) {
if (HII->isPredicated(MI) || !HII->isPredicable(MI))
if (HII->isPredicated(*MI) || !HII->isPredicable(*MI))
return false;
if (MI->hasUnmodeledSideEffects() || MI->mayStore())
return false;
Expand Down Expand Up @@ -784,8 +784,8 @@ MachineInstr *HexagonExpandCondsets::getReachingDefForPred(RegisterRef RD,
MachineInstr *MI = &*I;
// Check if this instruction can be ignored, i.e. if it is predicated
// on the complementary condition.
if (PredValid && HII->isPredicated(MI)) {
if (MI->readsRegister(PredR) && (Cond != HII->isPredicatedTrue(MI)))
if (PredValid && HII->isPredicated(*MI)) {
if (MI->readsRegister(PredR) && (Cond != HII->isPredicatedTrue(*MI)))
continue;
}

Expand Down Expand Up @@ -945,9 +945,9 @@ void HexagonExpandCondsets::renameInRange(RegisterRef RO, RegisterRef RN,
MachineInstr *MI = &*I;
// Do not touch instructions that are not predicated, or are predicated
// on the opposite condition.
if (!HII->isPredicated(MI))
if (!HII->isPredicated(*MI))
continue;
if (!MI->readsRegister(PredR) || (Cond != HII->isPredicatedTrue(MI)))
if (!MI->readsRegister(PredR) || (Cond != HII->isPredicatedTrue(*MI)))
continue;

for (auto &Op : MI->operands()) {
Expand Down Expand Up @@ -1014,8 +1014,8 @@ bool HexagonExpandCondsets::predicate(MachineInstr *TfrI, bool Cond) {
// By default assume that the instruction executes on the same condition
// as TfrI (Exec_Then), and also on the opposite one (Exec_Else).
unsigned Exec = Exec_Then | Exec_Else;
if (PredValid && HII->isPredicated(MI) && MI->readsRegister(PredR))
Exec = (Cond == HII->isPredicatedTrue(MI)) ? Exec_Then : Exec_Else;
if (PredValid && HII->isPredicated(*MI) && MI->readsRegister(PredR))
Exec = (Cond == HII->isPredicatedTrue(*MI)) ? Exec_Then : Exec_Else;

for (auto &Op : MI->operands()) {
if (!Op.isReg())
Expand Down Expand Up @@ -1119,11 +1119,9 @@ void HexagonExpandCondsets::removeImplicitUses(MachineInstr *MI) {


void HexagonExpandCondsets::removeImplicitUses(MachineBasicBlock &B) {
for (MachineBasicBlock::iterator I = B.begin(), E = B.end(); I != E; ++I) {
MachineInstr *MI = &*I;
for (MachineInstr &MI : B)
if (HII->isPredicated(MI))
removeImplicitUses(MI);
}
removeImplicitUses(&MI);
}


Expand Down Expand Up @@ -1290,13 +1288,13 @@ bool HexagonExpandCondsets::coalesceSegments(MachineFunction &MF) {
if (S1.isReg()) {
RegisterRef RS = S1;
MachineInstr *RDef = getReachingDefForPred(RS, CI, RP.Reg, true);
if (!RDef || !HII->isPredicable(RDef))
if (!RDef || !HII->isPredicable(*RDef))
Done = coalesceRegisters(RD, RegisterRef(S1));
}
if (!Done && S2.isReg()) {
RegisterRef RS = S2;
MachineInstr *RDef = getReachingDefForPred(RS, CI, RP.Reg, false);
if (!RDef || !HII->isPredicable(RDef))
if (!RDef || !HII->isPredicable(*RDef))
Done = coalesceRegisters(RD, RegisterRef(S2));
}
Changed |= Done;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,8 +1772,8 @@ void HexagonFrameLowering::optimizeSpillSlots(MachineFunction &MF,

for (auto &In : B) {
int LFI, SFI;
bool Load = HII.isLoadFromStackSlot(&In, LFI) && !HII.isPredicated(&In);
bool Store = HII.isStoreToStackSlot(&In, SFI) && !HII.isPredicated(&In);
bool Load = HII.isLoadFromStackSlot(&In, LFI) && !HII.isPredicated(In);
bool Store = HII.isStoreToStackSlot(&In, SFI) && !HII.isPredicated(In);
if (Load && Store) {
// If it's both a load and a store, then we won't handle it.
BadFIs.insert(LFI);
Expand Down
117 changes: 57 additions & 60 deletions llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,15 @@ bool HexagonInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
return false;
--I;
}
if (!isUnpredicatedTerminator(&*I))
if (!isUnpredicatedTerminator(*I))
return false;

// Get the last instruction in the block.
MachineInstr *LastInst = &*I;
MachineInstr *SecondLastInst = nullptr;
// Find one more terminator if present.
for (;;) {
if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(&*I)) {
if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) {
if (!SecondLastInst)
SecondLastInst = &*I;
else
Expand Down Expand Up @@ -585,7 +585,7 @@ unsigned HexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB,
MachineBasicBlock *NewTBB, *NewFBB;
SmallVector<MachineOperand, 4> Cond;
MachineInstr *Term = MBB.getFirstTerminator();
if (Term != MBB.end() && isPredicated(Term) &&
if (Term != MBB.end() && isPredicated(*Term) &&
!AnalyzeBranch(MBB, NewTBB, NewFBB, Cond, false)) {
MachineBasicBlock *NextBB = &*++MBB.getIterator();
if (NewTBB == NextBB) {
Expand Down Expand Up @@ -1211,20 +1211,19 @@ void HexagonInstrInfo::insertNoop(MachineBasicBlock &MBB,
// if (!p0.new) R1 = add(R2, R3)
// Note: New-value stores are not included here as in the current
// implementation, we don't need to check their predicate sense.
bool HexagonInstrInfo::isPredicated(const MachineInstr *MI) const {
const uint64_t F = MI->getDesc().TSFlags;
bool HexagonInstrInfo::isPredicated(const MachineInstr &MI) const {
const uint64_t F = MI.getDesc().TSFlags;
return (F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask;
}


bool HexagonInstrInfo::PredicateInstruction(MachineInstr *MI,
ArrayRef<MachineOperand> Cond) const {
bool HexagonInstrInfo::PredicateInstruction(
MachineInstr &MI, ArrayRef<MachineOperand> Cond) const {
if (Cond.empty() || isNewValueJump(Cond[0].getImm()) ||
isEndLoopN(Cond[0].getImm())) {
DEBUG(dbgs() << "\nCannot predicate:"; MI->dump(););
DEBUG(dbgs() << "\nCannot predicate:"; MI.dump(););
return false;
}
int Opc = MI->getOpcode();
int Opc = MI.getOpcode();
assert (isPredicable(MI) && "Expected predicable instruction");
bool invertJump = predOpcodeHasNot(Cond);

Expand All @@ -1233,13 +1232,13 @@ bool HexagonInstrInfo::PredicateInstruction(MachineInstr *MI,
// plicated manipulations with the operands (handling tied operands,
// etc.), build a new temporary instruction, then overwrite MI with it.

MachineBasicBlock &B = *MI->getParent();
DebugLoc DL = MI->getDebugLoc();
MachineBasicBlock &B = *MI.getParent();
DebugLoc DL = MI.getDebugLoc();
unsigned PredOpc = getCondOpcode(Opc, invertJump);
MachineInstrBuilder T = BuildMI(B, MI, DL, get(PredOpc));
unsigned NOp = 0, NumOps = MI->getNumOperands();
unsigned NOp = 0, NumOps = MI.getNumOperands();
while (NOp < NumOps) {
MachineOperand &Op = MI->getOperand(NOp);
MachineOperand &Op = MI.getOperand(NOp);
if (!Op.isReg() || !Op.isDef() || Op.isImplicit())
break;
T.addOperand(Op);
Expand All @@ -1252,13 +1251,13 @@ bool HexagonInstrInfo::PredicateInstruction(MachineInstr *MI,
assert(GotPredReg);
T.addReg(PredReg, PredRegFlags);
while (NOp < NumOps)
T.addOperand(MI->getOperand(NOp++));
T.addOperand(MI.getOperand(NOp++));

MI->setDesc(get(PredOpc));
while (unsigned n = MI->getNumOperands())
MI->RemoveOperand(n-1);
MI.setDesc(get(PredOpc));
while (unsigned n = MI.getNumOperands())
MI.RemoveOperand(n-1);
for (unsigned i = 0, n = T->getNumOperands(); i < n; ++i)
MI->addOperand(T->getOperand(i));
MI.addOperand(T->getOperand(i));

MachineBasicBlock::instr_iterator TI = T->getIterator();
B.erase(TI);
Expand All @@ -1275,12 +1274,11 @@ bool HexagonInstrInfo::SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
return false;
}


bool HexagonInstrInfo::DefinesPredicate(MachineInstr *MI,
std::vector<MachineOperand> &Pred) const {
bool HexagonInstrInfo::DefinesPredicate(
MachineInstr &MI, std::vector<MachineOperand> &Pred) const {
auto &HRI = getRegisterInfo();
for (unsigned oper = 0; oper < MI->getNumOperands(); ++oper) {
MachineOperand MO = MI->getOperand(oper);
for (unsigned oper = 0; oper < MI.getNumOperands(); ++oper) {
MachineOperand MO = MI.getOperand(oper);
if (MO.isReg() && MO.isDef()) {
const TargetRegisterClass* RC = HRI.getMinimalPhysRegClass(MO.getReg());
if (RC == &Hexagon::PredRegsRegClass) {
Expand All @@ -1292,14 +1290,14 @@ bool HexagonInstrInfo::DefinesPredicate(MachineInstr *MI,
return false;
}

bool HexagonInstrInfo::isPredicable(MachineInstr *MI) const {
bool isPred = MI->getDesc().isPredicable();
bool HexagonInstrInfo::isPredicable(MachineInstr &MI) const {
bool isPred = MI.getDesc().isPredicable();

if (!isPred)
return false;

const int Opc = MI->getOpcode();
int NumOperands = MI->getNumOperands();
const int Opc = MI.getOpcode();
int NumOperands = MI.getNumOperands();

// Keep a flag for upto 4 operands in the instructions, to indicate if
// that operand has been constant extended.
Expand All @@ -1308,64 +1306,64 @@ bool HexagonInstrInfo::isPredicable(MachineInstr *MI) const {
NumOperands = 4;

for (int i = 0; i < NumOperands; i++)
OpCExtended[i] = (isOperandExtended(MI, i) && isConstExtended(MI));
OpCExtended[i] = (isOperandExtended(&MI, i) && isConstExtended(&MI));

switch(Opc) {
case Hexagon::A2_tfrsi:
return (isOperandExtended(MI, 1) && isConstExtended(MI)) ||
isInt<12>(MI->getOperand(1).getImm());
return (isOperandExtended(&MI, 1) && isConstExtended(&MI)) ||
isInt<12>(MI.getOperand(1).getImm());

case Hexagon::S2_storerd_io:
return isShiftedUInt<6,3>(MI->getOperand(1).getImm());
return isShiftedUInt<6,3>(MI.getOperand(1).getImm());

case Hexagon::S2_storeri_io:
case Hexagon::S2_storerinew_io:
return isShiftedUInt<6,2>(MI->getOperand(1).getImm());
return isShiftedUInt<6,2>(MI.getOperand(1).getImm());

case Hexagon::S2_storerh_io:
case Hexagon::S2_storerhnew_io:
return isShiftedUInt<6,1>(MI->getOperand(1).getImm());
return isShiftedUInt<6,1>(MI.getOperand(1).getImm());

case Hexagon::S2_storerb_io:
case Hexagon::S2_storerbnew_io:
return isUInt<6>(MI->getOperand(1).getImm());
return isUInt<6>(MI.getOperand(1).getImm());

case Hexagon::L2_loadrd_io:
return isShiftedUInt<6,3>(MI->getOperand(2).getImm());
return isShiftedUInt<6,3>(MI.getOperand(2).getImm());

case Hexagon::L2_loadri_io:
return isShiftedUInt<6,2>(MI->getOperand(2).getImm());
return isShiftedUInt<6,2>(MI.getOperand(2).getImm());

case Hexagon::L2_loadrh_io:
case Hexagon::L2_loadruh_io:
return isShiftedUInt<6,1>(MI->getOperand(2).getImm());
return isShiftedUInt<6,1>(MI.getOperand(2).getImm());

case Hexagon::L2_loadrb_io:
case Hexagon::L2_loadrub_io:
return isUInt<6>(MI->getOperand(2).getImm());
return isUInt<6>(MI.getOperand(2).getImm());

case Hexagon::L2_loadrd_pi:
return isShiftedInt<4,3>(MI->getOperand(3).getImm());
return isShiftedInt<4,3>(MI.getOperand(3).getImm());

case Hexagon::L2_loadri_pi:
return isShiftedInt<4,2>(MI->getOperand(3).getImm());
return isShiftedInt<4,2>(MI.getOperand(3).getImm());

case Hexagon::L2_loadrh_pi:
case Hexagon::L2_loadruh_pi:
return isShiftedInt<4,1>(MI->getOperand(3).getImm());
return isShiftedInt<4,1>(MI.getOperand(3).getImm());

case Hexagon::L2_loadrb_pi:
case Hexagon::L2_loadrub_pi:
return isInt<4>(MI->getOperand(3).getImm());
return isInt<4>(MI.getOperand(3).getImm());

case Hexagon::S4_storeirb_io:
case Hexagon::S4_storeirh_io:
case Hexagon::S4_storeiri_io:
return (OpCExtended[1] || isUInt<6>(MI->getOperand(1).getImm())) &&
(OpCExtended[2] || isInt<6>(MI->getOperand(2).getImm()));
return (OpCExtended[1] || isUInt<6>(MI.getOperand(1).getImm())) &&
(OpCExtended[2] || isInt<6>(MI.getOperand(2).getImm()));

case Hexagon::A2_addi:
return isInt<8>(MI->getOperand(2).getImm());
return isInt<8>(MI.getOperand(2).getImm());

case Hexagon::A2_aslh:
case Hexagon::A2_asrh:
Expand Down Expand Up @@ -1662,13 +1660,13 @@ bool HexagonInstrInfo::isCompoundBranchInstr(const MachineInstr *MI) const {


bool HexagonInstrInfo::isCondInst(const MachineInstr *MI) const {
return (MI->isBranch() && isPredicated(MI)) ||
return (MI->isBranch() && isPredicated(*MI)) ||
isConditionalTransfer(MI) ||
isConditionalALU32(MI) ||
isConditionalLoad(MI) ||
// Predicated stores which don't have a .new on any operands.
(MI->mayStore() && isPredicated(MI) && !isNewValueStore(MI) &&
!isPredicatedNew(MI));
(MI->mayStore() && isPredicated(*MI) && !isNewValueStore(MI) &&
!isPredicatedNew(*MI));
}


Expand Down Expand Up @@ -1733,7 +1731,7 @@ bool HexagonInstrInfo::isConditionalALU32(const MachineInstr* MI) const {
// FIXME - Function name and it's functionality don't match.
// It should be renamed to hasPredNewOpcode()
bool HexagonInstrInfo::isConditionalLoad(const MachineInstr* MI) const {
if (!MI->getDesc().mayLoad() || !isPredicated(MI))
if (!MI->getDesc().mayLoad() || !isPredicated(*MI))
return false;

int PNewOpcode = Hexagon::getPredNewOpcode(MI->getOpcode());
Expand Down Expand Up @@ -1939,8 +1937,7 @@ bool HexagonInstrInfo::isDotCurInst(const MachineInstr* MI) const {
// Returns true, if any one of the operands is a dot new
// insn, whether it is predicated dot new or register dot new.
bool HexagonInstrInfo::isDotNewInst(const MachineInstr* MI) const {
if (isNewValueInst(MI) ||
(isPredicated(MI) && isPredicatedNew(MI)))
if (isNewValueInst(MI) || (isPredicated(*MI) && isPredicatedNew(*MI)))
return true;

return false;
Expand Down Expand Up @@ -2305,8 +2302,8 @@ bool HexagonInstrInfo::isPostIncrement(const MachineInstr* MI) const {
}


bool HexagonInstrInfo::isPredicatedNew(const MachineInstr *MI) const {
const uint64_t F = MI->getDesc().TSFlags;
bool HexagonInstrInfo::isPredicatedNew(const MachineInstr &MI) const {
const uint64_t F = MI.getDesc().TSFlags;
assert(isPredicated(MI));
return (F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask;
}
Expand All @@ -2319,8 +2316,8 @@ bool HexagonInstrInfo::isPredicatedNew(unsigned Opcode) const {
}


bool HexagonInstrInfo::isPredicatedTrue(const MachineInstr *MI) const {
const uint64_t F = MI->getDesc().TSFlags;
bool HexagonInstrInfo::isPredicatedTrue(const MachineInstr &MI) const {
const uint64_t F = MI.getDesc().TSFlags;
return !((F >> HexagonII::PredicatedFalsePos) &
HexagonII::PredicatedFalseMask);
}
Expand Down Expand Up @@ -3084,7 +3081,7 @@ bool HexagonInstrInfo::getBaseAndOffsetPosition(const MachineInstr *MI,
} else
return false;

if (isPredicated(MI)) {
if (isPredicated(*MI)) {
BasePos++;
OffsetPos++;
}
Expand Down Expand Up @@ -3138,7 +3135,7 @@ SmallVector<MachineInstr*, 2> HexagonInstrInfo::getBranchingInstrs(
return Jumpers;
--I;
}
if (!isUnpredicatedTerminator(&*I))
if (!isUnpredicatedTerminator(*I))
return Jumpers;

// Get the last instruction in the block.
Expand All @@ -3147,7 +3144,7 @@ SmallVector<MachineInstr*, 2> HexagonInstrInfo::getBranchingInstrs(
MachineInstr *SecondLastInst = nullptr;
// Find one more terminator if present.
do {
if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(&*I)) {
if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) {
if (!SecondLastInst) {
SecondLastInst = &*I;
Jumpers.push_back(SecondLastInst);
Expand Down Expand Up @@ -4106,7 +4103,7 @@ bool HexagonInstrInfo::invertAndChangeJumpTarget(
--TargetPos;
assert((TargetPos >= 0) && MI->getOperand(TargetPos).isMBB());
MI->getOperand(TargetPos).setMBB(NewTarget);
if (EnableBranchPrediction && isPredicatedNew(MI)) {
if (EnableBranchPrediction && isPredicatedNew(*MI)) {
NewOpcode = reversePrediction(NewOpcode);
}
MI->setDesc(get(NewOpcode));
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Target/Hexagon/HexagonInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ class HexagonInstrInfo : public HexagonGenInstrInfo {
MachineBasicBlock::iterator MI) const override;

/// Returns true if the instruction is already predicated.
bool isPredicated(const MachineInstr *MI) const override;
bool isPredicated(const MachineInstr &MI) const override;

/// Convert the instruction into a predicated instruction.
/// It returns true if the operation was successful.
bool PredicateInstruction(MachineInstr *MI,
bool PredicateInstruction(MachineInstr &MI,
ArrayRef<MachineOperand> Cond) const override;

/// Returns true if the first specified predicate
Expand All @@ -198,13 +198,13 @@ class HexagonInstrInfo : public HexagonGenInstrInfo {
/// If the specified instruction defines any predicate
/// or condition code register(s) used for predication, returns true as well
/// as the definition predicate(s) by reference.
bool DefinesPredicate(MachineInstr *MI,
bool DefinesPredicate(MachineInstr &MI,
std::vector<MachineOperand> &Pred) const override;

/// Return true if the specified instruction can be predicated.
/// By default, this returns true for every instruction with a
/// PredicateOperand.
bool isPredicable(MachineInstr *MI) const override;
bool isPredicable(MachineInstr &MI) const override;

/// Test if the given instruction should be considered a scheduling boundary.
/// This primarily includes labels and terminators.
Expand Down Expand Up @@ -301,9 +301,9 @@ class HexagonInstrInfo : public HexagonGenInstrInfo {
bool isNewValueStore(unsigned Opcode) const;
bool isOperandExtended(const MachineInstr *MI, unsigned OperandNum) const;
bool isPostIncrement(const MachineInstr* MI) const;
bool isPredicatedNew(const MachineInstr *MI) const;
bool isPredicatedNew(const MachineInstr &MI) const;
bool isPredicatedNew(unsigned Opcode) const;
bool isPredicatedTrue(const MachineInstr *MI) const;
bool isPredicatedTrue(const MachineInstr &MI) const;
bool isPredicatedTrue(unsigned Opcode) const;
bool isPredicated(unsigned Opcode) const;
bool isPredicateLate(unsigned Opcode) const;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Hexagon/HexagonNewValueJump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static bool canBeFeederToNewValueJump(const HexagonInstrInfo *QII,
MachineFunction &MF) {

// Predicated instruction can not be feeder to NVJ.
if (QII->isPredicated(II))
if (QII->isPredicated(*II))
return false;

// Bail out if feederReg is a paired register (double regs in
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Hexagon/HexagonPeephole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ bool HexagonPeephole::runOnMachineFunction(MachineFunction &MF) {
// Look for Predicated instructions.
if (!DisablePNotP) {
bool Done = false;
if (QII->isPredicated(MI)) {
if (QII->isPredicated(*MI)) {
MachineOperand &Op0 = MI->getOperand(0);
unsigned Reg0 = Op0.getReg();
const TargetRegisterClass *RC0 = MRI->getRegClass(Reg0);
Expand Down
32 changes: 16 additions & 16 deletions llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ enum PredicateKind {

/// Returns true if an instruction is predicated on p0 and false if it's
/// predicated on !p0.
static PredicateKind getPredicateSense(const MachineInstr *MI,
static PredicateKind getPredicateSense(const MachineInstr &MI,
const HexagonInstrInfo *HII) {
if (!HII->isPredicated(MI))
return PK_Unknown;
Expand Down Expand Up @@ -570,8 +570,8 @@ bool HexagonPacketizerList::canPromoteToNewValueStore(const MachineInstr *MI,

// If the source that feeds the store is predicated, new value store must
// also be predicated.
if (HII->isPredicated(PacketMI)) {
if (!HII->isPredicated(MI))
if (HII->isPredicated(*PacketMI)) {
if (!HII->isPredicated(*MI))
return false;

// Check to make sure that they both will have their predicates
Expand Down Expand Up @@ -613,8 +613,8 @@ bool HexagonPacketizerList::canPromoteToNewValueStore(const MachineInstr *MI,
// 3) Both new-value register producer and user should have same predicate
// sense, i.e, either both should be negated or both should be non-negated.
if (predRegNumDst != predRegNumSrc ||
HII->isDotNewInst(PacketMI) != HII->isDotNewInst(MI) ||
getPredicateSense(MI, HII) != getPredicateSense(PacketMI, HII))
HII->isDotNewInst(PacketMI) != HII->isDotNewInst(MI) ||
getPredicateSense(*MI, HII) != getPredicateSense(*PacketMI, HII))
return false;
}

Expand Down Expand Up @@ -793,7 +793,7 @@ bool HexagonPacketizerList::restrictingDepExistInPacket(MachineInstr* MI,

for (auto I : CurrentPacketMIs) {
// We only care for dependencies to predicated instructions
if (!HII->isPredicated(I))
if (!HII->isPredicated(*I))
continue;

// Scheduling Unit for current insn in the packet
Expand All @@ -817,13 +817,13 @@ bool HexagonPacketizerList::restrictingDepExistInPacket(MachineInstr* MI,


/// Gets the predicate register of a predicated instruction.
static unsigned getPredicatedRegister(MachineInstr *MI,
static unsigned getPredicatedRegister(MachineInstr &MI,
const HexagonInstrInfo *QII) {
/// We use the following rule: The first predicate register that is a use is
/// the predicate register of a predicated instruction.
assert(QII->isPredicated(MI) && "Must be predicated instruction");

for (auto &Op : MI->operands()) {
for (auto &Op : MI.operands()) {
if (Op.isReg() && Op.getReg() && Op.isUse() &&
Hexagon::PredRegsRegClass.contains(Op.getReg()))
return Op.getReg();
Expand All @@ -835,16 +835,16 @@ static unsigned getPredicatedRegister(MachineInstr *MI,

// Given two predicated instructions, this function detects whether
// the predicates are complements.
bool HexagonPacketizerList::arePredicatesComplements(MachineInstr *MI1,
MachineInstr *MI2) {
bool HexagonPacketizerList::arePredicatesComplements(MachineInstr &MI1,
MachineInstr &MI2) {
// If we don't know the predicate sense of the instructions bail out early, we
// need it later.
if (getPredicateSense(MI1, HII) == PK_Unknown ||
getPredicateSense(MI2, HII) == PK_Unknown)
return false;

// Scheduling unit for candidate.
SUnit *SU = MIToSUnit[MI1];
SUnit *SU = MIToSUnit[&MI1];

// One corner case deals with the following scenario:
// Trying to add
Expand Down Expand Up @@ -898,7 +898,7 @@ bool HexagonPacketizerList::arePredicatesComplements(MachineInstr *MI1,
Hexagon::PredRegsRegClass.contains(PReg1) &&
Hexagon::PredRegsRegClass.contains(PReg2) &&
getPredicateSense(MI1, HII) != getPredicateSense(MI2, HII) &&
HII->isDotNewInst(MI1) == HII->isDotNewInst(MI2);
HII->isDotNewInst(&MI1) == HII->isDotNewInst(&MI2);
}

// Initialize packetizer flags.
Expand Down Expand Up @@ -1045,7 +1045,7 @@ bool HexagonPacketizerList::hasDeadDependence(const MachineInstr *I,
// defining the same (dead) register.
if (I->isCall() || J->isCall())
return false;
if (HII->isPredicated(I) || HII->isPredicated(J))
if (HII->isPredicated(*I) || HII->isPredicated(*J))
return false;

BitVector DeadDefs(Hexagon::NUM_TARGET_REGS);
Expand Down Expand Up @@ -1085,7 +1085,7 @@ bool HexagonPacketizerList::hasControlDependence(const MachineInstr *I,
auto isBadForLoopN = [this] (const MachineInstr *MI) -> bool {
if (MI->isCall() || HII->isDeallocRet(MI) || HII->isNewValueJump(MI))
return true;
if (HII->isPredicated(MI) && HII->isPredicatedNew(MI) && HII->isJumpR(MI))
if (HII->isPredicated(*MI) && HII->isPredicatedNew(*MI) && HII->isJumpR(MI))
return true;
return false;
};
Expand Down Expand Up @@ -1275,8 +1275,8 @@ bool HexagonPacketizerList::isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) {

// For predicated instructions, if the predicates are complements then
// there can be no dependence.
if (HII->isPredicated(I) && HII->isPredicated(J) &&
arePredicatesComplements(I, J)) {
if (HII->isPredicated(*I) && HII->isPredicated(*J) &&
arePredicatesComplements(*I, *J)) {
// Not always safe to do this translation.
// DAG Builder attempts to reduce dependence edges using transitive
// nature of dependencies. Here is an example:
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class HexagonPacketizerList : public VLIWPacketizerList {
bool canPromoteToNewValueStore(const MachineInstr* MI,
const MachineInstr* PacketMI, unsigned DepReg);
bool demoteToDotOld(MachineInstr* MI);
bool arePredicatesComplements(MachineInstr* MI1, MachineInstr* MI2);
bool arePredicatesComplements(MachineInstr &MI1, MachineInstr &MI2);
bool restrictingDepExistInPacket(MachineInstr*, unsigned);
bool isNewifiable(const MachineInstr *MI);
bool isCurifiable(MachineInstr* MI);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/Hexagon/RDFGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ bool RegisterAliasInfo::alias(RegisterRef RA, RegisterRef RB) const {
// unchanged across this def.
bool TargetOperandInfo::isPreserving(const MachineInstr &In, unsigned OpNum)
const {
return TII.isPredicated(&In);
return TII.isPredicated(In);
}

// Check if the definition of RR produces an unspecified value.
Expand Down Expand Up @@ -1179,7 +1179,7 @@ void DataFlowGraph::buildStmt(NodeAddr<BlockNode*> BA, MachineInstr &In) {
ImpUses.insert({R, 0});

bool IsCall = In.isCall(), IsReturn = In.isReturn();
bool IsPredicated = TII.isPredicated(&In);
bool IsPredicated = TII.isPredicated(In);
unsigned NumOps = In.getNumOperands();

// Avoid duplicate implicit defs. This will not detect cases of implicit
Expand Down
11 changes: 6 additions & 5 deletions llvm/lib/Target/MSP430/MSP430InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,14 @@ ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
return false;
}

bool MSP430InstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
if (!MI->isTerminator()) return false;
bool MSP430InstrInfo::isUnpredicatedTerminator(const MachineInstr &MI) const {
if (!MI.isTerminator())
return false;

// Conditional branch is a special case.
if (MI->isBranch() && !MI->isBarrier())
if (MI.isBranch() && !MI.isBarrier())
return true;
if (!MI->isPredicable())
if (!MI.isPredicable())
return true;
return !isPredicated(MI);
}
Expand All @@ -182,7 +183,7 @@ bool MSP430InstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,

// Working from the bottom, when we see a non-terminator
// instruction, we're done.
if (!isUnpredicatedTerminator(I))
if (!isUnpredicatedTerminator(*I))
break;

// A terminator that isn't a branch can't easily be handled
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/MSP430/MSP430InstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MSP430InstrInfo : public MSP430GenInstrInfo {
// Branch folding goodness
bool
ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
bool isUnpredicatedTerminator(const MachineInstr *MI) const override;
bool isUnpredicatedTerminator(const MachineInstr &MI) const override;
bool AnalyzeBranch(MachineBasicBlock &MBB,
MachineBasicBlock *&TBB, MachineBasicBlock *&FBB,
SmallVectorImpl<MachineOperand> &Cond,
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/Mips/MipsInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ MipsInstrInfo::BranchType MipsInstrInfo::AnalyzeBranch(
while (I != REnd && I->isDebugValue())
++I;

if (I == REnd || !isUnpredicatedTerminator(&*I)) {
if (I == REnd || !isUnpredicatedTerminator(*I)) {
// This block ends with no branches (it just falls through to its succ).
// Leave TBB/FBB null.
TBB = FBB = nullptr;
Expand All @@ -208,7 +208,7 @@ MipsInstrInfo::BranchType MipsInstrInfo::AnalyzeBranch(
SecondLastOpc = getAnalyzableBrOpc(SecondLastInst->getOpcode());

// Not an analyzable branch (must be an indirect jump).
if (isUnpredicatedTerminator(SecondLastInst) && !SecondLastOpc)
if (isUnpredicatedTerminator(*SecondLastInst) && !SecondLastOpc)
return BT_None;
}

Expand All @@ -227,7 +227,7 @@ MipsInstrInfo::BranchType MipsInstrInfo::AnalyzeBranch(

// If we reached here, there are two branches.
// If there are three terminators, we don't know what sort of block this is.
if (++I != REnd && isUnpredicatedTerminator(&*I))
if (++I != REnd && isUnpredicatedTerminator(*I))
return BT_None;

BranchInstrs.insert(BranchInstrs.begin(), SecondLastInst);
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/NVPTX/NVPTXInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ bool NVPTXInstrInfo::AnalyzeBranch(
SmallVectorImpl<MachineOperand> &Cond, bool AllowModify) const {
// If the block has no terminators, it just falls into the block after it.
MachineBasicBlock::iterator I = MBB.end();
if (I == MBB.begin() || !isUnpredicatedTerminator(--I))
if (I == MBB.begin() || !isUnpredicatedTerminator(*--I))
return false;

// Get the last instruction in the block.
MachineInstr *LastInst = I;

// If there is only one terminator instruction, process it.
if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
if (I == MBB.begin() || !isUnpredicatedTerminator(*--I)) {
if (LastInst->getOpcode() == NVPTX::GOTO) {
TBB = LastInst->getOperand(0).getMBB();
return false;
Expand All @@ -175,7 +175,7 @@ bool NVPTXInstrInfo::AnalyzeBranch(
MachineInstr *SecondLastInst = I;

// If there are three terminators, we don't know what sort of block this is.
if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(--I))
if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(*--I))
return true;

// If the block ends with NVPTX::GOTO and NVPTX:CBranch, handle it.
Expand Down
125 changes: 61 additions & 64 deletions llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,14 @@ bool PPCInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
if (I == MBB.end())
return false;

if (!isUnpredicatedTerminator(I))
if (!isUnpredicatedTerminator(*I))
return false;

// Get the last instruction in the block.
MachineInstr *LastInst = I;

// If there is only one terminator instruction, process it.
if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
if (I == MBB.begin() || !isUnpredicatedTerminator(*--I)) {
if (LastInst->getOpcode() == PPC::B) {
if (!LastInst->getOperand(0).isMBB())
return true;
Expand Down Expand Up @@ -522,8 +522,7 @@ bool PPCInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
MachineInstr *SecondLastInst = I;

// If there are three terminators, we don't know what sort of block this is.
if (SecondLastInst && I != MBB.begin() &&
isUnpredicatedTerminator(--I))
if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(*--I))
return true;

// If the block ends with PPC::B and PPC:BCC, handle it.
Expand Down Expand Up @@ -1299,7 +1298,7 @@ bool PPCInstrInfo::isProfitableToIfCvt(MachineBasicBlock &TMBB,
}


bool PPCInstrInfo::isPredicated(const MachineInstr *MI) const {
bool PPCInstrInfo::isPredicated(const MachineInstr &MI) const {
// The predicated branches are identified by their type, not really by the
// explicit presence of a predicate. Furthermore, some of them can be
// predicated more than once. Because if conversion won't try to predicate
Expand All @@ -1310,73 +1309,71 @@ bool PPCInstrInfo::isPredicated(const MachineInstr *MI) const {
return false;
}

bool PPCInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
if (!MI->isTerminator())
bool PPCInstrInfo::isUnpredicatedTerminator(const MachineInstr &MI) const {
if (!MI.isTerminator())
return false;

// Conditional branch is a special case.
if (MI->isBranch() && !MI->isBarrier())
if (MI.isBranch() && !MI.isBarrier())
return true;

return !isPredicated(MI);
}

bool PPCInstrInfo::PredicateInstruction(MachineInstr *MI,
bool PPCInstrInfo::PredicateInstruction(MachineInstr &MI,
ArrayRef<MachineOperand> Pred) const {
unsigned OpC = MI->getOpcode();
unsigned OpC = MI.getOpcode();
if (OpC == PPC::BLR || OpC == PPC::BLR8) {
if (Pred[1].getReg() == PPC::CTR8 || Pred[1].getReg() == PPC::CTR) {
bool isPPC64 = Subtarget.isPPC64();
MI->setDesc(get(Pred[0].getImm() ?
(isPPC64 ? PPC::BDNZLR8 : PPC::BDNZLR) :
(isPPC64 ? PPC::BDZLR8 : PPC::BDZLR)));
MI.setDesc(get(Pred[0].getImm() ? (isPPC64 ? PPC::BDNZLR8 : PPC::BDNZLR)
: (isPPC64 ? PPC::BDZLR8 : PPC::BDZLR)));
} else if (Pred[0].getImm() == PPC::PRED_BIT_SET) {
MI->setDesc(get(PPC::BCLR));
MachineInstrBuilder(*MI->getParent()->getParent(), MI)
.addReg(Pred[1].getReg());
MI.setDesc(get(PPC::BCLR));
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
.addReg(Pred[1].getReg());
} else if (Pred[0].getImm() == PPC::PRED_BIT_UNSET) {
MI->setDesc(get(PPC::BCLRn));
MachineInstrBuilder(*MI->getParent()->getParent(), MI)
.addReg(Pred[1].getReg());
MI.setDesc(get(PPC::BCLRn));
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
.addReg(Pred[1].getReg());
} else {
MI->setDesc(get(PPC::BCCLR));
MachineInstrBuilder(*MI->getParent()->getParent(), MI)
.addImm(Pred[0].getImm())
.addReg(Pred[1].getReg());
MI.setDesc(get(PPC::BCCLR));
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
.addImm(Pred[0].getImm())
.addReg(Pred[1].getReg());
}

return true;
} else if (OpC == PPC::B) {
if (Pred[1].getReg() == PPC::CTR8 || Pred[1].getReg() == PPC::CTR) {
bool isPPC64 = Subtarget.isPPC64();
MI->setDesc(get(Pred[0].getImm() ?
(isPPC64 ? PPC::BDNZ8 : PPC::BDNZ) :
(isPPC64 ? PPC::BDZ8 : PPC::BDZ)));
MI.setDesc(get(Pred[0].getImm() ? (isPPC64 ? PPC::BDNZ8 : PPC::BDNZ)
: (isPPC64 ? PPC::BDZ8 : PPC::BDZ)));
} else if (Pred[0].getImm() == PPC::PRED_BIT_SET) {
MachineBasicBlock *MBB = MI->getOperand(0).getMBB();
MI->RemoveOperand(0);
MachineBasicBlock *MBB = MI.getOperand(0).getMBB();
MI.RemoveOperand(0);

MI->setDesc(get(PPC::BC));
MachineInstrBuilder(*MI->getParent()->getParent(), MI)
.addReg(Pred[1].getReg())
.addMBB(MBB);
MI.setDesc(get(PPC::BC));
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
.addReg(Pred[1].getReg())
.addMBB(MBB);
} else if (Pred[0].getImm() == PPC::PRED_BIT_UNSET) {
MachineBasicBlock *MBB = MI->getOperand(0).getMBB();
MI->RemoveOperand(0);
MachineBasicBlock *MBB = MI.getOperand(0).getMBB();
MI.RemoveOperand(0);

MI->setDesc(get(PPC::BCn));
MachineInstrBuilder(*MI->getParent()->getParent(), MI)
.addReg(Pred[1].getReg())
.addMBB(MBB);
MI.setDesc(get(PPC::BCn));
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
.addReg(Pred[1].getReg())
.addMBB(MBB);
} else {
MachineBasicBlock *MBB = MI->getOperand(0).getMBB();
MI->RemoveOperand(0);

MI->setDesc(get(PPC::BCC));
MachineInstrBuilder(*MI->getParent()->getParent(), MI)
.addImm(Pred[0].getImm())
.addReg(Pred[1].getReg())
.addMBB(MBB);
MachineBasicBlock *MBB = MI.getOperand(0).getMBB();
MI.RemoveOperand(0);

MI.setDesc(get(PPC::BCC));
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
.addImm(Pred[0].getImm())
.addReg(Pred[1].getReg())
.addMBB(MBB);
}

return true;
Expand All @@ -1389,24 +1386,24 @@ bool PPCInstrInfo::PredicateInstruction(MachineInstr *MI,
bool isPPC64 = Subtarget.isPPC64();

if (Pred[0].getImm() == PPC::PRED_BIT_SET) {
MI->setDesc(get(isPPC64 ? (setLR ? PPC::BCCTRL8 : PPC::BCCTR8) :
(setLR ? PPC::BCCTRL : PPC::BCCTR)));
MachineInstrBuilder(*MI->getParent()->getParent(), MI)
.addReg(Pred[1].getReg());
MI.setDesc(get(isPPC64 ? (setLR ? PPC::BCCTRL8 : PPC::BCCTR8)
: (setLR ? PPC::BCCTRL : PPC::BCCTR)));
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
.addReg(Pred[1].getReg());
return true;
} else if (Pred[0].getImm() == PPC::PRED_BIT_UNSET) {
MI->setDesc(get(isPPC64 ? (setLR ? PPC::BCCTRL8n : PPC::BCCTR8n) :
(setLR ? PPC::BCCTRLn : PPC::BCCTRn)));
MachineInstrBuilder(*MI->getParent()->getParent(), MI)
.addReg(Pred[1].getReg());
MI.setDesc(get(isPPC64 ? (setLR ? PPC::BCCTRL8n : PPC::BCCTR8n)
: (setLR ? PPC::BCCTRLn : PPC::BCCTRn)));
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
.addReg(Pred[1].getReg());
return true;
}

MI->setDesc(get(isPPC64 ? (setLR ? PPC::BCCCTRL8 : PPC::BCCCTR8) :
(setLR ? PPC::BCCCTRL : PPC::BCCCTR)));
MachineInstrBuilder(*MI->getParent()->getParent(), MI)
.addImm(Pred[0].getImm())
.addReg(Pred[1].getReg());
MI.setDesc(get(isPPC64 ? (setLR ? PPC::BCCCTRL8 : PPC::BCCCTR8)
: (setLR ? PPC::BCCCTRL : PPC::BCCCTR)));
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
.addImm(Pred[0].getImm())
.addReg(Pred[1].getReg());
return true;
}

Expand Down Expand Up @@ -1444,7 +1441,7 @@ bool PPCInstrInfo::SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
return false;
}

bool PPCInstrInfo::DefinesPredicate(MachineInstr *MI,
bool PPCInstrInfo::DefinesPredicate(MachineInstr &MI,
std::vector<MachineOperand> &Pred) const {
// Note: At the present time, the contents of Pred from this function is
// unused by IfConversion. This implementation follows ARM by pushing the
Expand All @@ -1457,8 +1454,8 @@ bool PPCInstrInfo::DefinesPredicate(MachineInstr *MI,
&PPC::CTRRCRegClass, &PPC::CTRRC8RegClass };

bool Found = false;
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
const MachineOperand &MO = MI->getOperand(i);
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
const MachineOperand &MO = MI.getOperand(i);
for (unsigned c = 0; c < array_lengthof(RCs) && !Found; ++c) {
const TargetRegisterClass *RC = RCs[c];
if (MO.isReg()) {
Expand All @@ -1480,8 +1477,8 @@ bool PPCInstrInfo::DefinesPredicate(MachineInstr *MI,
return Found;
}

bool PPCInstrInfo::isPredicable(MachineInstr *MI) const {
unsigned OpC = MI->getOpcode();
bool PPCInstrInfo::isPredicable(MachineInstr &MI) const {
unsigned OpC = MI.getOpcode();
switch (OpC) {
default:
return false;
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Target/PowerPC/PPCInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,20 @@ class PPCInstrInfo : public PPCGenInstrInfo {
}

// Predication support.
bool isPredicated(const MachineInstr *MI) const override;
bool isPredicated(const MachineInstr &MI) const override;

bool isUnpredicatedTerminator(const MachineInstr *MI) const override;
bool isUnpredicatedTerminator(const MachineInstr &MI) const override;

bool PredicateInstruction(MachineInstr *MI,
bool PredicateInstruction(MachineInstr &MI,
ArrayRef<MachineOperand> Pred) const override;

bool SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
ArrayRef<MachineOperand> Pred2) const override;

bool DefinesPredicate(MachineInstr *MI,
bool DefinesPredicate(MachineInstr &MI,
std::vector<MachineOperand> &Pred) const override;

bool isPredicable(MachineInstr *MI) const override;
bool isPredicable(MachineInstr &MI) const override;

// Comparison optimization.

Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/Sparc/SparcInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ bool SparcInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
if (I == MBB.end())
return false;

if (!isUnpredicatedTerminator(I))
if (!isUnpredicatedTerminator(*I))
return false;

// Get the last instruction in the block.
MachineInstr *LastInst = I;
unsigned LastOpc = LastInst->getOpcode();

// If there is only one terminator instruction, process it.
if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
if (I == MBB.begin() || !isUnpredicatedTerminator(*--I)) {
if (isUncondBranchOpcode(LastOpc)) {
TBB = LastInst->getOperand(0).getMBB();
return false;
Expand All @@ -180,7 +180,7 @@ bool SparcInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
LastInst->eraseFromParent();
LastInst = SecondLastInst;
LastOpc = LastInst->getOpcode();
if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
if (I == MBB.begin() || !isUnpredicatedTerminator(*--I)) {
// Return now the only terminator is an unconditional branch.
TBB = LastInst->getOperand(0).getMBB();
return false;
Expand All @@ -192,7 +192,7 @@ bool SparcInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
}

// If there are three terminators, we don't know what sort of block this is.
if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(--I))
if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(*--I))
return true;

// If the block ends with a B and a Bcc, handle it.
Expand Down
21 changes: 11 additions & 10 deletions llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ bool SystemZInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,

// Working from the bottom, when we see a non-terminator instruction, we're
// done.
if (!isUnpredicatedTerminator(I))
if (!isUnpredicatedTerminator(*I))
break;

// A terminator that isn't a branch can't easily be handled by this
Expand Down Expand Up @@ -506,8 +506,8 @@ static unsigned getConditionalMove(unsigned Opcode) {
}
}

bool SystemZInstrInfo::isPredicable(MachineInstr *MI) const {
unsigned Opcode = MI->getOpcode();
bool SystemZInstrInfo::isPredicable(MachineInstr &MI) const {
unsigned Opcode = MI.getOpcode();
return STI.hasLoadStoreOnCond() && getConditionalMove(Opcode);
}

Expand All @@ -529,19 +529,20 @@ isProfitableToIfCvt(MachineBasicBlock &TMBB,
return false;
}

bool SystemZInstrInfo::
PredicateInstruction(MachineInstr *MI, ArrayRef<MachineOperand> Pred) const {
bool SystemZInstrInfo::PredicateInstruction(
MachineInstr &MI, ArrayRef<MachineOperand> Pred) const {
assert(Pred.size() == 2 && "Invalid condition");
unsigned CCValid = Pred[0].getImm();
unsigned CCMask = Pred[1].getImm();
assert(CCMask > 0 && CCMask < 15 && "Invalid predicate");
unsigned Opcode = MI->getOpcode();
unsigned Opcode = MI.getOpcode();
if (STI.hasLoadStoreOnCond()) {
if (unsigned CondOpcode = getConditionalMove(Opcode)) {
MI->setDesc(get(CondOpcode));
MachineInstrBuilder(*MI->getParent()->getParent(), MI)
.addImm(CCValid).addImm(CCMask)
.addReg(SystemZ::CC, RegState::Implicit);
MI.setDesc(get(CondOpcode));
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
.addImm(CCValid)
.addImm(CCMask)
.addReg(SystemZ::CC, RegState::Implicit);
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/SystemZ/SystemZInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class SystemZInstrInfo : public SystemZGenInstrInfo {
bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
unsigned SrcReg2, int Mask, int Value,
const MachineRegisterInfo *MRI) const override;
bool isPredicable(MachineInstr *MI) const override;
bool isPredicable(MachineInstr &MI) const override;
bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,
unsigned ExtraPredCycles,
BranchProbability Probability) const override;
Expand All @@ -165,7 +165,7 @@ class SystemZInstrInfo : public SystemZGenInstrInfo {
MachineBasicBlock &FMBB,
unsigned NumCyclesF, unsigned ExtraPredCyclesF,
BranchProbability Probability) const override;
bool PredicateInstruction(MachineInstr *MI,
bool PredicateInstruction(MachineInstr &MI,
ArrayRef<MachineOperand> Pred) const override;
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
DebugLoc DL, unsigned DestReg, unsigned SrcReg,
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Target/X86/X86InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3903,13 +3903,13 @@ unsigned X86::getCMovFromCond(CondCode CC, unsigned RegBytes,
}
}

bool X86InstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
if (!MI->isTerminator()) return false;
bool X86InstrInfo::isUnpredicatedTerminator(const MachineInstr &MI) const {
if (!MI.isTerminator()) return false;

// Conditional branch is a special case.
if (MI->isBranch() && !MI->isBarrier())
if (MI.isBranch() && !MI.isBarrier())
return true;
if (!MI->isPredicable())
if (!MI.isPredicable())
return true;
return !isPredicated(MI);
}
Expand All @@ -3930,7 +3930,7 @@ bool X86InstrInfo::AnalyzeBranchImpl(

// Working from the bottom, when we see a non-terminator instruction, we're
// done.
if (!isUnpredicatedTerminator(I))
if (!isUnpredicatedTerminator(*I))
break;

// A terminator that isn't a branch can't easily be handled by this
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/X86InstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class X86InstrInfo final : public X86GenInstrInfo {
unsigned SrcOpIdx2) const;

// Branch analysis.
bool isUnpredicatedTerminator(const MachineInstr* MI) const override;
bool isUnpredicatedTerminator(const MachineInstr &MI) const override;
bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
MachineBasicBlock *&FBB,
SmallVectorImpl<MachineOperand> &Cond,
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/Target/XCore/XCoreInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ XCoreInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
if (I == MBB.end())
return false;

if (!isUnpredicatedTerminator(I))
if (!isUnpredicatedTerminator(*I))
return false;

// Get the last instruction in the block.
MachineInstr *LastInst = I;

// If there is only one terminator instruction, process it.
if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
if (I == MBB.begin() || !isUnpredicatedTerminator(*--I)) {
if (IsBRU(LastInst->getOpcode())) {
TBB = LastInst->getOperand(0).getMBB();
return false;
Expand All @@ -230,8 +230,7 @@ XCoreInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
MachineInstr *SecondLastInst = I;

// If there are three terminators, we don't know what sort of block this is.
if (SecondLastInst && I != MBB.begin() &&
isUnpredicatedTerminator(--I))
if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(*--I))
return true;

unsigned SecondLastOpc = SecondLastInst->getOpcode();
Expand Down