[PATCH] D146192: [RISCV] Add an empty block after outlined MBB
Wang Pengcheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 15 21:06:53 PDT 2023
pcwang-thead created this revision.
pcwang-thead added reviewers: asb, craig.topper, reames.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
pcwang-thead requested review of this revision.
Herald added subscribers: llvm-commits, eopXD, MaskRay.
Herald added a project: LLVM.
So that MCP won't delete any copy instructions where a register is
set that is intended to be live-out, since MCP assumes that all the
defs are live-out conservatively.
This is a fix for D146037 <https://reviews.llvm.org/D146037>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D146192
Files:
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
llvm/test/CodeGen/RISCV/O3-pipeline.ll
llvm/test/CodeGen/RISCV/machine-outliner-and-machine-copy-propagation.ll
Index: llvm/test/CodeGen/RISCV/machine-outliner-and-machine-copy-propagation.ll
===================================================================
--- llvm/test/CodeGen/RISCV/machine-outliner-and-machine-copy-propagation.ll
+++ llvm/test/CodeGen/RISCV/machine-outliner-and-machine-copy-propagation.ll
@@ -196,3 +196,4 @@
; RV64I-NEXT: lui a0, 524288
; RV64I-NEXT: mv a1, s0
; RV64I-NEXT: jr t0
+; RV64I-NEXT: # %bb.1:
Index: llvm/test/CodeGen/RISCV/O3-pipeline.ll
===================================================================
--- llvm/test/CodeGen/RISCV/O3-pipeline.ll
+++ llvm/test/CodeGen/RISCV/O3-pipeline.ll
@@ -166,7 +166,6 @@
; CHECK-NEXT: Implement the 'patchable-function' attribute
; CHECK-NEXT: Branch relaxation pass
; CHECK-NEXT: RISCV Make Compressible
-; CHECK-NEXT: Machine Copy Propagation Pass
; CHECK-NEXT: Contiguously Lay Out Funclets
; CHECK-NEXT: StackMap Liveness Analysis
; CHECK-NEXT: Live DEBUG_VALUE analysis
@@ -177,6 +176,7 @@
; CHECK-NEXT: Machine Optimization Remark Emitter
; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: RISCV pseudo instruction expansion pass
+; CHECK-NEXT: Machine Copy Propagation Pass
; CHECK-NEXT: RISCV atomic pseudo instruction expansion pass
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
; CHECK-NEXT: Machine Optimization Remark Emitter
Index: llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -337,19 +337,16 @@
void RISCVPassConfig::addPreEmitPass() {
addPass(&BranchRelaxationPassID);
addPass(createRISCVMakeCompressibleOptPass());
-
- // TODO: It would potentially be better to schedule copy propagation after
- // expanding pseudos (in addPreEmitPass2). However, performing copy
- // propagation after the machine outliner (which runs after addPreEmitPass)
- // currently leads to incorrect code-gen, where copies to registers within
- // outlined functions are removed erroneously.
- if (TM->getOptLevel() >= CodeGenOpt::Default && EnableRISCVCopyPropagation)
- addPass(createMachineCopyPropagationPass(true));
}
void RISCVPassConfig::addPreEmitPass2() {
addPass(createRISCVExpandPseudoPass());
+ // Do the copy propagation after expanding pseudos because we may produce some
+ // MVs when expanding.
+ if (TM->getOptLevel() >= CodeGenOpt::Default && EnableRISCVCopyPropagation)
+ addPass(createMachineCopyPropagationPass(true));
+
// Schedule the expansion of AMOs at the last possible moment, avoiding the
// possibility for other passes to break the requirements for forward
// progress in the LR/SC block.
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -2011,6 +2011,13 @@
MachineBasicBlock &MBB, MachineFunction &MF,
const outliner::OutlinedFunction &OF) const {
+ // FIXME: Add an empty successor so that MCP won't delete any copy
+ // instructions where a register is set that is intended to be live-out, since
+ // MCP assumes that all the defs are live-out conservatively.
+ MachineBasicBlock &EmptyMBB = *MF.CreateMachineBasicBlock();
+ MF.insert(MF.end(), &EmptyMBB);
+ MBB.addSuccessorWithoutProb(&EmptyMBB);
+
// Strip out any CFI instructions
bool Changed = true;
while (Changed) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146192.505697.patch
Type: text/x-patch
Size: 3584 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230316/f6a05a05/attachment.bin>
More information about the llvm-commits
mailing list