Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ extern char &SIShrinkInstructionsLegacyID;
void initializeSIFixSGPRCopiesLegacyPass(PassRegistry &);
extern char &SIFixSGPRCopiesLegacyID;

void initializeSIFixVGPRCopiesPass(PassRegistry &);
void initializeSIFixVGPRCopiesLegacyPass(PassRegistry &);
extern char &SIFixVGPRCopiesID;

void initializeSILowerWWMCopiesPass(PassRegistry &);
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ FUNCTION_PASS_WITH_PARAMS(
MACHINE_FUNCTION_PASS("amdgpu-isel", AMDGPUISelDAGToDAGPass(*this))
MACHINE_FUNCTION_PASS("si-fix-sgpr-copies", SIFixSGPRCopiesPass())
MACHINE_FUNCTION_PASS("si-i1-copies", SILowerI1CopiesPass())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this patch. This option is placed wrongly. Should have a post patch to sink it down.

MACHINE_FUNCTION_PASS("si-fix-vgpr-copies", SIFixVGPRCopiesPass())
MACHINE_FUNCTION_PASS("si-fold-operands", SIFoldOperandsPass());
MACHINE_FUNCTION_PASS("gcn-dpp-combine", GCNDPPCombinePass())
MACHINE_FUNCTION_PASS("si-load-store-opt", SILoadStoreOptimizerPass())
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "R600.h"
#include "R600TargetMachine.h"
#include "SIFixSGPRCopies.h"
#include "SIFixVGPRCopies.h"
#include "SIFoldOperands.h"
#include "SILoadStoreOptimizer.h"
#include "SILowerControlFlow.h"
Expand Down Expand Up @@ -486,7 +487,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
initializeAMDGPUMarkLastScratchLoadPass(*PR);
initializeSILowerSGPRSpillsLegacyPass(*PR);
initializeSIFixSGPRCopiesLegacyPass(*PR);
initializeSIFixVGPRCopiesPass(*PR);
initializeSIFixVGPRCopiesLegacyPass(*PR);
initializeSIFoldOperandsLegacyPass(*PR);
initializeSIPeepholeSDWALegacyPass(*PR);
initializeSIShrinkInstructionsLegacyPass(*PR);
Expand Down Expand Up @@ -2107,7 +2108,7 @@ void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
}

void AMDGPUCodeGenPassBuilder::addPostRegAlloc(AddMachinePass &addPass) const {
// addPass(SIFixVGPRCopiesID);
addPass(SIFixVGPRCopiesPass());
if (TM.getOptLevel() > CodeGenOptLevel::None)
addPass(SIOptimizeExecMaskingPass());
Base::addPostRegAlloc(addPass);
Expand Down
32 changes: 24 additions & 8 deletions llvm/lib/Target/AMDGPU/SIFixVGPRCopies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
///
//===----------------------------------------------------------------------===//

#include "SIFixVGPRCopies.h"
#include "AMDGPU.h"
#include "GCNSubtarget.h"
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
Expand All @@ -22,13 +23,12 @@ using namespace llvm;

namespace {

class SIFixVGPRCopies : public MachineFunctionPass {
class SIFixVGPRCopiesLegacy : public MachineFunctionPass {
public:
static char ID;

public:
SIFixVGPRCopies() : MachineFunctionPass(ID) {
initializeSIFixVGPRCopiesPass(*PassRegistry::getPassRegistry());
SIFixVGPRCopiesLegacy() : MachineFunctionPass(ID) {
initializeSIFixVGPRCopiesLegacyPass(*PassRegistry::getPassRegistry());
}

void getAnalysisUsage(AnalysisUsage &AU) const override {
Expand All @@ -41,15 +41,31 @@ class SIFixVGPRCopies : public MachineFunctionPass {
StringRef getPassName() const override { return "SI Fix VGPR copies"; }
};

class SIFixVGPRCopies {
public:
bool run(MachineFunction &MF);
};

} // End anonymous namespace.

INITIALIZE_PASS(SIFixVGPRCopies, DEBUG_TYPE, "SI Fix VGPR copies", false, false)
INITIALIZE_PASS(SIFixVGPRCopiesLegacy, DEBUG_TYPE, "SI Fix VGPR copies", false,
false)

char SIFixVGPRCopies::ID = 0;
char SIFixVGPRCopiesLegacy::ID = 0;

char &llvm::SIFixVGPRCopiesID = SIFixVGPRCopies::ID;
char &llvm::SIFixVGPRCopiesID = SIFixVGPRCopiesLegacy::ID;

PreservedAnalyses SIFixVGPRCopiesPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &) {
SIFixVGPRCopies().run(MF);
return PreservedAnalyses::all();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it OK to return all unconditionally?

Copy link
Contributor

@arsenm arsenm Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the legacy one does setPreservesAll, so this is just replicating that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. (s/DAG/legacy/?)

}

bool SIFixVGPRCopiesLegacy::runOnMachineFunction(MachineFunction &MF) {
return SIFixVGPRCopies().run(MF);
}

bool SIFixVGPRCopies::runOnMachineFunction(MachineFunction &MF) {
bool SIFixVGPRCopies::run(MachineFunction &MF) {
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
const SIRegisterInfo *TRI = ST.getRegisterInfo();
const SIInstrInfo *TII = ST.getInstrInfo();
Expand Down
22 changes: 22 additions & 0 deletions llvm/lib/Target/AMDGPU/SIFixVGPRCopies.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===- SIFixVGPRCopies.h ----------------------------------------*- C++- *-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIB_TARGET_AMDGPU_SIFIXVGPRCOPIES_H
#define LLVM_LIB_TARGET_AMDGPU_SIFIXVGPRCOPIES_H

#include "llvm/CodeGen/MachinePassManager.h"

namespace llvm {
class SIFixVGPRCopiesPass : public PassInfoMixin<SIFixVGPRCopiesPass> {
public:
PreservedAnalyses run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM);
};
} // namespace llvm

#endif // LLVM_LIB_TARGET_AMDGPU_SIFIXVGPRCOPIES_H
2 changes: 2 additions & 0 deletions llvm/test/CodeGen/AMDGPU/fix-vgpr-copies.mir
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# RUN: llc -mtriple=amdgcn -start-after=greedy -disable-copyprop -stop-after=si-optimize-exec-masking -o - %s | FileCheck %s
# RUN: llc -mtriple=amdgcn -passes=si-fix-vgpr-copies,si-optimize-exec-masking -o - %s | FileCheck %s

# Check that we first do all vector instructions and only then change exec
# CHECK-DAG: COPY $vgpr10_vgpr11
# CHECK-DAG: COPY $vgpr12_vgpr13
Expand Down
Loading