[llvm] b61ff0c - [PowerPC] move ctrloop pass before tail duplication
Chen Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 1 21:34:48 PST 2022
Author: Chen Zheng
Date: 2022-12-02T00:31:00-05:00
New Revision: b61ff0ca76a50e6eb2b110084b690823b94ff77f
URL: https://github.com/llvm/llvm-project/commit/b61ff0ca76a50e6eb2b110084b690823b94ff77f
DIFF: https://github.com/llvm/llvm-project/commit/b61ff0ca76a50e6eb2b110084b690823b94ff77f.diff
LOG: [PowerPC] move ctrloop pass before tail duplication
Tail duplication may modify the loop to a "non-canonical" form
that CTR Loop pass can not recognize. We fixed one issue in D135846.
And we found in some other case, the loop is changed to irreducible form.
It is hard to fix this case in CTR loop pass, instead we reorder the
CTR loop pass before tail duplication pass and just after finalize-isel
pass to avoid any unexpected change to the loop form.
Reviewed By: lkail
Differential Revision: https://reviews.llvm.org/D138265
Added:
Modified:
llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
llvm/test/CodeGen/PowerPC/O3-pipeline.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
index fe396cbfc011..9b28310a3622 100644
--- a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -500,6 +500,11 @@ bool PPCPassConfig::addInstSelector() {
}
void PPCPassConfig::addMachineSSAOptimization() {
+ // Run CTR loops pass before any cfg modification pass to prevent the
+ // canonical form of hardware loop from being destroied.
+ if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
+ addPass(createPPCCTRLoopsPass());
+
// PPCBranchCoalescingPass need to be done before machine sinking
// since it merges empty blocks.
if (EnableBranchCoalescing && getOptLevel() != CodeGenOpt::None)
@@ -540,16 +545,6 @@ void PPCPassConfig::addPreRegAlloc() {
if (EnableExtraTOCRegDeps)
addPass(createPPCTOCRegDepsPass());
- // Run CTR loops pass before MachinePipeliner pass.
- // MachinePipeliner will pipeline all instructions before the terminator, but
- // we don't want DecreaseCTRPseudo to be pipelined.
- // Note we may lose some MachinePipeliner opportunities if we run CTR loops
- // generation pass before MachinePipeliner and the loop is converted back to
- // a normal loop. We can revisit this later for running PPCCTRLoops after
- // MachinePipeliner and handling DecreaseCTRPseudo in MachinePipeliner pass.
- if (getOptLevel() != CodeGenOpt::None)
- addPass(createPPCCTRLoopsPass());
-
if (getOptLevel() != CodeGenOpt::None)
addPass(&MachinePipelinerID);
}
diff --git a/llvm/test/CodeGen/PowerPC/O3-pipeline.ll b/llvm/test/CodeGen/PowerPC/O3-pipeline.ll
index 02ed427770c0..6b87f605dd8b 100644
--- a/llvm/test/CodeGen/PowerPC/O3-pipeline.ll
+++ b/llvm/test/CodeGen/PowerPC/O3-pipeline.ll
@@ -95,6 +95,9 @@
; CHECK-NEXT: PowerPC CTR Loops Verify
; CHECK-NEXT: PowerPC VSX Copy Legalization
; CHECK-NEXT: Finalize ISel and expand pseudo-instructions
+; CHECK-NEXT: MachineDominator Tree Construction
+; CHECK-NEXT: Machine Natural Loop Construction
+; CHECK-NEXT: PowerPC CTR loops generation
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
; CHECK-NEXT: Early Tail Duplication
; CHECK-NEXT: Optimize machine instruction PHIs
@@ -134,9 +137,6 @@
; CHECK-NEXT: PowerPC TOC Register Dependencies
; CHECK-NEXT: MachineDominator Tree Construction
; CHECK-NEXT: Machine Natural Loop Construction
-; CHECK-NEXT: PowerPC CTR loops generation
-; CHECK-NEXT: MachineDominator Tree Construction
-; CHECK-NEXT: Machine Natural Loop Construction
; CHECK-NEXT: Slot index numbering
; CHECK-NEXT: Live Interval Analysis
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
More information about the llvm-commits
mailing list