Skip to content

Commit e91420e

Browse files
author
Sjoerd Meijer
committed
Revert "[ARM][MVE] findVCMPToFoldIntoVPS. NFC."
This reverts commit 9468e33. There's a test that doesn't like this change. The RDA analysis gets invalided by changes in the block, which is not taken into account. Revert while I work on a fix for this.
1 parent 228c740 commit e91420e

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

llvm/lib/Target/ARM/MVEVPTBlockPass.cpp

+30-28
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"
2625
#include "llvm/IR/DebugLoc.h"
2726
#include "llvm/MC/MCInstrDesc.h"
27+
#include "llvm/MC/MCRegisterInfo.h"
2828
#include "llvm/Support/Debug.h"
2929
#include <cassert>
3030
#include <new>
@@ -37,21 +37,16 @@ namespace {
3737
class MVEVPTBlock : public MachineFunctionPass {
3838
public:
3939
static char ID;
40+
const Thumb2InstrInfo *TII;
41+
const TargetRegisterInfo *TRI;
4042

4143
MVEVPTBlock() : MachineFunctionPass(ID) {}
4244

4345
bool runOnMachineFunction(MachineFunction &Fn) override;
4446

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

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

6156
private:
6257
bool InsertVPTBlocks(MachineBasicBlock &MBB);
63-
64-
const Thumb2InstrInfo *TII = nullptr;
65-
ReachingDefAnalysis *RDA = nullptr;
6658
};
6759

6860
char MVEVPTBlock::ID = 0;
@@ -142,25 +134,35 @@ static unsigned VCMPOpcodeToVPT(unsigned Opcode) {
142134
}
143135
}
144136

145-
static MachineInstr *findVCMPToFoldIntoVPST(MachineInstr *MI,
146-
ReachingDefAnalysis *RDA,
137+
static MachineInstr *findVCMPToFoldIntoVPST(MachineBasicBlock::iterator MI,
138+
const TargetRegisterInfo *TRI,
147139
unsigned &NewOpcode) {
148-
// First, search backwards to the instruction that defines VPR
149-
auto *Def = RDA->getReachingMIDef(MI, ARM::VPR);
150-
if (!Def)
151-
return nullptr;
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+
}
152151

153-
// Now check that Def is a VCMP
154-
if (!(NewOpcode = VCMPOpcodeToVPT(Def->getOpcode())))
152+
if (CmpMI == MI)
155153
return nullptr;
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()))
154+
NewOpcode = VCMPOpcodeToVPT(CmpMI->getOpcode());
155+
if (NewOpcode == 0)
161156
return nullptr;
162157

163-
return Def;
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))
161+
return nullptr;
162+
if (registerDefinedBetween(CmpMI->getOperand(2).getReg(), std::next(CmpMI),
163+
MI, TRI))
164+
return nullptr;
165+
return &*CmpMI;
164166
}
165167

166168
bool MVEVPTBlock::InsertVPTBlocks(MachineBasicBlock &Block) {
@@ -228,7 +230,7 @@ bool MVEVPTBlock::InsertVPTBlocks(MachineBasicBlock &Block) {
228230
// a VPST directly
229231
MachineInstrBuilder MIBuilder;
230232
unsigned NewOpcode;
231-
MachineInstr *VCMP = findVCMPToFoldIntoVPST(MI, RDA, NewOpcode);
233+
MachineInstr *VCMP = findVCMPToFoldIntoVPST(MI, TRI, NewOpcode);
232234
if (VCMP) {
233235
LLVM_DEBUG(dbgs() << " folding VCMP into VPST: "; VCMP->dump());
234236
MIBuilder = BuildMI(Block, MI, dl, TII->get(NewOpcode));
@@ -258,7 +260,7 @@ bool MVEVPTBlock::runOnMachineFunction(MachineFunction &Fn) {
258260
return false;
259261

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

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

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

-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
; CHECK-NEXT: Machine Natural Loop Construction
145145
; CHECK-NEXT: Machine Block Frequency Analysis
146146
; CHECK-NEXT: If Converter
147-
; CHECK-NEXT: ReachingDefAnalysis
148147
; CHECK-NEXT: MVE VPT block insertion pass
149148
; CHECK-NEXT: Thumb IT blocks insertion pass
150149
; CHECK-NEXT: MachineDominator Tree Construction

0 commit comments

Comments
 (0)