Skip to content

Commit 7c95925

Browse files
author
Jessica Paquette
committedJul 10, 2019
[GlobalISel][AArch64] Use getOpcodeDef instead of findMIFromReg
Some minor cleanup. This function in Utils does the same thing as `findMIFromReg`. It also looks through copies, which `findMIFromReg` didn't. Delete `findMIFromReg` and use `getOpcodeDef` instead. This only happens in `tryOptVectorDup` right now. Update opt-shuffle-splat to show that we can look through the copies now, too. Differential Revision: https://reviews.llvm.org/D64520 llvm-svn: 365684
1 parent 3132968 commit 7c95925

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed
 

‎llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,6 @@ class AArch64InstructionSelector : public InstructionSelector {
190190
unsigned char OpFlags) const;
191191

192192
// Optimization methods.
193-
194-
// Helper function to check if a reg def is an MI with a given opcode and
195-
// returns it if so.
196-
MachineInstr *findMIFromReg(unsigned Reg, unsigned Opc,
197-
MachineIRBuilder &MIB) const {
198-
auto *Def = MIB.getMRI()->getVRegDef(Reg);
199-
if (!Def || Def->getOpcode() != Opc)
200-
return nullptr;
201-
return Def;
202-
}
203-
204193
bool tryOptVectorShuffle(MachineInstr &I) const;
205194
bool tryOptVectorDup(MachineInstr &MI) const;
206195
bool tryOptSelect(MachineInstr &MI) const;
@@ -3325,12 +3314,12 @@ bool AArch64InstructionSelector::tryOptVectorDup(MachineInstr &I) const {
33253314

33263315
// Begin matching the insert.
33273316
auto *InsMI =
3328-
findMIFromReg(I.getOperand(1).getReg(), G_INSERT_VECTOR_ELT, MIB);
3317+
getOpcodeDef(G_INSERT_VECTOR_ELT, I.getOperand(1).getReg(), MRI);
33293318
if (!InsMI)
33303319
return false;
33313320
// Match the undef vector operand.
33323321
auto *UndefMI =
3333-
findMIFromReg(InsMI->getOperand(1).getReg(), G_IMPLICIT_DEF, MIB);
3322+
getOpcodeDef(G_IMPLICIT_DEF, InsMI->getOperand(1).getReg(), MRI);
33343323
if (!UndefMI)
33353324
return false;
33363325
// Match the scalar being splatted.
@@ -3342,7 +3331,7 @@ bool AArch64InstructionSelector::tryOptVectorDup(MachineInstr &I) const {
33423331
return false;
33433332

33443333
// The shuffle's second operand doesn't matter if the mask is all zero.
3345-
auto *ZeroVec = findMIFromReg(I.getOperand(3).getReg(), G_BUILD_VECTOR, MIB);
3334+
auto *ZeroVec = getOpcodeDef(G_BUILD_VECTOR, I.getOperand(3).getReg(), MRI);
33463335
if (!ZeroVec)
33473336
return false;
33483337
int64_t Zero = 0;

‎llvm/test/CodeGen/AArch64/GlobalISel/opt-shuffle-splat.mir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,25 @@ body: |
108108
RET_ReallyLR implicit $q0
109109
110110
...
111+
---
112+
name: splat_2xf64_copies
113+
alignment: 2
114+
legalized: true
115+
regBankSelected: true
116+
tracksRegLiveness: true
117+
body: |
118+
bb.1.entry:
119+
liveins: $d0
120+
121+
; This test is exactly the same as splat_2xf64, except it adds two copies.
122+
; These copies shouldn't get in the way of matching the dup pattern.
123+
%0:fpr(s64) = COPY $d0
124+
%2:fpr(<2 x s64>) = G_IMPLICIT_DEF
125+
%6:fpr(<2 x s64>) = COPY %2
126+
%3:gpr(s32) = G_CONSTANT i32 0
127+
%5:fpr(<2 x s32>) = G_BUILD_VECTOR %3(s32), %3(s32)
128+
%1:fpr(<2 x s64>) = G_INSERT_VECTOR_ELT %6, %0(s64), %3(s32)
129+
%7:fpr(<2 x s64>) = COPY %1
130+
%4:fpr(<2 x s64>) = G_SHUFFLE_VECTOR %7(<2 x s64>), %2, %5(<2 x s32>)
131+
$q0 = COPY %4(<2 x s64>)
132+
RET_ReallyLR implicit $q0

0 commit comments

Comments
 (0)
Please sign in to comment.