From 84e429693fe5f225fe68b9dd54043cddb9c4cd4c Mon Sep 17 00:00:00 2001 From: Nemanja Ivanovic Date: Mon, 12 Jul 2021 05:49:12 -0500 Subject: [PATCH] [PowerPC] Fix rounding mode for vec_round in altivec.h The function is supposed to be the equivalent of rint() (as in round to nearest, ties to even) rather than round() (round to nearest, ties away from zero). In fact, the instruction we emit without VSX is vrfin which is correct. However, with VSX we emit xvrspi which is the equivalent of round() and therefore incorrect. Since there is no equivalent VSX instruction, simply use vrfin regardless of availability of VSX. --- clang/lib/Headers/altivec.h | 4 ---- clang/test/CodeGen/builtins-ppc-vsx.c | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h index c916017fad6a..35dde8203b7f 100644 --- a/clang/lib/Headers/altivec.h +++ b/clang/lib/Headers/altivec.h @@ -8386,11 +8386,7 @@ vec_vrlw(vector unsigned int __a, vector unsigned int __b) { /* vec_round */ static __inline__ vector float __ATTRS_o_ai vec_round(vector float __a) { -#ifdef __VSX__ - return __builtin_vsx_xvrspi(__a); -#else return __builtin_altivec_vrfin(__a); -#endif } #ifdef __VSX__ diff --git a/clang/test/CodeGen/builtins-ppc-vsx.c b/clang/test/CodeGen/builtins-ppc-vsx.c index b5ddd03722ad..e1341dc589c5 100644 --- a/clang/test/CodeGen/builtins-ppc-vsx.c +++ b/clang/test/CodeGen/builtins-ppc-vsx.c @@ -407,8 +407,8 @@ void test1() { // CHECK-LE: call <4 x i32> @llvm.ppc.altivec.vperm(<4 x i32> [[T1]], <4 x i32> [[T2]], <16 x i8> res_vf = vec_round(vf); -// CHECK: call <4 x float> @llvm.round.v4f32(<4 x float> -// CHECK-LE: call <4 x float> @llvm.round.v4f32(<4 x float> +// CHECK: call <4 x float> @llvm.ppc.altivec.vrfin(<4 x float> +// CHECK-LE: call <4 x float> @llvm.ppc.altivec.vrfin(<4 x float> res_vd = vec_round(vd); // CHECK: call <2 x double> @llvm.round.v2f64(<2 x double>