Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LoongArch] Add support for the BranchRelaxation pass
When the branch target is out of the range represented by the current branch instruction's immediate, branch relaxation is required. There are three types of immediate for branch instructions on LoongArch, including simm16, simm21 and simm26. And the real branch target address is PC + sext(simmXX << 2). In addition, the indirect branch way is implemented to support larger branch target. BranchRelaxation pass calls `RenumberBlocks` to renumber all of the machine basic blocks in the function. So the machine basic blocks number changed in some test cases. Differential Revision: https://reviews.llvm.org/D137233
- Loading branch information
1 parent
5426a1e
commit 57ad3f1
Showing
9 changed files
with
252 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc --mtriple=loongarch32 --filetype=obj --verify-machineinstrs < %s \ | ||
; RUN: -o /dev/null 2>&1 | ||
; RUN: llc --mtriple=loongarch64 --filetype=obj --verify-machineinstrs < %s \ | ||
; RUN: -o /dev/null 2>&1 | ||
; RUN: llc --mtriple=loongarch32 --verify-machineinstrs < %s | FileCheck %s --check-prefix=LA32 | ||
; RUN: llc --mtriple=loongarch64 --verify-machineinstrs < %s | FileCheck %s --check-prefix=LA64 | ||
|
||
define i32 @relax_b18(i32 signext %a, i32 signext %b) { | ||
; LA32-LABEL: relax_b18: | ||
; LA32: # %bb.0: | ||
; LA32-NEXT: beq $a0, $a1, .LBB0_1 | ||
; LA32-NEXT: b .LBB0_2 | ||
; LA32-NEXT: .LBB0_1: # %iftrue | ||
; LA32-NEXT: #APP | ||
; LA32-NEXT: .space 1048576 | ||
; LA32-NEXT: #NO_APP | ||
; LA32-NEXT: ori $a0, $zero, 1 | ||
; LA32-NEXT: ret | ||
; LA32-NEXT: .LBB0_2: # %iffalse | ||
; LA32-NEXT: move $a0, $zero | ||
; LA32-NEXT: ret | ||
; | ||
; LA64-LABEL: relax_b18: | ||
; LA64: # %bb.0: | ||
; LA64-NEXT: beq $a0, $a1, .LBB0_1 | ||
; LA64-NEXT: b .LBB0_2 | ||
; LA64-NEXT: .LBB0_1: # %iftrue | ||
; LA64-NEXT: #APP | ||
; LA64-NEXT: .space 1048576 | ||
; LA64-NEXT: #NO_APP | ||
; LA64-NEXT: ori $a0, $zero, 1 | ||
; LA64-NEXT: ret | ||
; LA64-NEXT: .LBB0_2: # %iffalse | ||
; LA64-NEXT: move $a0, $zero | ||
; LA64-NEXT: ret | ||
%cond = icmp eq i32 %a, %b | ||
br i1 %cond, label %iftrue, label %iffalse | ||
|
||
iftrue: | ||
call void asm sideeffect ".space 1048576", ""() | ||
ret i32 1 | ||
|
||
iffalse: | ||
ret i32 0 | ||
} | ||
|
||
define i32 @relax_b23(i1 %a) { | ||
; LA32-LABEL: relax_b23: | ||
; LA32: # %bb.0: | ||
; LA32-NEXT: andi $a0, $a0, 1 | ||
; LA32-NEXT: bnez $a0, .LBB1_1 | ||
; LA32-NEXT: b .LBB1_2 | ||
; LA32-NEXT: .LBB1_1: # %iftrue | ||
; LA32-NEXT: #APP | ||
; LA32-NEXT: .space 16777216 | ||
; LA32-NEXT: #NO_APP | ||
; LA32-NEXT: ori $a0, $zero, 1 | ||
; LA32-NEXT: ret | ||
; LA32-NEXT: .LBB1_2: # %iffalse | ||
; LA32-NEXT: move $a0, $zero | ||
; LA32-NEXT: ret | ||
; | ||
; LA64-LABEL: relax_b23: | ||
; LA64: # %bb.0: | ||
; LA64-NEXT: andi $a0, $a0, 1 | ||
; LA64-NEXT: bnez $a0, .LBB1_1 | ||
; LA64-NEXT: b .LBB1_2 | ||
; LA64-NEXT: .LBB1_1: # %iftrue | ||
; LA64-NEXT: #APP | ||
; LA64-NEXT: .space 16777216 | ||
; LA64-NEXT: #NO_APP | ||
; LA64-NEXT: ori $a0, $zero, 1 | ||
; LA64-NEXT: ret | ||
; LA64-NEXT: .LBB1_2: # %iffalse | ||
; LA64-NEXT: move $a0, $zero | ||
; LA64-NEXT: ret | ||
br i1 %a, label %iftrue, label %iffalse | ||
|
||
iftrue: | ||
call void asm sideeffect ".space 16777216", ""() | ||
ret i32 1 | ||
|
||
iffalse: | ||
ret i32 0 | ||
} | ||
|
||
define i32 @relax_b28(i1 %a) { | ||
; LA32-LABEL: relax_b28: | ||
; LA32: # %bb.0: | ||
; LA32-NEXT: andi $a0, $a0, 1 | ||
; LA32-NEXT: bnez $a0, .LBB2_1 | ||
; LA32-NEXT: # %bb.3: | ||
; LA32-NEXT: pcalau12i $a0, %pc_hi20(.LBB2_2) | ||
; LA32-NEXT: addi.w $a0, $a0, %pc_lo12(.LBB2_2) | ||
; LA32-NEXT: jr $a0 | ||
; LA32-NEXT: .LBB2_1: # %iftrue | ||
; LA32-NEXT: #APP | ||
; LA32-NEXT: .space 536870912 | ||
; LA32-NEXT: #NO_APP | ||
; LA32-NEXT: ori $a0, $zero, 1 | ||
; LA32-NEXT: ret | ||
; LA32-NEXT: .LBB2_2: # %iffalse | ||
; LA32-NEXT: move $a0, $zero | ||
; LA32-NEXT: ret | ||
; | ||
; LA64-LABEL: relax_b28: | ||
; LA64: # %bb.0: | ||
; LA64-NEXT: andi $a0, $a0, 1 | ||
; LA64-NEXT: bnez $a0, .LBB2_1 | ||
; LA64-NEXT: # %bb.3: | ||
; LA64-NEXT: pcalau12i $a0, %pc_hi20(.LBB2_2) | ||
; LA64-NEXT: addi.d $a0, $a0, %pc_lo12(.LBB2_2) | ||
; LA64-NEXT: jr $a0 | ||
; LA64-NEXT: .LBB2_1: # %iftrue | ||
; LA64-NEXT: #APP | ||
; LA64-NEXT: .space 536870912 | ||
; LA64-NEXT: #NO_APP | ||
; LA64-NEXT: ori $a0, $zero, 1 | ||
; LA64-NEXT: ret | ||
; LA64-NEXT: .LBB2_2: # %iffalse | ||
; LA64-NEXT: move $a0, $zero | ||
; LA64-NEXT: ret | ||
br i1 %a, label %iftrue, label %iffalse | ||
|
||
iftrue: | ||
call void asm sideeffect ".space 536870912", ""() | ||
ret i32 1 | ||
|
||
iffalse: | ||
ret i32 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.