Skip to content

Commit 82e8c8b

Browse files
committed
Rename RISCVFoldMasks -> RISCVVectorPeephole
1 parent f25dd71 commit 82e8c8b

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

llvm/lib/Target/RISCV/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ add_llvm_target(RISCVCodeGen
3434
RISCVMakeCompressible.cpp
3535
RISCVExpandAtomicPseudoInsts.cpp
3636
RISCVExpandPseudoInsts.cpp
37-
RISCVFoldMasks.cpp
3837
RISCVFrameLowering.cpp
3938
RISCVGatherScatterLowering.cpp
4039
RISCVInsertVSETVLI.cpp
@@ -55,6 +54,7 @@ add_llvm_target(RISCVCodeGen
5554
RISCVTargetMachine.cpp
5655
RISCVTargetObjectFile.cpp
5756
RISCVTargetTransformInfo.cpp
57+
RISCVVectorPeephole.cpp
5858
GISel/RISCVCallLowering.cpp
5959
GISel/RISCVInstructionSelector.cpp
6060
GISel/RISCVLegalizerInfo.cpp

llvm/lib/Target/RISCV/RISCV.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ void initializeRISCVMakeCompressibleOptPass(PassRegistry &);
4040
FunctionPass *createRISCVGatherScatterLoweringPass();
4141
void initializeRISCVGatherScatterLoweringPass(PassRegistry &);
4242

43-
FunctionPass *createRISCVFoldMasksPass();
44-
void initializeRISCVFoldMasksPass(PassRegistry &);
43+
FunctionPass *createRISCVVectorPeepholePass();
44+
void initializeRISCVVectorPeepholePass(PassRegistry &);
4545

4646
FunctionPass *createRISCVOptWInstrsPass();
4747
void initializeRISCVOptWInstrsPass(PassRegistry &);

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget() {
121121
initializeRISCVOptWInstrsPass(*PR);
122122
initializeRISCVPreRAExpandPseudoPass(*PR);
123123
initializeRISCVExpandPseudoPass(*PR);
124-
initializeRISCVFoldMasksPass(*PR);
124+
initializeRISCVVectorPeepholePass(*PR);
125125
initializeRISCVInsertVSETVLIPass(*PR);
126126
initializeRISCVInsertReadWriteCSRPass(*PR);
127127
initializeRISCVInsertWriteVXRMPass(*PR);
@@ -532,7 +532,7 @@ void RISCVPassConfig::addPreEmitPass2() {
532532
}
533533

534534
void RISCVPassConfig::addMachineSSAOptimization() {
535-
addPass(createRISCVFoldMasksPass());
535+
addPass(createRISCVVectorPeepholePass());
536536

537537
TargetPassConfig::addMachineSSAOptimization();
538538

llvm/lib/Target/RISCV/RISCVFoldMasks.cpp renamed to llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
//===- RISCVFoldMasks.cpp - MI Vector Pseudo Mask Peepholes ---------------===//
1+
//===- RISCVVectorPeephole.cpp - MI Vector Pseudo Peepholes --------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===---------------------------------------------------------------------===//
88
//
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.
1111
//
12-
// Currently it converts
12+
// Currently it converts vmerge.vvm to vmv.v.v
1313
// PseudoVMERGE_VVM %false, %false, %true, %allonesmask, %vl, %sew
1414
// ->
1515
// PseudoVMV_V_V %false, %true, %vl, %sew
1616
//
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+
//
1722
// It also converts AVLs to VLMAX where possible
1823
// %vl = VLENB * something
19-
// PseudoVADD_V_V %a, %b, %vl
24+
// PseudoVADD_V_V %passthru, %a, %b, %vl, sew, policy
2025
// ->
21-
// PseudoVADD_V_V %a, %b, -1
26+
// PseudoVADD_V_V %passthru, %a, %b, -1, sew, policy
2227
//
2328
//===---------------------------------------------------------------------===//
2429

@@ -32,17 +37,17 @@
3237

3338
using namespace llvm;
3439

35-
#define DEBUG_TYPE "riscv-fold-masks"
40+
#define DEBUG_TYPE "riscv-vector-peephole"
3641

3742
namespace {
3843

39-
class RISCVFoldMasks : public MachineFunctionPass {
44+
class RISCVVectorPeephole : public MachineFunctionPass {
4045
public:
4146
static char ID;
4247
const TargetInstrInfo *TII;
4348
MachineRegisterInfo *MRI;
4449
const TargetRegisterInfo *TRI;
45-
RISCVFoldMasks() : MachineFunctionPass(ID) {}
50+
RISCVVectorPeephole() : MachineFunctionPass(ID) {}
4651

4752
bool runOnMachineFunction(MachineFunction &MF) override;
4853
MachineFunctionProperties getRequiredProperties() const override {
@@ -65,13 +70,14 @@ class RISCVFoldMasks : public MachineFunctionPass {
6570

6671
} // namespace
6772

68-
char RISCVFoldMasks::ID = 0;
73+
char RISCVVectorPeephole::ID = 0;
6974

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)
7177

7278
// If an AVL is a VLENB that's possibly scaled to be equal to VLMAX, convert it
7379
// to the VLMAX sentinel value.
74-
bool RISCVFoldMasks::convertToVLMAX(MachineInstr &MI) const {
80+
bool RISCVVectorPeephole::convertToVLMAX(MachineInstr &MI) const {
7581
if (!RISCVII::hasVLOp(MI.getDesc().TSFlags) ||
7682
!RISCVII::hasSEWOp(MI.getDesc().TSFlags))
7783
return false;
@@ -119,7 +125,7 @@ bool RISCVFoldMasks::convertToVLMAX(MachineInstr &MI) const {
119125
return true;
120126
}
121127

122-
bool RISCVFoldMasks::isAllOnesMask(const MachineInstr *MaskDef) const {
128+
bool RISCVVectorPeephole::isAllOnesMask(const MachineInstr *MaskDef) const {
123129
assert(MaskDef && MaskDef->isCopy() &&
124130
MaskDef->getOperand(0).getReg() == RISCV::V0);
125131
Register SrcReg = TRI->lookThruCopyLike(MaskDef->getOperand(1).getReg(), MRI);
@@ -148,7 +154,7 @@ bool RISCVFoldMasks::isAllOnesMask(const MachineInstr *MaskDef) const {
148154

149155
// Transform (VMERGE_VVM_<LMUL> false, false, true, allones, vl, sew) to
150156
// (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 {
152158
#define CASE_VMERGE_TO_VMV(lmul) \
153159
case RISCV::PseudoVMERGE_VVM_##lmul: \
154160
NewOpc = RISCV::PseudoVMV_V_V_##lmul; \
@@ -191,7 +197,7 @@ bool RISCVFoldMasks::convertVMergeToVMv(MachineInstr &MI) const {
191197
return true;
192198
}
193199

194-
bool RISCVFoldMasks::convertToUnmasked(MachineInstr &MI) const {
200+
bool RISCVVectorPeephole::convertToUnmasked(MachineInstr &MI) const {
195201
const RISCV::RISCVMaskedPseudoInfo *I =
196202
RISCV::getMaskedPseudoInfo(MI.getOpcode());
197203
if (!I)
@@ -235,7 +241,7 @@ bool RISCVFoldMasks::convertToUnmasked(MachineInstr &MI) const {
235241
return true;
236242
}
237243

238-
bool RISCVFoldMasks::runOnMachineFunction(MachineFunction &MF) {
244+
bool RISCVVectorPeephole::runOnMachineFunction(MachineFunction &MF) {
239245
if (skipFunction(MF.getFunction()))
240246
return false;
241247

@@ -279,4 +285,6 @@ bool RISCVFoldMasks::runOnMachineFunction(MachineFunction &MF) {
279285
return Changed;
280286
}
281287

282-
FunctionPass *llvm::createRISCVFoldMasksPass() { return new RISCVFoldMasks(); }
288+
FunctionPass *llvm::createRISCVVectorPeepholePass() {
289+
return new RISCVVectorPeephole();
290+
}

llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-to-vmv.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
2-
# RUN: llc %s -o - -mtriple=riscv64 -mattr=+v -run-pass=riscv-fold-masks \
2+
# RUN: llc %s -o - -mtriple=riscv64 -mattr=+v -run-pass=riscv-vector-peephole \
33
# RUN: -verify-machineinstrs | FileCheck %s
44

55
---

0 commit comments

Comments
 (0)