Skip to content

Commit 892e94c

Browse files
committed
[WIP][RISCV][GISel] Add ZFA 7 insn [WIP] (min/max)imum
Signed-off-by: Luke Quinn <[email protected]>
1 parent 32b821c commit 892e94c

File tree

4 files changed

+403
-2
lines changed

4 files changed

+403
-2
lines changed

llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,12 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
582582
.libcallFor(ST.is64Bit(), {{s32, s128}, {s64, s128}});
583583

584584
// FIXME: We can do custom inline expansion like SelectionDAG.
585-
// FIXME: Legal with Zfa.
586585
getActionDefinitionsBuilder({G_FCEIL, G_FFLOOR, G_FRINT, G_FNEARBYINT,
587586
G_INTRINSIC_TRUNC, G_INTRINSIC_ROUND,
588-
G_INTRINSIC_ROUNDEVEN})
587+
G_INTRINSIC_ROUNDEVEN, G_FMAXIMUM, G_FMINIMUM})
588+
.legalFor(ST.hasStdExtZfa() /*ST.hasStdExtF()*/, {s32})
589+
.legalFor(ST.hasStdExtZfa() && ST.hasStdExtD(), {s64})
590+
.legalFor(ST.hasStdExtZfa() && ST.hasStdExtZfh(), {s16})
589591
.libcallFor({s32, s64});
590592

591593
getActionDefinitionsBuilder({G_FCOS, G_FSIN, G_FTAN, G_FPOW, G_FLOG, G_FLOG2,
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
3+
; RUN: llc -mtriple=riscv32 -mattr=+zfa,d -global-isel < %s \
4+
; RUN: | FileCheck %s --check-prefixes=CHECK-ZFA-f64
5+
; RUN: llc -mtriple=riscv64 -mattr=+zfa,d -global-isel < %s \
6+
; RUN: | FileCheck %s --check-prefixes=CHECK-ZFA-f64
7+
; RUN: llc -mtriple=riscv32 -mattr=+d -global-isel < %s \
8+
; RUN: | FileCheck %s --check-prefix=CHECK-ZFA-libcall
9+
10+
11+
define double @fceil(double %a) {
12+
; CHECK-ZFA-f64-LABEL: fceil:
13+
; CHECK-ZFA-f64: # %bb.0:
14+
; CHECK-ZFA-f64-NEXT: fround.d fa0, fa0, rup
15+
; CHECK-ZFA-f64-NEXT: ret
16+
;
17+
; CHECK-ZFA-libcall-LABEL: fceil:
18+
; CHECK-ZFA-libcall: # %bb.0:
19+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, -16
20+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 16
21+
; CHECK-ZFA-libcall-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
22+
; CHECK-ZFA-libcall-NEXT: .cfi_offset ra, -4
23+
; CHECK-ZFA-libcall-NEXT: call ceil
24+
; CHECK-ZFA-libcall-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
25+
; CHECK-ZFA-libcall-NEXT: .cfi_restore ra
26+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, 16
27+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 0
28+
; CHECK-ZFA-libcall-NEXT: ret
29+
%b = call double @llvm.ceil.f64(double %a)
30+
ret double %b
31+
}
32+
33+
define double @ffloor(double %a) {
34+
; CHECK-ZFA-f64-LABEL: ffloor:
35+
; CHECK-ZFA-f64: # %bb.0:
36+
; CHECK-ZFA-f64-NEXT: fround.d fa0, fa0, rdn
37+
; CHECK-ZFA-f64-NEXT: ret
38+
;
39+
; CHECK-ZFA-libcall-LABEL: ffloor:
40+
; CHECK-ZFA-libcall: # %bb.0:
41+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, -16
42+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 16
43+
; CHECK-ZFA-libcall-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
44+
; CHECK-ZFA-libcall-NEXT: .cfi_offset ra, -4
45+
; CHECK-ZFA-libcall-NEXT: call floor
46+
; CHECK-ZFA-libcall-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
47+
; CHECK-ZFA-libcall-NEXT: .cfi_restore ra
48+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, 16
49+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 0
50+
; CHECK-ZFA-libcall-NEXT: ret
51+
%b = call double @llvm.floor.f64(double %a)
52+
ret double %b
53+
}
54+
55+
define double @frint(double %a) {
56+
; CHECK-ZFA-f64-LABEL: frint:
57+
; CHECK-ZFA-f64: # %bb.0:
58+
; CHECK-ZFA-f64-NEXT: froundnx.d fa0, fa0
59+
; CHECK-ZFA-f64-NEXT: ret
60+
;
61+
; CHECK-ZFA-libcall-LABEL: frint:
62+
; CHECK-ZFA-libcall: # %bb.0:
63+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, -16
64+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 16
65+
; CHECK-ZFA-libcall-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
66+
; CHECK-ZFA-libcall-NEXT: .cfi_offset ra, -4
67+
; CHECK-ZFA-libcall-NEXT: call rint
68+
; CHECK-ZFA-libcall-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
69+
; CHECK-ZFA-libcall-NEXT: .cfi_restore ra
70+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, 16
71+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 0
72+
; CHECK-ZFA-libcall-NEXT: ret
73+
%b = call double @llvm.rint.f64(double %a)
74+
ret double %b
75+
}
76+
77+
define double @fnearbyint(double %a) {
78+
; CHECK-ZFA-f64-LABEL: fnearbyint:
79+
; CHECK-ZFA-f64: # %bb.0:
80+
; CHECK-ZFA-f64-NEXT: fround.d fa0, fa0
81+
; CHECK-ZFA-f64-NEXT: ret
82+
;
83+
; CHECK-ZFA-libcall-LABEL: fnearbyint:
84+
; CHECK-ZFA-libcall: # %bb.0:
85+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, -16
86+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 16
87+
; CHECK-ZFA-libcall-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
88+
; CHECK-ZFA-libcall-NEXT: .cfi_offset ra, -4
89+
; CHECK-ZFA-libcall-NEXT: call nearbyint
90+
; CHECK-ZFA-libcall-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
91+
; CHECK-ZFA-libcall-NEXT: .cfi_restore ra
92+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, 16
93+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 0
94+
; CHECK-ZFA-libcall-NEXT: ret
95+
%b = call double @llvm.nearbyint.f64(double %a)
96+
ret double %b
97+
}
98+
99+
define double @fround(double %a) {
100+
; CHECK-ZFA-f64-LABEL: fround:
101+
; CHECK-ZFA-f64: # %bb.0:
102+
; CHECK-ZFA-f64-NEXT: fround.d fa0, fa0, rmm
103+
; CHECK-ZFA-f64-NEXT: ret
104+
;
105+
; CHECK-ZFA-libcall-LABEL: fround:
106+
; CHECK-ZFA-libcall: # %bb.0:
107+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, -16
108+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 16
109+
; CHECK-ZFA-libcall-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
110+
; CHECK-ZFA-libcall-NEXT: .cfi_offset ra, -4
111+
; CHECK-ZFA-libcall-NEXT: call round
112+
; CHECK-ZFA-libcall-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
113+
; CHECK-ZFA-libcall-NEXT: .cfi_restore ra
114+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, 16
115+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 0
116+
; CHECK-ZFA-libcall-NEXT: ret
117+
%b = call double @llvm.round.f64(double %a)
118+
ret double %b
119+
}
120+
121+
define double @froundeven(double %a) {
122+
; CHECK-ZFA-f64-LABEL: froundeven:
123+
; CHECK-ZFA-f64: # %bb.0:
124+
; CHECK-ZFA-f64-NEXT: fround.d fa0, fa0, rne
125+
; CHECK-ZFA-f64-NEXT: ret
126+
;
127+
; CHECK-ZFA-libcall-LABEL: froundeven:
128+
; CHECK-ZFA-libcall: # %bb.0:
129+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, -16
130+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 16
131+
; CHECK-ZFA-libcall-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
132+
; CHECK-ZFA-libcall-NEXT: .cfi_offset ra, -4
133+
; CHECK-ZFA-libcall-NEXT: call roundeven
134+
; CHECK-ZFA-libcall-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
135+
; CHECK-ZFA-libcall-NEXT: .cfi_restore ra
136+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, 16
137+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 0
138+
; CHECK-ZFA-libcall-NEXT: ret
139+
%b = call double @llvm.roundeven.f64(double %a)
140+
ret double %b
141+
}
142+
143+
;; TODO recreate this test with LIB call
144+
;define double @fmaximum(double %a, double %b) {
145+
;; CHECK-ZFA-f64-LABEL: fmaximum:
146+
;; CHECK-ZFA-f64: # %bb.0:
147+
;; CHECK-ZFA-f64-NEXT: fmaxm.d fa0, fa0, fa1
148+
;; CHECK-ZFA-f64-NEXT: ret
149+
; %c = call double @llvm.maximum.f64(double %a, double %b)
150+
; ret double %c
151+
;}
152+
;
153+
;define double @fminimum(double %a, double %b) {
154+
;; CHECK-ZFA-f64-LABEL: fminimum:
155+
;; CHECK-ZFA-f64: # %bb.0:
156+
;; CHECK-ZFA-f64-NEXT: fminm.d fa0, fa0, fa1
157+
;; CHECK-ZFA-f64-NEXT: ret
158+
; %c = call double @llvm.minimum.f64(double %a, double %b)
159+
; ret double %c
160+
;}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
3+
; RUN: llc -mtriple=riscv32 -mattr=+zfa -global-isel < %s \
4+
; RUN: | FileCheck %s --check-prefixes=CHECK-ZFA-f32
5+
; RUN: llc -mtriple=riscv64 -mattr=+zfa -global-isel < %s \
6+
; RUN: | FileCheck %s --check-prefixes=CHECK-ZFA-f32
7+
; RUN: llc -mtriple=riscv32 -mattr=+f -global-isel < %s \
8+
; RUN: | FileCheck %s --check-prefix=CHECK-ZFA-libcall
9+
10+
11+
define float @fceil(float %a) {
12+
; CHECK-ZFA-f32-LABEL: fceil:
13+
; CHECK-ZFA-f32: # %bb.0:
14+
; CHECK-ZFA-f32-NEXT: fround.s fa0, fa0, rup
15+
; CHECK-ZFA-f32-NEXT: ret
16+
;
17+
; CHECK-ZFA-libcall-LABEL: fceil:
18+
; CHECK-ZFA-libcall: # %bb.0:
19+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, -16
20+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 16
21+
; CHECK-ZFA-libcall-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
22+
; CHECK-ZFA-libcall-NEXT: .cfi_offset ra, -4
23+
; CHECK-ZFA-libcall-NEXT: call ceilf
24+
; CHECK-ZFA-libcall-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
25+
; CHECK-ZFA-libcall-NEXT: .cfi_restore ra
26+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, 16
27+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 0
28+
; CHECK-ZFA-libcall-NEXT: ret
29+
%b = call float @llvm.ceil.f32(float %a)
30+
ret float %b
31+
}
32+
33+
define float @ffloor(float %a) {
34+
; CHECK-ZFA-f32-LABEL: ffloor:
35+
; CHECK-ZFA-f32: # %bb.0:
36+
; CHECK-ZFA-f32-NEXT: fround.s fa0, fa0, rdn
37+
; CHECK-ZFA-f32-NEXT: ret
38+
;
39+
; CHECK-ZFA-libcall-LABEL: ffloor:
40+
; CHECK-ZFA-libcall: # %bb.0:
41+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, -16
42+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 16
43+
; CHECK-ZFA-libcall-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
44+
; CHECK-ZFA-libcall-NEXT: .cfi_offset ra, -4
45+
; CHECK-ZFA-libcall-NEXT: call floorf
46+
; CHECK-ZFA-libcall-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
47+
; CHECK-ZFA-libcall-NEXT: .cfi_restore ra
48+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, 16
49+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 0
50+
; CHECK-ZFA-libcall-NEXT: ret
51+
%b = call float @llvm.floor.f32(float %a)
52+
ret float %b
53+
}
54+
55+
define float @frint(float %a) {
56+
; CHECK-ZFA-f32-LABEL: frint:
57+
; CHECK-ZFA-f32: # %bb.0:
58+
; CHECK-ZFA-f32-NEXT: froundnx.s fa0, fa0
59+
; CHECK-ZFA-f32-NEXT: ret
60+
;
61+
; CHECK-ZFA-libcall-LABEL: frint:
62+
; CHECK-ZFA-libcall: # %bb.0:
63+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, -16
64+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 16
65+
; CHECK-ZFA-libcall-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
66+
; CHECK-ZFA-libcall-NEXT: .cfi_offset ra, -4
67+
; CHECK-ZFA-libcall-NEXT: call rintf
68+
; CHECK-ZFA-libcall-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
69+
; CHECK-ZFA-libcall-NEXT: .cfi_restore ra
70+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, 16
71+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 0
72+
; CHECK-ZFA-libcall-NEXT: ret
73+
%b = call float @llvm.rint.f32(float %a)
74+
ret float %b
75+
}
76+
77+
define float @fnearbyint(float %a) {
78+
; CHECK-ZFA-f32-LABEL: fnearbyint:
79+
; CHECK-ZFA-f32: # %bb.0:
80+
; CHECK-ZFA-f32-NEXT: fround.s fa0, fa0
81+
; CHECK-ZFA-f32-NEXT: ret
82+
;
83+
; CHECK-ZFA-libcall-LABEL: fnearbyint:
84+
; CHECK-ZFA-libcall: # %bb.0:
85+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, -16
86+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 16
87+
; CHECK-ZFA-libcall-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
88+
; CHECK-ZFA-libcall-NEXT: .cfi_offset ra, -4
89+
; CHECK-ZFA-libcall-NEXT: call nearbyintf
90+
; CHECK-ZFA-libcall-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
91+
; CHECK-ZFA-libcall-NEXT: .cfi_restore ra
92+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, 16
93+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 0
94+
; CHECK-ZFA-libcall-NEXT: ret
95+
%b = call float @llvm.nearbyint.f32(float %a)
96+
ret float %b
97+
}
98+
99+
define float @fround(float %a) {
100+
; CHECK-ZFA-f32-LABEL: fround:
101+
; CHECK-ZFA-f32: # %bb.0:
102+
; CHECK-ZFA-f32-NEXT: fround.s fa0, fa0, rmm
103+
; CHECK-ZFA-f32-NEXT: ret
104+
;
105+
; CHECK-ZFA-libcall-LABEL: fround:
106+
; CHECK-ZFA-libcall: # %bb.0:
107+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, -16
108+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 16
109+
; CHECK-ZFA-libcall-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
110+
; CHECK-ZFA-libcall-NEXT: .cfi_offset ra, -4
111+
; CHECK-ZFA-libcall-NEXT: call roundf
112+
; CHECK-ZFA-libcall-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
113+
; CHECK-ZFA-libcall-NEXT: .cfi_restore ra
114+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, 16
115+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 0
116+
; CHECK-ZFA-libcall-NEXT: ret
117+
%b = call float @llvm.round.f32(float %a)
118+
ret float %b
119+
}
120+
121+
122+
define float @froundeven(float %a) {
123+
; CHECK-ZFA-f32-LABEL: froundeven:
124+
; CHECK-ZFA-f32: # %bb.0:
125+
; CHECK-ZFA-f32-NEXT: fround.s fa0, fa0, rne
126+
; CHECK-ZFA-f32-NEXT: ret
127+
;
128+
; CHECK-ZFA-libcall-LABEL: froundeven:
129+
; CHECK-ZFA-libcall: # %bb.0:
130+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, -16
131+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 16
132+
; CHECK-ZFA-libcall-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
133+
; CHECK-ZFA-libcall-NEXT: .cfi_offset ra, -4
134+
; CHECK-ZFA-libcall-NEXT: call roundevenf
135+
; CHECK-ZFA-libcall-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
136+
; CHECK-ZFA-libcall-NEXT: .cfi_restore ra
137+
; CHECK-ZFA-libcall-NEXT: addi sp, sp, 16
138+
; CHECK-ZFA-libcall-NEXT: .cfi_def_cfa_offset 0
139+
; CHECK-ZFA-libcall-NEXT: ret
140+
%b = call float @llvm.roundeven.f32(float %a)
141+
ret float %b
142+
}
143+
144+
; TODO fix these tests for libcall
145+
;;define float @fmaximum(float %a, float %b) {
146+
;; CHECK-ZFA-f32-LABEL: fmaximum:
147+
;; CHECK-ZFA-f32: # %bb.0:
148+
;; CHECK-ZFA-f32-NEXT: fmaxm.s fa0, fa0, fa1
149+
;; CHECK-ZFA-f32-NEXT: ret
150+
; %c = call float @llvm.maximum.f32(float %a, float %b)
151+
; ret float %c
152+
;}
153+
;
154+
;define float @fminimum(float %a, float %b) {
155+
;; CHECK-ZFA-f32-LABEL: fminimum:
156+
;; CHECK-ZFA-f32: # %bb.0:
157+
;; CHECK-ZFA-f32-NEXT: fminm.s fa0, fa0, fa1
158+
;; CHECK-ZFA-f32-NEXT: ret
159+
; %c = call float @llvm.minimum.f32(float %a, float %b)
160+
; ret float %c
161+
;}

0 commit comments

Comments
 (0)