Skip to content

Commit 6ee890b

Browse files
committed
[RISCV] Precommit test for D122634
This is a recommit of 360d44e, which was reverted in b1620d4 because it caused some errors due to no `nounwind` attrs in `machine-outliner-cfi.mir`. Reviewed By: luismarques Differential Revision: https://reviews.llvm.org/D123364
1 parent 2147b6c commit 6ee890b

File tree

3 files changed

+263
-0
lines changed

3 files changed

+263
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# RUN: llc -march=riscv32 -x mir -run-pass=machine-outliner -simplify-mir -verify-machineinstrs < %s \
2+
# RUN: | FileCheck -check-prefixes=OUTLINED,RV32I-MO %s
3+
# RUN: llc -march=riscv64 -x mir -run-pass=machine-outliner -simplify-mir -verify-machineinstrs < %s \
4+
# RUN: | FileCheck -check-prefixes=OUTLINED,RV64I-MO %s
5+
6+
# CFIs are invisible (they can be outlined, but won't actually impact the outlining result) if there
7+
# is no need to unwind. CFIs will be stripped when we build outlined functions.
8+
9+
--- |
10+
define void @func1(i32 %a, i32 %b) nounwind { ret void }
11+
12+
define void @func2(i32 %a, i32 %b) nounwind { ret void }
13+
14+
define void @func3(i32 %a, i32 %b) nounwind { ret void }
15+
...
16+
---
17+
name: func1
18+
tracksRegLiveness: true
19+
body: |
20+
bb.0:
21+
liveins: $x10, $x11
22+
; RV32I-MO-LABEL: name: func1
23+
; RV32I-MO: liveins: $x10, $x11
24+
; RV32I-MO-NEXT: {{ $}}
25+
; RV32I-MO-NEXT: $x5 = PseudoCALLReg target-flags(riscv-call) @OUTLINED_FUNCTION_0, implicit-def $x5, implicit-def $x10, implicit-def $x11, implicit-def $x12, implicit $x10, implicit $x11
26+
; RV32I-MO-NEXT: PseudoRET
27+
; RV64I-MO-LABEL: name: func1
28+
; RV64I-MO: liveins: $x10, $x11
29+
; RV64I-MO-NEXT: {{ $}}
30+
; RV64I-MO-NEXT: $x5 = PseudoCALLReg target-flags(riscv-call) @OUTLINED_FUNCTION_0, implicit-def $x5, implicit-def $x10, implicit-def $x11, implicit-def $x12, implicit $x10, implicit $x11
31+
; RV64I-MO-NEXT: PseudoRET
32+
$x10 = ORI $x10, 1023
33+
CFI_INSTRUCTION offset $x1, 0
34+
$x11 = ORI $x11, 1023
35+
CFI_INSTRUCTION offset $x1, -4
36+
$x12 = ADDI $x10, 17
37+
CFI_INSTRUCTION offset $x1, -8
38+
$x11 = AND $x12, $x11
39+
CFI_INSTRUCTION offset $x1, -12
40+
$x10 = SUB $x10, $x11
41+
PseudoRET
42+
...
43+
---
44+
name: func2
45+
tracksRegLiveness: true
46+
body: |
47+
bb.0:
48+
liveins: $x10, $x11
49+
; RV32I-MO-LABEL: name: func2
50+
; RV32I-MO: liveins: $x10, $x11
51+
; RV32I-MO-NEXT: {{ $}}
52+
; RV32I-MO-NEXT: $x5 = PseudoCALLReg target-flags(riscv-call) @OUTLINED_FUNCTION_0, implicit-def $x5, implicit-def $x10, implicit-def $x11, implicit-def $x12, implicit $x10, implicit $x11
53+
; RV32I-MO-NEXT: PseudoRET
54+
; RV64I-MO-LABEL: name: func2
55+
; RV64I-MO: liveins: $x10, $x11
56+
; RV64I-MO-NEXT: {{ $}}
57+
; RV64I-MO-NEXT: $x5 = PseudoCALLReg target-flags(riscv-call) @OUTLINED_FUNCTION_0, implicit-def $x5, implicit-def $x10, implicit-def $x11, implicit-def $x12, implicit $x10, implicit $x11
58+
; RV64I-MO-NEXT: PseudoRET
59+
$x10 = ORI $x10, 1023
60+
CFI_INSTRUCTION offset $x1, 0
61+
$x11 = ORI $x11, 1023
62+
CFI_INSTRUCTION offset $x1, -8
63+
$x12 = ADDI $x10, 17
64+
CFI_INSTRUCTION offset $x1, -4
65+
$x11 = AND $x12, $x11
66+
CFI_INSTRUCTION offset $x1, -12
67+
$x10 = SUB $x10, $x11
68+
PseudoRET
69+
...
70+
---
71+
name: func3
72+
tracksRegLiveness: true
73+
body: |
74+
bb.0:
75+
liveins: $x10, $x11
76+
; RV32I-MO-LABEL: name: func3
77+
; RV32I-MO: liveins: $x10, $x11
78+
; RV32I-MO-NEXT: {{ $}}
79+
; RV32I-MO-NEXT: $x5 = PseudoCALLReg target-flags(riscv-call) @OUTLINED_FUNCTION_0, implicit-def $x5, implicit-def $x10, implicit-def $x11, implicit-def $x12, implicit $x10, implicit $x11
80+
; RV32I-MO-NEXT: PseudoRET
81+
; RV64I-MO-LABEL: name: func3
82+
; RV64I-MO: liveins: $x10, $x11
83+
; RV64I-MO-NEXT: {{ $}}
84+
; RV64I-MO-NEXT: $x5 = PseudoCALLReg target-flags(riscv-call) @OUTLINED_FUNCTION_0, implicit-def $x5, implicit-def $x10, implicit-def $x11, implicit-def $x12, implicit $x10, implicit $x11
85+
; RV64I-MO-NEXT: PseudoRET
86+
$x10 = ORI $x10, 1023
87+
CFI_INSTRUCTION offset $x1, -12
88+
$x11 = ORI $x11, 1023
89+
CFI_INSTRUCTION offset $x1, -8
90+
$x12 = ADDI $x10, 17
91+
CFI_INSTRUCTION offset $x1, -4
92+
$x11 = AND $x12, $x11
93+
CFI_INSTRUCTION offset $x1, 0
94+
$x10 = SUB $x10, $x11
95+
PseudoRET
96+
97+
98+
# OUTLINED-LABEL: name: OUTLINED_FUNCTION_0
99+
# OUTLINED: liveins: $x11, $x10, $x5
100+
# OUTLINED-NEXT: {{ $}}
101+
# OUTLINED-NEXT: $x10 = ORI $x10, 1023
102+
# OUTLINED-NEXT: $x11 = ORI $x11, 1023
103+
# OUTLINED-NEXT: $x12 = ADDI $x10, 17
104+
# OUTLINED-NEXT: $x11 = AND $x12, $x11
105+
# OUTLINED-NEXT: $x10 = SUB $x10, $x11
106+
# OUTLINED-NEXT: $x0 = JALR $x5, 0
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -march=riscv32 -x mir -run-pass=machine-outliner -simplify-mir -verify-machineinstrs < %s \
3+
# RUN: | FileCheck -check-prefixes=RV32I-MO %s
4+
# RUN: llc -march=riscv64 -x mir -run-pass=machine-outliner -simplify-mir -verify-machineinstrs < %s \
5+
# RUN: | FileCheck -check-prefixes=RV64I-MO %s
6+
7+
# Position instructions are illegal to outline. The first instruction won't be outlined
8+
# because position instructions break the sequence.
9+
10+
--- |
11+
define void @func1(i32 %a, i32 %b) { ret void }
12+
13+
define void @func2(i32 %a, i32 %b) { ret void }
14+
15+
define void @func3(i32 %a, i32 %b) { ret void }
16+
...
17+
---
18+
name: func1
19+
tracksRegLiveness: true
20+
body: |
21+
bb.0:
22+
liveins: $x10, $x11
23+
; RV32I-MO-LABEL: name: func1
24+
; RV32I-MO: liveins: $x10, $x11
25+
; RV32I-MO-NEXT: {{ $}}
26+
; RV32I-MO-NEXT: $x10 = ORI $x10, 1023
27+
; RV32I-MO-NEXT: EH_LABEL <mcsymbol .Ltmp0>
28+
; RV32I-MO-NEXT: $x5 = PseudoCALLReg target-flags(riscv-call) @OUTLINED_FUNCTION_0, implicit-def $x5, implicit-def $x10, implicit-def $x11, implicit-def $x12, implicit $x10, implicit $x11
29+
; RV32I-MO-NEXT: PseudoRET
30+
; RV64I-MO-LABEL: name: func1
31+
; RV64I-MO: liveins: $x10, $x11
32+
; RV64I-MO-NEXT: {{ $}}
33+
; RV64I-MO-NEXT: $x10 = ORI $x10, 1023
34+
; RV64I-MO-NEXT: EH_LABEL <mcsymbol .Ltmp0>
35+
; RV64I-MO-NEXT: $x5 = PseudoCALLReg target-flags(riscv-call) @OUTLINED_FUNCTION_0, implicit-def $x5, implicit-def $x10, implicit-def $x11, implicit-def $x12, implicit $x10, implicit $x11
36+
; RV64I-MO-NEXT: PseudoRET
37+
$x10 = ORI $x10, 1023
38+
EH_LABEL <mcsymbol .Ltmp0>
39+
$x11 = ORI $x11, 1023
40+
$x12 = ADDI $x10, 17
41+
$x11 = AND $x12, $x11
42+
$x10 = SUB $x10, $x11
43+
PseudoRET
44+
...
45+
---
46+
name: func2
47+
tracksRegLiveness: true
48+
body: |
49+
bb.0:
50+
liveins: $x10, $x11
51+
; RV32I-MO-LABEL: name: func2
52+
; RV32I-MO: liveins: $x10, $x11
53+
; RV32I-MO-NEXT: {{ $}}
54+
; RV32I-MO-NEXT: $x10 = ORI $x10, 1023
55+
; RV32I-MO-NEXT: GC_LABEL <mcsymbol .Ltmp1>
56+
; RV32I-MO-NEXT: $x5 = PseudoCALLReg target-flags(riscv-call) @OUTLINED_FUNCTION_0, implicit-def $x5, implicit-def $x10, implicit-def $x11, implicit-def $x12, implicit $x10, implicit $x11
57+
; RV32I-MO-NEXT: PseudoRET
58+
; RV64I-MO-LABEL: name: func2
59+
; RV64I-MO: liveins: $x10, $x11
60+
; RV64I-MO-NEXT: {{ $}}
61+
; RV64I-MO-NEXT: $x10 = ORI $x10, 1023
62+
; RV64I-MO-NEXT: GC_LABEL <mcsymbol .Ltmp1>
63+
; RV64I-MO-NEXT: $x5 = PseudoCALLReg target-flags(riscv-call) @OUTLINED_FUNCTION_0, implicit-def $x5, implicit-def $x10, implicit-def $x11, implicit-def $x12, implicit $x10, implicit $x11
64+
; RV64I-MO-NEXT: PseudoRET
65+
$x10 = ORI $x10, 1023
66+
GC_LABEL <mcsymbol .Ltmp1>
67+
$x11 = ORI $x11, 1023
68+
$x12 = ADDI $x10, 17
69+
$x11 = AND $x12, $x11
70+
$x10 = SUB $x10, $x11
71+
PseudoRET
72+
...
73+
---
74+
name: func3
75+
tracksRegLiveness: true
76+
body: |
77+
bb.0:
78+
liveins: $x10, $x11
79+
; RV32I-MO-LABEL: name: func3
80+
; RV32I-MO: liveins: $x10, $x11
81+
; RV32I-MO-NEXT: {{ $}}
82+
; RV32I-MO-NEXT: $x10 = ORI $x10, 1023
83+
; RV32I-MO-NEXT: ANNOTATION_LABEL <mcsymbol .Ltmp2>
84+
; RV32I-MO-NEXT: $x5 = PseudoCALLReg target-flags(riscv-call) @OUTLINED_FUNCTION_0, implicit-def $x5, implicit-def $x10, implicit-def $x11, implicit-def $x12, implicit $x10, implicit $x11
85+
; RV32I-MO-NEXT: PseudoRET
86+
; RV64I-MO-LABEL: name: func3
87+
; RV64I-MO: liveins: $x10, $x11
88+
; RV64I-MO-NEXT: {{ $}}
89+
; RV64I-MO-NEXT: $x10 = ORI $x10, 1023
90+
; RV64I-MO-NEXT: ANNOTATION_LABEL <mcsymbol .Ltmp2>
91+
; RV64I-MO-NEXT: $x5 = PseudoCALLReg target-flags(riscv-call) @OUTLINED_FUNCTION_0, implicit-def $x5, implicit-def $x10, implicit-def $x11, implicit-def $x12, implicit $x10, implicit $x11
92+
; RV64I-MO-NEXT: PseudoRET
93+
$x10 = ORI $x10, 1023
94+
ANNOTATION_LABEL <mcsymbol .Ltmp2>
95+
$x11 = ORI $x11, 1023
96+
$x12 = ADDI $x10, 17
97+
$x11 = AND $x12, $x11
98+
$x10 = SUB $x10, $x11
99+
PseudoRET
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
; RUN: llc -verify-machineinstrs -enable-machine-outliner -mattr=+m -mtriple=riscv64 < %s | FileCheck %s
2+
3+
; Ensure that we won't outline CFIs when they are needed in unwinding.
4+
5+
define i32 @func1(i32 %x) #0 {
6+
; CHECK-LABEL: func1:
7+
; CHECK: # %bb.0: # %entry
8+
; CHECK-NEXT: call t0, OUTLINED_FUNCTION_0
9+
; CHECK-NEXT: call __cxa_allocate_exception@plt
10+
; CHECK-NEXT: sw s0, 0(a0)
11+
; CHECK-NEXT: lui a1, %hi(_ZTIi)
12+
; CHECK-NEXT: addi a1, a1, %lo(_ZTIi)
13+
; CHECK-NEXT: li a2, 0
14+
; CHECK-NEXT: call __cxa_throw@plt
15+
entry:
16+
%mul = mul i32 %x, %x
17+
%add = add i32 %mul, 1
18+
%exception = tail call i8* @__cxa_allocate_exception(i64 4)
19+
%0 = bitcast i8* %exception to i32*
20+
store i32 %add, i32* %0
21+
tail call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null)
22+
unreachable
23+
}
24+
25+
define i32 @func2(i32 %x) #0 {
26+
; CHECK-LABEL: func2:
27+
; CHECK: # %bb.0: # %entry
28+
; CHECK-NEXT: call t0, OUTLINED_FUNCTION_0
29+
; CHECK-NEXT: call __cxa_allocate_exception@plt
30+
; CHECK-NEXT: sw s0, 0(a0)
31+
; CHECK-NEXT: lui a1, %hi(_ZTIi)
32+
; CHECK-NEXT: addi a1, a1, %lo(_ZTIi)
33+
; CHECK-NEXT: li a2, 0
34+
; CHECK-NEXT: call __cxa_throw@plt
35+
entry:
36+
%mul = mul i32 %x, %x
37+
%add = add i32 %mul, 1
38+
%exception = tail call i8* @__cxa_allocate_exception(i64 4)
39+
%0 = bitcast i8* %exception to i32*
40+
store i32 %add, i32* %0
41+
tail call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null)
42+
unreachable
43+
}
44+
45+
; CHECK-LABEL: OUTLINED_FUNCTION_0:
46+
; CHECK: # %bb.0:
47+
; CHECK-NEXT: addi sp, sp, -16
48+
; CHECK-NEXT: sd ra, 8(sp)
49+
; CHECK-NEXT: sd s0, 0(sp)
50+
; CHECK-NEXT: mulw a0, a0, a0
51+
; CHECK-NEXT: addiw s0, a0, 1
52+
; CHECK-NEXT: li a0, 4
53+
54+
@_ZTIi = external constant i8*
55+
declare i8* @__cxa_allocate_exception(i64)
56+
declare void @__cxa_throw(i8*, i8*, i8*)
57+
58+
attributes #0 = { minsize noreturn }

0 commit comments

Comments
 (0)