Skip to content

Commit 5ade51d

Browse files
committed
[ARM]: codegen llvm.roundeven.v*
1 parent 4504e77 commit 5ade51d

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM,
905905
setOperationAction(ISD::FCEIL, MVT::v2f64, Expand);
906906
setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand);
907907
setOperationAction(ISD::FRINT, MVT::v2f64, Expand);
908+
setOperationAction(ISD::FROUNDEVEN, MVT::v2f64, Expand);
908909
setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand);
909910
setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand);
910911
setOperationAction(ISD::FMA, MVT::v2f64, Expand);
@@ -927,6 +928,7 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM,
927928
setOperationAction(ISD::FCEIL, MVT::v4f32, Expand);
928929
setOperationAction(ISD::FTRUNC, MVT::v4f32, Expand);
929930
setOperationAction(ISD::FRINT, MVT::v4f32, Expand);
931+
setOperationAction(ISD::FROUNDEVEN, MVT::v4f32, Expand);
930932
setOperationAction(ISD::FNEARBYINT, MVT::v4f32, Expand);
931933
setOperationAction(ISD::FFLOOR, MVT::v4f32, Expand);
932934

@@ -945,6 +947,7 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM,
945947
setOperationAction(ISD::FCEIL, MVT::v2f32, Expand);
946948
setOperationAction(ISD::FTRUNC, MVT::v2f32, Expand);
947949
setOperationAction(ISD::FRINT, MVT::v2f32, Expand);
950+
setOperationAction(ISD::FROUNDEVEN, MVT::v2f32, Expand);
948951
setOperationAction(ISD::FNEARBYINT, MVT::v2f32, Expand);
949952
setOperationAction(ISD::FFLOOR, MVT::v2f32, Expand);
950953

@@ -1087,6 +1090,7 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM,
10871090
setOperationAction(ISD::FCEIL, MVT::f64, Expand);
10881091
setOperationAction(ISD::FTRUNC, MVT::f64, Expand);
10891092
setOperationAction(ISD::FRINT, MVT::f64, Expand);
1093+
setOperationAction(ISD::FROUNDEVEN, MVT::f64, Expand);
10901094
setOperationAction(ISD::FNEARBYINT, MVT::f64, Expand);
10911095
setOperationAction(ISD::FFLOOR, MVT::f64, Expand);
10921096
setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom);
@@ -1534,6 +1538,7 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM,
15341538
setOperationAction(ISD::FTRUNC, MVT::f32, Legal);
15351539
setOperationAction(ISD::FNEARBYINT, MVT::f32, Legal);
15361540
setOperationAction(ISD::FRINT, MVT::f32, Legal);
1541+
setOperationAction(ISD::FROUNDEVEN, MVT::f32, Legal);
15371542
setOperationAction(ISD::FMINNUM, MVT::f32, Legal);
15381543
setOperationAction(ISD::FMAXNUM, MVT::f32, Legal);
15391544
if (Subtarget->hasNEON()) {
@@ -1550,6 +1555,7 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM,
15501555
setOperationAction(ISD::FTRUNC, MVT::f64, Legal);
15511556
setOperationAction(ISD::FNEARBYINT, MVT::f64, Legal);
15521557
setOperationAction(ISD::FRINT, MVT::f64, Legal);
1558+
setOperationAction(ISD::FROUNDEVEN, MVT::f64, Legal);
15531559
setOperationAction(ISD::FMINNUM, MVT::f64, Legal);
15541560
setOperationAction(ISD::FMAXNUM, MVT::f64, Legal);
15551561
}

llvm/lib/Target/ARM/ARMInstrVFP.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,14 @@ multiclass vrint_inst_zrx<string opc, bit op, bit op2, SDPatternOperator node> {
10931093
Requires<[HasFPARMv8,HasDPVFP]>;
10941094
}
10951095

1096+
def frint_or_froundeven : PatFrags<(ops node:$src), [
1097+
(frint node:$src),
1098+
(any_froundeven node:$src)
1099+
]>;
1100+
10961101
defm VRINTZ : vrint_inst_zrx<"z", 0, 1, ftrunc>;
10971102
defm VRINTR : vrint_inst_zrx<"r", 0, 0, fnearbyint>;
1098-
defm VRINTX : vrint_inst_zrx<"x", 1, 0, frint>;
1103+
defm VRINTX : vrint_inst_zrx<"x", 1, 0, frint_or_froundeven>;
10991104

11001105
multiclass vrint_inst_anpm<string opc, bits<2> rm,
11011106
SDPatternOperator node = null_frag> {

llvm/test/CodeGen/ARM/arm32-rounding.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ entry:
104104
ret double %call
105105
}
106106

107+
; CHECK-LABEL: test13
108+
; CHECK: b roundevenf
109+
define float @test13(float %a) {
110+
entry:
111+
%round = call float @llvm.roundeven.f32(float %a)
112+
ret float %round
113+
}
114+
115+
; CHECK-LABEL: test14
116+
; CHECK: b roundeven
117+
define double @test14(double %a) {
118+
entry:
119+
%round = call double @llvm.roundeven.f64(double %a)
120+
ret double %round
121+
}
122+
107123
declare float @floorf(float) nounwind readnone
108124
declare double @floor(double) nounwind readnone
109125
declare float @ceilf(float) nounwind readnone
@@ -116,3 +132,5 @@ declare float @nearbyintf(float) nounwind readnone
116132
declare double @nearbyint(double) nounwind readnone
117133
declare float @rintf(float) nounwind readnone
118134
declare double @rint(double) nounwind readnone
135+
declare float @llvm.roundeven.f32(float)
136+
declare double @llvm.roundeven.f64(double)

llvm/test/CodeGen/ARM/frintn.ll

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
; RUN: llc -mtriple=armv8 -mattr=+neon %s -o - | FileCheck %s
2+
3+
; The llvm.arm.neon.frintn intrinsic should be auto-upgraded to the
4+
; target-independent roundeven intrinsic.
5+
6+
define <4 x half> @frintn_4h(<4 x half> %A) nounwind {
7+
;CHECK-LABEL: frintn_4h:
8+
;CHECK: bl llvm.arm.neon.frintn.v4f16
9+
%tmp3 = call <4 x half> @llvm.arm.neon.frintn.v4f16(<4 x half> %A)
10+
ret <4 x half> %tmp3
11+
}
12+
13+
define <2 x float> @frintn_2s(<2 x float> %A) nounwind {
14+
;CHECK-LABEL: frintn_2s:
15+
;CHECK: bl llvm.arm.neon.frintn.v2f32
16+
%tmp3 = call <2 x float> @llvm.arm.neon.frintn.v2f32(<2 x float> %A)
17+
ret <2 x float> %tmp3
18+
}
19+
20+
define <4 x float> @frintn_4s(<4 x float> %A) nounwind {
21+
;CHECK-LABEL: frintn_4s:
22+
;CHECK: bl llvm.arm.neon.frintn.v4f32
23+
%tmp3 = call <4 x float> @llvm.arm.neon.frintn.v4f32(<4 x float> %A)
24+
ret <4 x float> %tmp3
25+
}
26+
27+
define <2 x double> @frintn_2d(<2 x double> %A) nounwind {
28+
;CHECK-LABEL: frintn_2d:
29+
;CHECK: bl llvm.arm.neon.frintn.v2f64
30+
%tmp3 = call <2 x double> @llvm.arm.neon.frintn.v2f64(<2 x double> %A)
31+
ret <2 x double> %tmp3
32+
}
33+
34+
declare <4 x half> @llvm.arm.neon.frintn.v4f16(<4 x half>) nounwind readnone
35+
declare <2 x float> @llvm.arm.neon.frintn.v2f32(<2 x float>) nounwind readnone
36+
declare <4 x float> @llvm.arm.neon.frintn.v4f32(<4 x float>) nounwind readnone
37+
declare <2 x double> @llvm.arm.neon.frintn.v2f64(<2 x double>) nounwind readnone
38+
39+
define <4 x half> @roundeven_4h(<4 x half> %A) nounwind {
40+
;CHECK-LABEL: roundeven_4h:
41+
;CHECK: vcvtb.f16.f32 s0, s0
42+
;CHECK: vmov r1, s0
43+
;CHECK: vcvtb.f16.f32 s0, s18
44+
;CHECK: vcvtb.f16.f32 s2, s16
45+
;CHECK: vmov r2, s2
46+
;CHECK: pkhbt r0, r1, r0, lsl #16
47+
;CHECK: vmov r1, s0
48+
;CHECK: pkhbt r1, r2, r1, lsl #16
49+
;CHECK: vmov d16, r1, r0
50+
%tmp3 = call <4 x half> @llvm.roundeven.v4f16(<4 x half> %A)
51+
ret <4 x half> %tmp3
52+
}
53+
54+
define <2 x float> @roundeven_2s(<2 x float> %A) nounwind {
55+
;CHECK-LABEL: roundeven_2s:
56+
;CHECK: bl roundevenf
57+
;CHECK: bl roundevenf
58+
%tmp3 = call <2 x float> @llvm.roundeven.v2f32(<2 x float> %A)
59+
ret <2 x float> %tmp3
60+
}
61+
62+
define <4 x float> @roundeven_4s(<4 x float> %A) nounwind {
63+
;CHECK-LABEL: roundeven_4s:
64+
;CHECK: bl roundevenf
65+
;CHECK: bl roundevenf
66+
;CHECK: bl roundevenf
67+
;CHECK: bl roundevenf
68+
%tmp3 = call <4 x float> @llvm.roundeven.v4f32(<4 x float> %A)
69+
ret <4 x float> %tmp3
70+
}
71+
72+
define <2 x double> @roundeven_2d(<2 x double> %A) nounwind {
73+
;CHECK-LABEL: roundeven_2d:
74+
;CHECK: bl roundeven
75+
;CHECK: bl roundeven
76+
%tmp3 = call <2 x double> @llvm.roundeven.v2f64(<2 x double> %A)
77+
ret <2 x double> %tmp3
78+
}
79+
80+
declare <4 x half> @llvm.roundeven.v4f16(<4 x half>) nounwind readnone
81+
declare <2 x float> @llvm.roundeven.v2f32(<2 x float>) nounwind readnone
82+
declare <4 x float> @llvm.roundeven.v4f32(<4 x float>) nounwind readnone
83+
declare <2 x double> @llvm.roundeven.v2f64(<2 x double>) nounwind readnone

0 commit comments

Comments
 (0)