Skip to content

Commit e86efbb

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

File tree

5 files changed

+104
-2
lines changed

5 files changed

+104
-2
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ multiclass vrint_inst_anpm<string opc, bits<2> rm,
11361136
}
11371137

11381138
defm VRINTA : vrint_inst_anpm<"a", 0b00, fround>;
1139-
defm VRINTN : vrint_inst_anpm<"n", 0b01, int_arm_neon_vrintn>;
1139+
defm VRINTN : vrint_inst_anpm<"n", 0b01, any_froundeven>;
11401140
defm VRINTP : vrint_inst_anpm<"p", 0b10, fceil>;
11411141
defm VRINTM : vrint_inst_anpm<"m", 0b11, ffloor>;
11421142

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: vrintn.f32
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: vrintn.f64
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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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: vrintn.f32 s2, s2
43+
;CHECK: vmov r0, s0
44+
;CHECK: vcvtb.f16.f32 s2, s2
45+
%tmp3 = call <4 x half> @llvm.roundeven.v4f16(<4 x half> %A)
46+
ret <4 x half> %tmp3
47+
}
48+
49+
define <2 x float> @roundeven_2s(<2 x float> %A) nounwind {
50+
;CHECK-LABEL: roundeven_2s:
51+
;CHECK: vrintn.f32 s3, s1
52+
;CHECK: vrintn.f32 s2, s0
53+
%tmp3 = call <2 x float> @llvm.roundeven.v2f32(<2 x float> %A)
54+
ret <2 x float> %tmp3
55+
}
56+
57+
define <4 x float> @roundeven_4s(<4 x float> %A) nounwind {
58+
;CHECK-LABEL: roundeven_4s:
59+
;CHECK: vrintn.f32 s7, s3
60+
;CHECK: vrintn.f32 s6, s2
61+
;CHECK: vrintn.f32 s5, s1
62+
;CHECK: vrintn.f32 s4, s0
63+
%tmp3 = call <4 x float> @llvm.roundeven.v4f32(<4 x float> %A)
64+
ret <4 x float> %tmp3
65+
}
66+
67+
define <2 x double> @roundeven_2d(<2 x double> %A) nounwind {
68+
;CHECK-LABEL: roundeven_2d:
69+
;CHECK: vrintn.f64 d16, d16
70+
;CHECK: vrintn.f64 d17, d17
71+
%tmp3 = call <2 x double> @llvm.roundeven.v2f64(<2 x double> %A)
72+
ret <2 x double> %tmp3
73+
}
74+
75+
declare <4 x half> @llvm.roundeven.v4f16(<4 x half>) nounwind readnone
76+
declare <2 x float> @llvm.roundeven.v2f32(<2 x float>) nounwind readnone
77+
declare <4 x float> @llvm.roundeven.v4f32(<4 x float>) nounwind readnone
78+
declare <2 x double> @llvm.roundeven.v2f64(<2 x double>) nounwind readnone

llvm/test/CodeGen/Thumb2/bf16-instructions.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ define bfloat @test_roundeven(bfloat %a) {
23732373
; CHECK-FP-NEXT: vmov r0, s0
23742374
; CHECK-FP-NEXT: lsls r0, r0, #16
23752375
; CHECK-FP-NEXT: vmov s0, r0
2376-
; CHECK-FP-NEXT: bl roundevenf
2376+
; CHECK-FP-NEXT: vrintn.f32 s0, s0
23772377
; CHECK-FP-NEXT: bl __truncsfbf2
23782378
; CHECK-FP-NEXT: vmov.f16 r0, s0
23792379
; CHECK-FP-NEXT: vmov s0, r0

0 commit comments

Comments
 (0)