Skip to content

Commit fdca2c3

Browse files
authored
AMDGPU/NewPM Port GCNDPPCombine to NPM (#105816)
Co-authored-by: Akshat Oke <[email protected]>
1 parent 575be3e commit fdca2c3

File tree

7 files changed

+77
-18
lines changed

7 files changed

+77
-18
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ struct AMDGPULowerBufferFatPointersPass
157157
void initializeAMDGPURewriteOutArgumentsPass(PassRegistry &);
158158
extern char &AMDGPURewriteOutArgumentsID;
159159

160-
void initializeGCNDPPCombinePass(PassRegistry &);
161-
extern char &GCNDPPCombineID;
160+
void initializeGCNDPPCombineLegacyPass(PassRegistry &);
161+
extern char &GCNDPPCombineLegacyID;
162162

163163
void initializeSIFoldOperandsLegacyPass(PassRegistry &);
164164
extern char &SIFoldOperandsLegacyID;

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,5 @@ MACHINE_FUNCTION_PASS("amdgpu-isel", AMDGPUISelDAGToDAGPass(*this))
9898
MACHINE_FUNCTION_PASS("si-fix-sgpr-copies", SIFixSGPRCopiesPass())
9999
MACHINE_FUNCTION_PASS("si-i1-copies", SILowerI1CopiesPass())
100100
MACHINE_FUNCTION_PASS("si-fold-operands", SIFoldOperandsPass());
101+
MACHINE_FUNCTION_PASS("gcn-dpp-combine", GCNDPPCombinePass())
101102
#undef MACHINE_FUNCTION_PASS

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "AMDGPUTargetObjectFile.h"
2929
#include "AMDGPUTargetTransformInfo.h"
3030
#include "AMDGPUUnifyDivergentExitNodes.h"
31+
#include "GCNDPPCombine.h"
3132
#include "GCNIterativeScheduler.h"
3233
#include "GCNSchedStrategy.h"
3334
#include "GCNVOPDUtils.h"
@@ -403,7 +404,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
403404
initializeR600VectorRegMergerPass(*PR);
404405
initializeGlobalISel(*PR);
405406
initializeAMDGPUDAGToDAGISelLegacyPass(*PR);
406-
initializeGCNDPPCombinePass(*PR);
407+
initializeGCNDPPCombineLegacyPass(*PR);
407408
initializeSILowerI1CopiesLegacyPass(*PR);
408409
initializeAMDGPUGlobalISelDivergenceLoweringPass(*PR);
409410
initializeSILowerWWMCopiesPass(*PR);
@@ -1273,7 +1274,7 @@ void GCNPassConfig::addMachineSSAOptimization() {
12731274
// XXX - Can we get away without running DeadMachineInstructionElim again?
12741275
addPass(&SIFoldOperandsLegacyID);
12751276
if (EnableDPPCombine)
1276-
addPass(&GCNDPPCombineID);
1277+
addPass(&GCNDPPCombineLegacyID);
12771278
addPass(&SILoadStoreOptimizerID);
12781279
if (isPassEnabled(EnableSDWAPeephole)) {
12791280
addPass(&SIPeepholeSDWAID);

llvm/lib/Target/AMDGPU/GCNDPPCombine.cpp

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
// The mov_dpp instruction should reside in the same BB as all its uses
3838
//===----------------------------------------------------------------------===//
3939

40+
#include "GCNDPPCombine.h"
4041
#include "AMDGPU.h"
4142
#include "GCNSubtarget.h"
4243
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -51,7 +52,7 @@ STATISTIC(NumDPPMovsCombined, "Number of DPP moves combined.");
5152

5253
namespace {
5354

54-
class GCNDPPCombine : public MachineFunctionPass {
55+
class GCNDPPCombine {
5556
MachineRegisterInfo *MRI;
5657
const SIInstrInfo *TII;
5758
const GCNSubtarget *ST;
@@ -76,12 +77,18 @@ class GCNDPPCombine : public MachineFunctionPass {
7677

7778
bool combineDPPMov(MachineInstr &MI) const;
7879

80+
int getDPPOp(unsigned Op, bool IsShrinkable) const;
81+
bool isShrinkable(MachineInstr &MI) const;
82+
83+
public:
84+
bool run(MachineFunction &MF);
85+
};
86+
87+
class GCNDPPCombineLegacy : public MachineFunctionPass {
7988
public:
8089
static char ID;
8190

82-
GCNDPPCombine() : MachineFunctionPass(ID) {
83-
initializeGCNDPPCombinePass(*PassRegistry::getPassRegistry());
84-
}
91+
GCNDPPCombineLegacy() : MachineFunctionPass(ID) {}
8592

8693
bool runOnMachineFunction(MachineFunction &MF) override;
8794

@@ -96,22 +103,19 @@ class GCNDPPCombine : public MachineFunctionPass {
96103
return MachineFunctionProperties()
97104
.set(MachineFunctionProperties::Property::IsSSA);
98105
}
99-
100-
private:
101-
int getDPPOp(unsigned Op, bool IsShrinkable) const;
102-
bool isShrinkable(MachineInstr &MI) const;
103106
};
104107

105108
} // end anonymous namespace
106109

107-
INITIALIZE_PASS(GCNDPPCombine, DEBUG_TYPE, "GCN DPP Combine", false, false)
110+
INITIALIZE_PASS(GCNDPPCombineLegacy, DEBUG_TYPE, "GCN DPP Combine", false,
111+
false)
108112

109-
char GCNDPPCombine::ID = 0;
113+
char GCNDPPCombineLegacy::ID = 0;
110114

111-
char &llvm::GCNDPPCombineID = GCNDPPCombine::ID;
115+
char &llvm::GCNDPPCombineLegacyID = GCNDPPCombineLegacy::ID;
112116

113117
FunctionPass *llvm::createGCNDPPCombinePass() {
114-
return new GCNDPPCombine();
118+
return new GCNDPPCombineLegacy();
115119
}
116120

117121
bool GCNDPPCombine::isShrinkable(MachineInstr &MI) const {
@@ -749,9 +753,16 @@ bool GCNDPPCombine::combineDPPMov(MachineInstr &MovMI) const {
749753
return !Rollback;
750754
}
751755

752-
bool GCNDPPCombine::runOnMachineFunction(MachineFunction &MF) {
756+
bool GCNDPPCombineLegacy::runOnMachineFunction(MachineFunction &MF) {
757+
if (skipFunction(MF.getFunction()))
758+
return false;
759+
760+
return GCNDPPCombine().run(MF);
761+
}
762+
763+
bool GCNDPPCombine::run(MachineFunction &MF) {
753764
ST = &MF.getSubtarget<GCNSubtarget>();
754-
if (!ST->hasDPP() || skipFunction(MF.getFunction()))
765+
if (!ST->hasDPP())
755766
return false;
756767

757768
MRI = &MF.getRegInfo();
@@ -781,3 +792,19 @@ bool GCNDPPCombine::runOnMachineFunction(MachineFunction &MF) {
781792
}
782793
return Changed;
783794
}
795+
796+
PreservedAnalyses GCNDPPCombinePass::run(MachineFunction &MF,
797+
MachineFunctionAnalysisManager &) {
798+
if (MF.getFunction().hasOptNone())
799+
return PreservedAnalyses::all();
800+
801+
MFPropsModifier _(*this, MF);
802+
803+
bool Changed = GCNDPPCombine().run(MF);
804+
if (!Changed)
805+
return PreservedAnalyses::all();
806+
807+
auto PA = getMachineFunctionPassPreservedAnalyses();
808+
PA.preserveSet<CFGAnalyses>();
809+
return PA;
810+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//=======--- GCNDPPCombine.h - optimization for DPP instructions ---==========//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIB_TARGET_AMDGPU_GCNDPPCOMBINE_H
10+
#define LLVM_LIB_TARGET_AMDGPU_GCNDPPCOMBINE_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
class GCNDPPCombinePass : public PassInfoMixin<GCNDPPCombinePass> {
16+
public:
17+
PreservedAnalyses run(MachineFunction &MF,
18+
MachineFunctionAnalysisManager &MAM);
19+
20+
MachineFunctionProperties getRequiredProperties() {
21+
return MachineFunctionProperties().set(
22+
MachineFunctionProperties::Property::IsSSA);
23+
}
24+
};
25+
26+
} // end namespace llvm
27+
28+
#endif // LLVM_LIB_TARGET_AMDGPU_GCNDPPCOMBINE_H

llvm/test/CodeGen/AMDGPU/dpp_combine.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -run-pass=gcn-dpp-combine -verify-machineinstrs -o - %s | FileCheck %s -check-prefix=GCN
2+
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -passes=gcn-dpp-combine -verify-machineinstrs -o - %s | FileCheck %s -check-prefix=GCN
23

34
---
45
# old is undefined: only combine when masks are fully enabled and

llvm/test/CodeGen/AMDGPU/llvm.amdgcn.cvt.fp8.dpp.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx1200 -verify-machineinstrs -run-pass=gcn-dpp-combine %s -o - | FileCheck -check-prefix=GFX12 %s
3+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1200 -verify-machineinstrs -passes=gcn-dpp-combine %s -o - | FileCheck -check-prefix=GFX12 %s
34

45
---
56
name: test_cvt_f32_bf8_byte0

0 commit comments

Comments
 (0)