Skip to content

Commit 9468e33

Browse files
author
Sjoerd Meijer
committed
[ARM][MVE] findVCMPToFoldIntoVPS. NFC.
This adds ReachingDefAnalysis (RDA) to the VPTBlock pass, so that we can reimplement findVCMPToFoldIntoVPS with just a few calls to RDA. Differential Revision: https://reviews.llvm.org/D71330
1 parent dbc5acf commit 9468e33

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

llvm/lib/Target/ARM/MVEVPTBlockPass.cpp

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
#include "llvm/CodeGen/MachineInstrBuilder.h"
2323
#include "llvm/CodeGen/MachineInstrBundle.h"
2424
#include "llvm/CodeGen/MachineOperand.h"
25+
#include "llvm/CodeGen/ReachingDefAnalysis.h"
2526
#include "llvm/IR/DebugLoc.h"
2627
#include "llvm/MC/MCInstrDesc.h"
27-
#include "llvm/MC/MCRegisterInfo.h"
2828
#include "llvm/Support/Debug.h"
2929
#include <cassert>
3030
#include <new>
@@ -37,16 +37,21 @@ namespace {
3737
class MVEVPTBlock : public MachineFunctionPass {
3838
public:
3939
static char ID;
40-
const Thumb2InstrInfo *TII;
41-
const TargetRegisterInfo *TRI;
4240

4341
MVEVPTBlock() : MachineFunctionPass(ID) {}
4442

4543
bool runOnMachineFunction(MachineFunction &Fn) override;
4644

45+
void getAnalysisUsage(AnalysisUsage &AU) const override {
46+
AU.setPreservesCFG();
47+
AU.addRequired<ReachingDefAnalysis>();
48+
MachineFunctionPass::getAnalysisUsage(AU);
49+
}
50+
4751
MachineFunctionProperties getRequiredProperties() const override {
4852
return MachineFunctionProperties().set(
49-
MachineFunctionProperties::Property::NoVRegs);
53+
MachineFunctionProperties::Property::NoVRegs).set(
54+
MachineFunctionProperties::Property::TracksLiveness);
5055
}
5156

5257
StringRef getPassName() const override {
@@ -55,6 +60,9 @@ namespace {
5560

5661
private:
5762
bool InsertVPTBlocks(MachineBasicBlock &MBB);
63+
64+
const Thumb2InstrInfo *TII = nullptr;
65+
ReachingDefAnalysis *RDA = nullptr;
5866
};
5967

6068
char MVEVPTBlock::ID = 0;
@@ -134,35 +142,25 @@ static unsigned VCMPOpcodeToVPT(unsigned Opcode) {
134142
}
135143
}
136144

137-
static MachineInstr *findVCMPToFoldIntoVPST(MachineBasicBlock::iterator MI,
138-
const TargetRegisterInfo *TRI,
145+
static MachineInstr *findVCMPToFoldIntoVPST(MachineInstr *MI,
146+
ReachingDefAnalysis *RDA,
139147
unsigned &NewOpcode) {
140-
// Search backwards to the instruction that defines VPR. This may or not
141-
// be a VCMP, we check that after this loop. If we find another instruction
142-
// that reads cpsr, we return nullptr.
143-
MachineBasicBlock::iterator CmpMI = MI;
144-
while (CmpMI != MI->getParent()->begin()) {
145-
--CmpMI;
146-
if (CmpMI->modifiesRegister(ARM::VPR, TRI))
147-
break;
148-
if (CmpMI->readsRegister(ARM::VPR, TRI))
149-
break;
150-
}
151-
152-
if (CmpMI == MI)
153-
return nullptr;
154-
NewOpcode = VCMPOpcodeToVPT(CmpMI->getOpcode());
155-
if (NewOpcode == 0)
148+
// First, search backwards to the instruction that defines VPR
149+
auto *Def = RDA->getReachingMIDef(MI, ARM::VPR);
150+
if (!Def)
156151
return nullptr;
157152

158-
// Search forward from CmpMI to MI, checking if either register was def'd
159-
if (registerDefinedBetween(CmpMI->getOperand(1).getReg(), std::next(CmpMI),
160-
MI, TRI))
153+
// Now check that Def is a VCMP
154+
if (!(NewOpcode = VCMPOpcodeToVPT(Def->getOpcode())))
161155
return nullptr;
162-
if (registerDefinedBetween(CmpMI->getOperand(2).getReg(), std::next(CmpMI),
163-
MI, TRI))
156+
157+
// Check that Def's operands are not defined between the VCMP and MI, i.e.
158+
// check that they have the same reaching def.
159+
if (!RDA->hasSameReachingDef(Def, MI, Def->getOperand(1).getReg()) ||
160+
!RDA->hasSameReachingDef(Def, MI, Def->getOperand(2).getReg()))
164161
return nullptr;
165-
return &*CmpMI;
162+
163+
return Def;
166164
}
167165

168166
bool MVEVPTBlock::InsertVPTBlocks(MachineBasicBlock &Block) {
@@ -230,7 +228,7 @@ bool MVEVPTBlock::InsertVPTBlocks(MachineBasicBlock &Block) {
230228
// a VPST directly
231229
MachineInstrBuilder MIBuilder;
232230
unsigned NewOpcode;
233-
MachineInstr *VCMP = findVCMPToFoldIntoVPST(MI, TRI, NewOpcode);
231+
MachineInstr *VCMP = findVCMPToFoldIntoVPST(MI, RDA, NewOpcode);
234232
if (VCMP) {
235233
LLVM_DEBUG(dbgs() << " folding VCMP into VPST: "; VCMP->dump());
236234
MIBuilder = BuildMI(Block, MI, dl, TII->get(NewOpcode));
@@ -260,7 +258,7 @@ bool MVEVPTBlock::runOnMachineFunction(MachineFunction &Fn) {
260258
return false;
261259

262260
TII = static_cast<const Thumb2InstrInfo *>(STI.getInstrInfo());
263-
TRI = STI.getRegisterInfo();
261+
RDA = &getAnalysis<ReachingDefAnalysis>();
264262

265263
LLVM_DEBUG(dbgs() << "********** ARM MVE VPT BLOCKS **********\n"
266264
<< "********** Function: " << Fn.getName() << '\n');

llvm/test/CodeGen/ARM/O3-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
; CHECK-NEXT: Machine Natural Loop Construction
145145
; CHECK-NEXT: Machine Block Frequency Analysis
146146
; CHECK-NEXT: If Converter
147+
; CHECK-NEXT: ReachingDefAnalysis
147148
; CHECK-NEXT: MVE VPT block insertion pass
148149
; CHECK-NEXT: Thumb IT blocks insertion pass
149150
; CHECK-NEXT: MachineDominator Tree Construction

0 commit comments

Comments
 (0)