Skip to content

Commit e5ad7f4

Browse files
authored
[RISCV] Move RISCVIndirectBranchTracking before Branch Relaxation (#139993)
The `RISCVIndirectBranchTracking` pass inserts `lpad` instruction and could change the basic block alignment, so this should not happen after the branch relaxation as the adjusted offset is possible to exceed the branch range.
1 parent 64bd485 commit e5ad7f4

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ void RISCVPassConfig::addPreEmitPass() {
570570
addPass(createMachineCopyPropagationPass(true));
571571
if (TM->getOptLevel() >= CodeGenOptLevel::Default)
572572
addPass(createRISCVLateBranchOptPass());
573+
// The IndirectBranchTrackingPass inserts lpad and could have changed the
574+
// basic block alignment. It must be done before Branch Relaxation to
575+
// prevent the adjusted offset exceeding the branch range.
576+
addPass(createRISCVIndirectBranchTrackingPass());
573577
addPass(&BranchRelaxationPassID);
574578
addPass(createRISCVMakeCompressibleOptPass());
575579
}
@@ -581,7 +585,6 @@ void RISCVPassConfig::addPreEmitPass2() {
581585
// ensuring return instruction is detected correctly.
582586
addPass(createRISCVPushPopOptimizationPass());
583587
}
584-
addPass(createRISCVIndirectBranchTrackingPass());
585588
addPass(createRISCVExpandPseudoPass());
586589

587590
// Schedule the expansion of AMOs at the last possible moment, avoiding the

llvm/test/CodeGen/RISCV/O0-pipeline.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
; CHECK-NEXT: Insert fentry calls
6363
; CHECK-NEXT: Insert XRay ops
6464
; CHECK-NEXT: Implement the 'patchable-function' attribute
65+
; CHECK-NEXT: RISC-V Indirect Branch Tracking
6566
; CHECK-NEXT: Branch relaxation pass
6667
; CHECK-NEXT: RISC-V Make Compressible
6768
; CHECK-NEXT: Contiguously Lay Out Funclets
@@ -73,7 +74,6 @@
7374
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
7475
; CHECK-NEXT: Machine Optimization Remark Emitter
7576
; CHECK-NEXT: Stack Frame Layout Analysis
76-
; CHECK-NEXT: RISC-V Indirect Branch Tracking
7777
; CHECK-NEXT: RISC-V pseudo instruction expansion pass
7878
; CHECK-NEXT: RISC-V atomic pseudo instruction expansion pass
7979
; CHECK-NEXT: Unpack machine instruction bundles

llvm/test/CodeGen/RISCV/O3-pipeline.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
; CHECK-NEXT: Implement the 'patchable-function' attribute
196196
; CHECK-NEXT: Machine Copy Propagation Pass
197197
; CHECK-NEXT: RISC-V Late Branch Optimisation Pass
198+
; CHECK-NEXT: RISC-V Indirect Branch Tracking
198199
; CHECK-NEXT: Branch relaxation pass
199200
; CHECK-NEXT: RISC-V Make Compressible
200201
; CHECK-NEXT: Contiguously Lay Out Funclets
@@ -210,7 +211,6 @@
210211
; CHECK-NEXT: Stack Frame Layout Analysis
211212
; CHECK-NEXT: RISC-V Zcmp move merging pass
212213
; CHECK-NEXT: RISC-V Zcmp Push/Pop optimization pass
213-
; CHECK-NEXT: RISC-V Indirect Branch Tracking
214214
; CHECK-NEXT: RISC-V pseudo instruction expansion pass
215215
; CHECK-NEXT: RISC-V atomic pseudo instruction expansion pass
216216
; CHECK-NEXT: Unpack machine instruction bundles

0 commit comments

Comments
 (0)