Skip to content

Commit 6ef4a7b

Browse files
authored
[RISCV] Exclude LPAD in machine outliner (#157220)
After #139993, the RISCVIndirectBranchTracking pass is also ran before the Machine Outliner pass, this yield a possibility that the outliner could also outline the LPAD instruction that should be placed at the target of an indirect branch. This patch excludes LPAD instruction from the candidate of machine outliner.
1 parent e91f367 commit 6ef4a7b

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3511,6 +3511,9 @@ RISCVInstrInfo::getOutliningTypeImpl(const MachineModuleInfo &MMI,
35113511
return outliner::InstrType::Illegal;
35123512
}
35133513

3514+
if (isLPAD(MI))
3515+
return outliner::InstrType::Illegal;
3516+
35143517
return outliner::InstrType::Legal;
35153518
}
35163519

llvm/lib/Target/RISCV/RISCVInstrPredicates.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ def isNonZeroLoadImmediate
148148
CheckNot<CheckImmOperand<2, 0>>
149149
]>>>;
150150

151+
def isLPAD
152+
: TIIPredicate<"isLPAD",
153+
MCReturnStatement<CheckAll<[
154+
CheckOpcode<[AUIPC]>,
155+
CheckIsRegOperand<0>,
156+
CheckRegOperand<0, X0>,
157+
]>>>;
158+
151159
def ignoresVXRM
152160
: TIIPredicate<"ignoresVXRM",
153161
MCOpcodeSwitchStatement<
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple riscv64 -mattr=+experimental-zicfilp < %s | FileCheck %s
3+
; RUN: llc -mtriple riscv32 -mattr=+experimental-zicfilp < %s | FileCheck %s
4+
5+
define i16 @test1(i16 %x) #0 {
6+
; CHECK-LABEL: test1:
7+
; CHECK: # %bb.0: # %entry
8+
; CHECK-NEXT: lpad 0
9+
; CHECK-NEXT: tail OUTLINED_FUNCTION_0
10+
entry:
11+
%y = add i16 5, %x
12+
%z = mul i16 4, %y
13+
ret i16 %z
14+
}
15+
16+
define i16 @test2(i16 %x) #0 {
17+
; CHECK-LABEL: test2:
18+
; CHECK: # %bb.0: # %entry
19+
; CHECK-NEXT: lpad 0
20+
; CHECK-NEXT: tail OUTLINED_FUNCTION_0
21+
entry:
22+
%y = add i16 5, %x
23+
%z = mul i16 4, %y
24+
ret i16 %z
25+
}
26+
27+
define i16 @test3(i16 %x) #0 {
28+
; CHECK-LABEL: test3:
29+
; CHECK: # %bb.0: # %entry
30+
; CHECK-NEXT: lpad 0
31+
; CHECK-NEXT: tail OUTLINED_FUNCTION_0
32+
entry:
33+
%y = add i16 5, %x
34+
%z = mul i16 4, %y
35+
ret i16 %z
36+
}
37+
38+
define i16 @test4(i16 %x) #0 {
39+
; CHECK-LABEL: test4:
40+
; CHECK: # %bb.0: # %entry
41+
; CHECK-NEXT: lpad 0
42+
; CHECK-NEXT: tail OUTLINED_FUNCTION_0
43+
entry:
44+
%y = add i16 5, %x
45+
%z = mul i16 4, %y
46+
ret i16 %z
47+
}
48+
49+
define i16 @main(i16 %x) #0 {
50+
; CHECK-LABEL: main:
51+
; CHECK: # %bb.0: # %entry
52+
; CHECK-NEXT: lpad 0
53+
; CHECK-NEXT: tail OUTLINED_FUNCTION_0
54+
entry:
55+
%y = add i16 5, %x
56+
%z = mul i16 4, %y
57+
ret i16 %z
58+
}
59+
60+
attributes #0 = { minsize }
61+
62+
!llvm.module.flags = !{!0, !1}
63+
64+
!0 = !{i32 8, !"cf-protection-branch", i32 1}
65+
!1 = !{i32 1, !"cf-branch-label-scheme", !"unlabeled"}

0 commit comments

Comments
 (0)