diff --git a/llvm/lib/Target/ARM/MVEVPTBlockPass.cpp b/llvm/lib/Target/ARM/MVEVPTBlockPass.cpp index 1c09d42a48944f..bc0a80b177ed2c 100644 --- a/llvm/lib/Target/ARM/MVEVPTBlockPass.cpp +++ b/llvm/lib/Target/ARM/MVEVPTBlockPass.cpp @@ -22,9 +22,9 @@ #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineInstrBundle.h" #include "llvm/CodeGen/MachineOperand.h" -#include "llvm/CodeGen/ReachingDefAnalysis.h" #include "llvm/IR/DebugLoc.h" #include "llvm/MC/MCInstrDesc.h" +#include "llvm/MC/MCRegisterInfo.h" #include "llvm/Support/Debug.h" #include #include @@ -37,21 +37,16 @@ namespace { class MVEVPTBlock : public MachineFunctionPass { public: static char ID; + const Thumb2InstrInfo *TII; + const TargetRegisterInfo *TRI; MVEVPTBlock() : MachineFunctionPass(ID) {} bool runOnMachineFunction(MachineFunction &Fn) override; - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesCFG(); - AU.addRequired(); - MachineFunctionPass::getAnalysisUsage(AU); - } - MachineFunctionProperties getRequiredProperties() const override { return MachineFunctionProperties().set( - MachineFunctionProperties::Property::NoVRegs).set( - MachineFunctionProperties::Property::TracksLiveness); + MachineFunctionProperties::Property::NoVRegs); } StringRef getPassName() const override { @@ -60,9 +55,6 @@ namespace { private: bool InsertVPTBlocks(MachineBasicBlock &MBB); - - const Thumb2InstrInfo *TII = nullptr; - ReachingDefAnalysis *RDA = nullptr; }; char MVEVPTBlock::ID = 0; @@ -142,25 +134,35 @@ static unsigned VCMPOpcodeToVPT(unsigned Opcode) { } } -static MachineInstr *findVCMPToFoldIntoVPST(MachineInstr *MI, - ReachingDefAnalysis *RDA, +static MachineInstr *findVCMPToFoldIntoVPST(MachineBasicBlock::iterator MI, + const TargetRegisterInfo *TRI, unsigned &NewOpcode) { - // First, search backwards to the instruction that defines VPR - auto *Def = RDA->getReachingMIDef(MI, ARM::VPR); - if (!Def) - return nullptr; + // Search backwards to the instruction that defines VPR. This may or not + // be a VCMP, we check that after this loop. If we find another instruction + // that reads cpsr, we return nullptr. + MachineBasicBlock::iterator CmpMI = MI; + while (CmpMI != MI->getParent()->begin()) { + --CmpMI; + if (CmpMI->modifiesRegister(ARM::VPR, TRI)) + break; + if (CmpMI->readsRegister(ARM::VPR, TRI)) + break; + } - // Now check that Def is a VCMP - if (!(NewOpcode = VCMPOpcodeToVPT(Def->getOpcode()))) + if (CmpMI == MI) return nullptr; - - // Check that Def's operands are not defined between the VCMP and MI, i.e. - // check that they have the same reaching def. - if (!RDA->hasSameReachingDef(Def, MI, Def->getOperand(1).getReg()) || - !RDA->hasSameReachingDef(Def, MI, Def->getOperand(2).getReg())) + NewOpcode = VCMPOpcodeToVPT(CmpMI->getOpcode()); + if (NewOpcode == 0) return nullptr; - return Def; + // Search forward from CmpMI to MI, checking if either register was def'd + if (registerDefinedBetween(CmpMI->getOperand(1).getReg(), std::next(CmpMI), + MI, TRI)) + return nullptr; + if (registerDefinedBetween(CmpMI->getOperand(2).getReg(), std::next(CmpMI), + MI, TRI)) + return nullptr; + return &*CmpMI; } bool MVEVPTBlock::InsertVPTBlocks(MachineBasicBlock &Block) { @@ -228,7 +230,7 @@ bool MVEVPTBlock::InsertVPTBlocks(MachineBasicBlock &Block) { // a VPST directly MachineInstrBuilder MIBuilder; unsigned NewOpcode; - MachineInstr *VCMP = findVCMPToFoldIntoVPST(MI, RDA, NewOpcode); + MachineInstr *VCMP = findVCMPToFoldIntoVPST(MI, TRI, NewOpcode); if (VCMP) { LLVM_DEBUG(dbgs() << " folding VCMP into VPST: "; VCMP->dump()); MIBuilder = BuildMI(Block, MI, dl, TII->get(NewOpcode)); @@ -258,7 +260,7 @@ bool MVEVPTBlock::runOnMachineFunction(MachineFunction &Fn) { return false; TII = static_cast(STI.getInstrInfo()); - RDA = &getAnalysis(); + TRI = STI.getRegisterInfo(); LLVM_DEBUG(dbgs() << "********** ARM MVE VPT BLOCKS **********\n" << "********** Function: " << Fn.getName() << '\n'); diff --git a/llvm/test/CodeGen/ARM/O3-pipeline.ll b/llvm/test/CodeGen/ARM/O3-pipeline.ll index 3e9431403af3fb..4188ce759eb9c8 100644 --- a/llvm/test/CodeGen/ARM/O3-pipeline.ll +++ b/llvm/test/CodeGen/ARM/O3-pipeline.ll @@ -144,7 +144,6 @@ ; CHECK-NEXT: Machine Natural Loop Construction ; CHECK-NEXT: Machine Block Frequency Analysis ; CHECK-NEXT: If Converter -; CHECK-NEXT: ReachingDefAnalysis ; CHECK-NEXT: MVE VPT block insertion pass ; CHECK-NEXT: Thumb IT blocks insertion pass ; CHECK-NEXT: MachineDominator Tree Construction