Skip to content

Commit 6d106ae

Browse files
committed
[RISCV][GISel] Add ZFA FP legalization and full sweep tests 9 now supported instructions
Signed-off-by: Luke Quinn <[email protected]>
1 parent 32b821c commit 6d106ae

File tree

4 files changed

+241
-2
lines changed

4 files changed

+241
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,13 @@ 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+
589+
.legalFor(ST.hasStdExtZfa() /*ST.hasStdExtF()*/, {s32})
590+
.legalFor(ST.hasStdExtZfa() & ST.hasStdExtD() , {s64})
591+
.legalFor(ST.hasStdExtZfa() & ST.hasStdExtZfh(), {s16})
589592
.libcallFor({s32, s64});
590593

591594
getActionDefinitionsBuilder({G_FCOS, G_FSIN, G_FTAN, G_FPOW, G_FLOG, G_FLOG2,
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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,+zfh -global-isel < %s \
4+
; RUN: | FileCheck %s --check-prefixes=CHECK-ZFA-f16
5+
; RUN: llc -mtriple=riscv64 -mattr=+zfa,+zfh -global-isel < %s \
6+
; RUN: | FileCheck %s --check-prefixes=CHECK-ZFA-f16
7+
8+
9+
define half @fceil(half %a) {
10+
; CHECK-ZFA-f16-LABEL: fceil:
11+
; CHECK-ZFA-f16: # %bb.0:
12+
; CHECK-ZFA-f16-NEXT: fround.h fa0, fa0, rup
13+
; CHECK-ZFA-f16-NEXT: ret
14+
%b = call half @llvm.ceil.f16(half %a)
15+
ret half %b
16+
}
17+
18+
define half @ffloor(half %a) {
19+
; CHECK-ZFA-f16-LABEL: ffloor:
20+
; CHECK-ZFA-f16: # %bb.0:
21+
; CHECK-ZFA-f16-NEXT: fround.h fa0, fa0, rdn
22+
; CHECK-ZFA-f16-NEXT: ret
23+
%b = call half @llvm.floor.f16(half %a)
24+
ret half %b
25+
}
26+
27+
define half @frint(half %a) {
28+
; CHECK-ZFA-f16-LABEL: frint:
29+
; CHECK-ZFA-f16: # %bb.0:
30+
; CHECK-ZFA-f16-NEXT: froundnx.h fa0, fa0
31+
; CHECK-ZFA-f16-NEXT: ret
32+
%b = call half @llvm.rint.f16(half %a)
33+
ret half %b
34+
}
35+
36+
define half @fnearbyint(half %a) {
37+
; CHECK-ZFA-f16-LABEL: fnearbyint:
38+
; CHECK-ZFA-f16: # %bb.0:
39+
; CHECK-ZFA-f16-NEXT: fround.h fa0, fa0
40+
; CHECK-ZFA-f16-NEXT: ret
41+
%b = call half @llvm.nearbyint.f16(half %a)
42+
ret half %b
43+
}
44+
45+
define half @fround(half %a) {
46+
; CHECK-ZFA-f16-LABEL: fround:
47+
; CHECK-ZFA-f16: # %bb.0:
48+
; CHECK-ZFA-f16-NEXT: fround.h fa0, fa0, rmm
49+
; CHECK-ZFA-f16-NEXT: ret
50+
%b = call half @llvm.round.f16(half %a)
51+
ret half %b
52+
}
53+
54+
define half @froundeven(half %a) {
55+
; CHECK-ZFA-f16-LABEL: froundeven:
56+
; CHECK-ZFA-f16: # %bb.0:
57+
; CHECK-ZFA-f16-NEXT: fround.h fa0, fa0, rne
58+
; CHECK-ZFA-f16-NEXT: ret
59+
%b = call half @llvm.roundeven.f16(half %a)
60+
ret half %b
61+
}
62+
define half @fmaximum(half %a, half %b) {
63+
; CHECK-ZFA-f16-LABEL: fmaximum:
64+
; CHECK-ZFA-f16: # %bb.0:
65+
; CHECK-ZFA-f16-NEXT: fmaxm.h fa0, fa0, fa1
66+
; CHECK-ZFA-f16-NEXT: ret
67+
%c = call half @llvm.maximum.f16(half %a, half %b)
68+
ret half %c
69+
}
70+
71+
define half @fminimum(half %a, half %b) {
72+
; CHECK-ZFA-f16-LABEL: fminimum:
73+
; CHECK-ZFA-f16: # %bb.0:
74+
; CHECK-ZFA-f16-NEXT: fminm.h fa0, fa0, fa1
75+
; CHECK-ZFA-f16-NEXT: ret
76+
%c = call half @llvm.minimum.f16(half %a, half %b)
77+
ret half %c
78+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
8+
9+
define float @fceil(float %a) {
10+
; CHECK-ZFA-f32-LABEL: fceil:
11+
; CHECK-ZFA-f32: # %bb.0:
12+
; CHECK-ZFA-f32-NEXT: fround.s fa0, fa0, rup
13+
; CHECK-ZFA-f32-NEXT: ret
14+
%b = call float @llvm.ceil.f32(float %a)
15+
ret float %b
16+
}
17+
18+
define float @ffloor(float %a) {
19+
; CHECK-ZFA-f32-LABEL: ffloor:
20+
; CHECK-ZFA-f32: # %bb.0:
21+
; CHECK-ZFA-f32-NEXT: fround.s fa0, fa0, rdn
22+
; CHECK-ZFA-f32-NEXT: ret
23+
%b = call float @llvm.floor.f32(float %a)
24+
ret float %b
25+
}
26+
27+
define float @frint(float %a) {
28+
; CHECK-ZFA-f32-LABEL: frint:
29+
; CHECK-ZFA-f32: # %bb.0:
30+
; CHECK-ZFA-f32-NEXT: froundnx.s fa0, fa0
31+
; CHECK-ZFA-f32-NEXT: ret
32+
%b = call float @llvm.rint.f32(float %a)
33+
ret float %b
34+
}
35+
36+
define float @fnearbyint(float %a) {
37+
; CHECK-ZFA-f32-LABEL: fnearbyint:
38+
; CHECK-ZFA-f32: # %bb.0:
39+
; CHECK-ZFA-f32-NEXT: fround.s fa0, fa0
40+
; CHECK-ZFA-f32-NEXT: ret
41+
%b = call float @llvm.nearbyint.f32(float %a)
42+
ret float %b
43+
}
44+
45+
define float @fround(float %a) {
46+
; CHECK-ZFA-f32-LABEL: fround:
47+
; CHECK-ZFA-f32: # %bb.0:
48+
; CHECK-ZFA-f32-NEXT: fround.s fa0, fa0, rmm
49+
; CHECK-ZFA-f32-NEXT: ret
50+
%b = call float @llvm.round.f32(float %a)
51+
ret float %b
52+
}
53+
54+
define float @fmaximum(float %a, float %b) {
55+
; CHECK-ZFA-f32-LABEL: fmaximum:
56+
; CHECK-ZFA-f32: # %bb.0:
57+
; CHECK-ZFA-f32-NEXT: fmaxm.s fa0, fa0, fa1
58+
; CHECK-ZFA-f32-NEXT: ret
59+
%c = call float @llvm.maximum.f32(float %a, float %b)
60+
ret float %c
61+
}
62+
63+
define float @fminimum(float %a, float %b) {
64+
; CHECK-ZFA-f32-LABEL: fminimum:
65+
; CHECK-ZFA-f32: # %bb.0:
66+
; CHECK-ZFA-f32-NEXT: fminm.s fa0, fa0, fa1
67+
; CHECK-ZFA-f32-NEXT: ret
68+
%c = call float @llvm.minimum.f32(float %a, float %b)
69+
ret float %c
70+
}
71+
72+
define float @froundeven(float %a) {
73+
; CHECK-ZFA-f32-LABEL: froundeven:
74+
; CHECK-ZFA-f32: # %bb.0:
75+
; CHECK-ZFA-f32-NEXT: fround.s fa0, fa0, rne
76+
; CHECK-ZFA-f32-NEXT: ret
77+
%b = call float @llvm.roundeven.f32(float %a)
78+
ret float %b
79+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
8+
9+
define double @fceil(double %a) {
10+
; CHECK-ZFA-f64-LABEL: fceil:
11+
; CHECK-ZFA-f64: # %bb.0:
12+
; CHECK-ZFA-f64-NEXT: fround.d fa0, fa0, rup
13+
; CHECK-ZFA-f64-NEXT: ret
14+
%b = call double @llvm.ceil.f64(double %a)
15+
ret double %b
16+
}
17+
18+
define double @ffloor(double %a) {
19+
; CHECK-ZFA-f64-LABEL: ffloor:
20+
; CHECK-ZFA-f64: # %bb.0:
21+
; CHECK-ZFA-f64-NEXT: fround.d fa0, fa0, rdn
22+
; CHECK-ZFA-f64-NEXT: ret
23+
%b = call double @llvm.floor.f64(double %a)
24+
ret double %b
25+
}
26+
27+
define double @frint(double %a) {
28+
; CHECK-ZFA-f64-LABEL: frint:
29+
; CHECK-ZFA-f64: # %bb.0:
30+
; CHECK-ZFA-f64-NEXT: froundnx.d fa0, fa0
31+
; CHECK-ZFA-f64-NEXT: ret
32+
%b = call double @llvm.rint.f64(double %a)
33+
ret double %b
34+
}
35+
36+
define double @fnearbyint(double %a) {
37+
; CHECK-ZFA-f64-LABEL: fnearbyint:
38+
; CHECK-ZFA-f64: # %bb.0:
39+
; CHECK-ZFA-f64-NEXT: fround.d fa0, fa0
40+
; CHECK-ZFA-f64-NEXT: ret
41+
%b = call double @llvm.nearbyint.f64(double %a)
42+
ret double %b
43+
}
44+
45+
define double @fround(double %a) {
46+
; CHECK-ZFA-f64-LABEL: fround:
47+
; CHECK-ZFA-f64: # %bb.0:
48+
; CHECK-ZFA-f64-NEXT: fround.d fa0, fa0, rmm
49+
; CHECK-ZFA-f64-NEXT: ret
50+
%b = call double @llvm.round.f64(double %a)
51+
ret double %b
52+
}
53+
54+
define double @froundeven(double %a) {
55+
; CHECK-ZFA-f64-LABEL: froundeven:
56+
; CHECK-ZFA-f64: # %bb.0:
57+
; CHECK-ZFA-f64-NEXT: fround.d fa0, fa0, rne
58+
; CHECK-ZFA-f64-NEXT: ret
59+
%b = call double @llvm.roundeven.f64(double %a)
60+
ret double %b
61+
}
62+
63+
define double @fmaximum(double %a, double %b) {
64+
; CHECK-ZFA-f64-LABEL: fmaximum:
65+
; CHECK-ZFA-f64: # %bb.0:
66+
; CHECK-ZFA-f64-NEXT: fmaxm.d fa0, fa0, fa1
67+
; CHECK-ZFA-f64-NEXT: ret
68+
%c = call double @llvm.maximum.f64(double %a, double %b)
69+
ret double %c
70+
}
71+
72+
define double @fminimum(double %a, double %b) {
73+
; CHECK-ZFA-f64-LABEL: fminimum:
74+
; CHECK-ZFA-f64: # %bb.0:
75+
; CHECK-ZFA-f64-NEXT: fminm.d fa0, fa0, fa1
76+
; CHECK-ZFA-f64-NEXT: ret
77+
%c = call double @llvm.minimum.f64(double %a, double %b)
78+
ret double %c
79+
}

0 commit comments

Comments
 (0)