[PowerPC] Fix rounding mode for vec_round in altivec.h
authorNemanja Ivanovic <nemanja.i.ibm@gmail.com>
Mon, 12 Jul 2021 10:49:12 +0000 (05:49 -0500)
committerNemanja Ivanovic <nemanja.i.ibm@gmail.com>
Mon, 12 Jul 2021 11:11:27 +0000 (06:11 -0500)
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
clang/test/CodeGen/builtins-ppc-vsx.c

index c916017..35dde82 100644 (file)
@@ -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__
index b5ddd03..e1341dc 100644 (file)
@@ -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>