1
- // ===- RISCVFoldMasks .cpp - MI Vector Pseudo Mask Peepholes - --------------===//
1
+ // ===- RISCVVectorPeephole .cpp - MI Vector Pseudo Peepholes --------------===//
2
2
//
3
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
5
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
6
//
7
7
// ===---------------------------------------------------------------------===//
8
8
//
9
- // This pass performs various peephole optimisations that fold masks into vector
10
- // pseudo instructions after instruction selection.
9
+ // This pass performs various vector pseudo peephole optimisations after
10
+ // instruction selection.
11
11
//
12
- // Currently it converts
12
+ // Currently it converts vmerge.vvm to vmv.v.v
13
13
// PseudoVMERGE_VVM %false, %false, %true, %allonesmask, %vl, %sew
14
14
// ->
15
15
// PseudoVMV_V_V %false, %true, %vl, %sew
16
16
//
17
+ // And masked pseudos to unmasked pseudos
18
+ // PseudoVADD_V_V_MASK %passthru, %a, %b, %allonesmask, %vl, sew, policy
19
+ // ->
20
+ // PseudoVADD_V_V %passthru %a, %b, %vl, sew, policy
21
+ //
17
22
// It also converts AVLs to VLMAX where possible
18
23
// %vl = VLENB * something
19
- // PseudoVADD_V_V %a, %b, %vl
24
+ // PseudoVADD_V_V %passthru, % a, %b, %vl, sew, policy
20
25
// ->
21
- // PseudoVADD_V_V %a, %b, -1
26
+ // PseudoVADD_V_V %passthru, % a, %b, -1, sew, policy
22
27
//
23
28
// ===---------------------------------------------------------------------===//
24
29
32
37
33
38
using namespace llvm ;
34
39
35
- #define DEBUG_TYPE " riscv-fold-masks "
40
+ #define DEBUG_TYPE " riscv-vector-peephole "
36
41
37
42
namespace {
38
43
39
- class RISCVFoldMasks : public MachineFunctionPass {
44
+ class RISCVVectorPeephole : public MachineFunctionPass {
40
45
public:
41
46
static char ID;
42
47
const TargetInstrInfo *TII;
43
48
MachineRegisterInfo *MRI;
44
49
const TargetRegisterInfo *TRI;
45
- RISCVFoldMasks () : MachineFunctionPass(ID) {}
50
+ RISCVVectorPeephole () : MachineFunctionPass(ID) {}
46
51
47
52
bool runOnMachineFunction (MachineFunction &MF) override ;
48
53
MachineFunctionProperties getRequiredProperties () const override {
@@ -65,13 +70,14 @@ class RISCVFoldMasks : public MachineFunctionPass {
65
70
66
71
} // namespace
67
72
68
- char RISCVFoldMasks ::ID = 0 ;
73
+ char RISCVVectorPeephole ::ID = 0 ;
69
74
70
- INITIALIZE_PASS (RISCVFoldMasks, DEBUG_TYPE, " RISC-V Fold Masks" , false , false )
75
+ INITIALIZE_PASS (RISCVVectorPeephole, DEBUG_TYPE, " RISC-V Fold Masks" , false ,
76
+ false )
71
77
72
78
// If an AVL is a VLENB that's possibly scaled to be equal to VLMAX, convert it
73
79
// to the VLMAX sentinel value.
74
- bool RISCVFoldMasks ::convertToVLMAX(MachineInstr &MI) const {
80
+ bool RISCVVectorPeephole ::convertToVLMAX(MachineInstr &MI) const {
75
81
if (!RISCVII::hasVLOp (MI.getDesc ().TSFlags ) ||
76
82
!RISCVII::hasSEWOp (MI.getDesc ().TSFlags ))
77
83
return false ;
@@ -119,7 +125,7 @@ bool RISCVFoldMasks::convertToVLMAX(MachineInstr &MI) const {
119
125
return true ;
120
126
}
121
127
122
- bool RISCVFoldMasks ::isAllOnesMask (const MachineInstr *MaskDef) const {
128
+ bool RISCVVectorPeephole ::isAllOnesMask (const MachineInstr *MaskDef) const {
123
129
assert (MaskDef && MaskDef->isCopy () &&
124
130
MaskDef->getOperand (0 ).getReg () == RISCV::V0);
125
131
Register SrcReg = TRI->lookThruCopyLike (MaskDef->getOperand (1 ).getReg (), MRI);
@@ -148,7 +154,7 @@ bool RISCVFoldMasks::isAllOnesMask(const MachineInstr *MaskDef) const {
148
154
149
155
// Transform (VMERGE_VVM_<LMUL> false, false, true, allones, vl, sew) to
150
156
// (VMV_V_V_<LMUL> false, true, vl, sew). It may decrease uses of VMSET.
151
- bool RISCVFoldMasks ::convertVMergeToVMv (MachineInstr &MI) const {
157
+ bool RISCVVectorPeephole ::convertVMergeToVMv (MachineInstr &MI) const {
152
158
#define CASE_VMERGE_TO_VMV (lmul ) \
153
159
case RISCV::PseudoVMERGE_VVM_##lmul: \
154
160
NewOpc = RISCV::PseudoVMV_V_V_##lmul; \
@@ -191,7 +197,7 @@ bool RISCVFoldMasks::convertVMergeToVMv(MachineInstr &MI) const {
191
197
return true ;
192
198
}
193
199
194
- bool RISCVFoldMasks ::convertToUnmasked (MachineInstr &MI) const {
200
+ bool RISCVVectorPeephole ::convertToUnmasked (MachineInstr &MI) const {
195
201
const RISCV::RISCVMaskedPseudoInfo *I =
196
202
RISCV::getMaskedPseudoInfo (MI.getOpcode ());
197
203
if (!I)
@@ -235,7 +241,7 @@ bool RISCVFoldMasks::convertToUnmasked(MachineInstr &MI) const {
235
241
return true ;
236
242
}
237
243
238
- bool RISCVFoldMasks ::runOnMachineFunction (MachineFunction &MF) {
244
+ bool RISCVVectorPeephole ::runOnMachineFunction (MachineFunction &MF) {
239
245
if (skipFunction (MF.getFunction ()))
240
246
return false ;
241
247
@@ -279,4 +285,6 @@ bool RISCVFoldMasks::runOnMachineFunction(MachineFunction &MF) {
279
285
return Changed;
280
286
}
281
287
282
- FunctionPass *llvm::createRISCVFoldMasksPass () { return new RISCVFoldMasks (); }
288
+ FunctionPass *llvm::createRISCVVectorPeepholePass () {
289
+ return new RISCVVectorPeephole ();
290
+ }
0 commit comments