[llvm] [RISCV] Move Machine Copy Propagation Pass before Branch relaxation pass (PR #97261)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 1 00:23:15 PDT 2024


https://github.com/Yunzezhu94 created https://github.com/llvm/llvm-project/pull/97261

Machine Copy Propagation Pass may enlarge branch relaxation distance by breaking generation of compressed insts. This commit moves Machine Copy Propagation Pass before Branch relaxation pass so the results of Branch relaxation pass won't be affected by Machine Copy Propagation Pass.

>From ee4951415ce08a38707294f4676f1f2538c29299 Mon Sep 17 00:00:00 2001
From: Yunze Zhu <yunzezhu at linux.alibaba.com>
Date: Mon, 1 Jul 2024 15:08:35 +0800
Subject: [PATCH] [RISCV] Move Machine Copy Propagation Pass before Branch
 relaxation pass

Machine Copy Propagation Pass may enlarge branch relaxation distance by breaking
generation of compressed insts. This commit moves Machine Copy Propagation Pass
before Branch relaxation pass so the results of Branch relaxation pass won't be
affected by Machine Copy Propagation Pass.
---
 llvm/lib/Target/RISCV/RISCVTargetMachine.cpp | 6 +++---
 llvm/test/CodeGen/RISCV/O3-pipeline.ll       | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
index 35d0b3408d09f..100afafb53c62 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -497,9 +497,6 @@ void RISCVPassConfig::addPreSched2() {
 }
 
 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)
@@ -508,6 +505,9 @@ void RISCVPassConfig::addPreEmitPass() {
   if (TM->getOptLevel() >= CodeGenOptLevel::Default &&
       EnableRISCVCopyPropagation)
     addPass(createMachineCopyPropagationPass(true));
+    
+  addPass(&BranchRelaxationPassID);
+  addPass(createRISCVMakeCompressibleOptPass());
 }
 
 void RISCVPassConfig::addPreEmitPass2() {
diff --git a/llvm/test/CodeGen/RISCV/O3-pipeline.ll b/llvm/test/CodeGen/RISCV/O3-pipeline.ll
index 1eee62e883cf6..3611d92826235 100644
--- a/llvm/test/CodeGen/RISCV/O3-pipeline.ll
+++ b/llvm/test/CodeGen/RISCV/O3-pipeline.ll
@@ -182,9 +182,9 @@
 ; CHECK-NEXT:       Insert fentry calls
 ; CHECK-NEXT:       Insert XRay ops
 ; CHECK-NEXT:       Implement the 'patchable-function' attribute
+; CHECK-NEXT:       Machine Copy Propagation Pass
 ; CHECK-NEXT:       Branch relaxation pass
 ; CHECK-NEXT:       RISC-V 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



More information about the llvm-commits mailing list