[clang] Fixed vec_pack_to_short_fp32 in Clang altivec.h (PR #129923)

John Platts via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 5 11:55:41 PST 2025


https://github.com/johnplatts created https://github.com/llvm/llvm-project/pull/129923

Fixes bug in vec_pack_to_short_fp32 in clang/lib/Headers/altivec.h.

Resolves issue #60822

Reviewer: @lei137

>From 0bfa20f7a2deaf61e444404f7418f4571a9d6de4 Mon Sep 17 00:00:00 2001
From: John Platts <john_platts at hotmail.com>
Date: Wed, 5 Mar 2025 13:11:15 -0600
Subject: [PATCH] Fixed vec_pack_to_short_fp32 in Clang altivec.h

---
 clang/lib/Headers/altivec.h | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index 8da65055012f1..45d557238e3d9 100644
--- a/clang/lib/Headers/altivec.h
+++ b/clang/lib/Headers/altivec.h
@@ -7529,13 +7529,9 @@ vec_pack(vector double __a, vector double __b) {
 #ifdef __POWER9_VECTOR__
 static __inline__ vector unsigned short __ATTRS_o_ai
 vec_pack_to_short_fp32(vector float __a, vector float __b) {
-  vector float __resa = __builtin_vsx_xvcvsphp(__a);
-  vector float __resb = __builtin_vsx_xvcvsphp(__b);
-#ifdef __LITTLE_ENDIAN__
-  return (vector unsigned short)vec_mergee(__resa, __resb);
-#else
-  return (vector unsigned short)vec_mergeo(__resa, __resb);
-#endif
+  vector unsigned int __resa = (vector unsigned int)__builtin_vsx_xvcvsphp(__a);
+  vector unsigned int __resb = (vector unsigned int)__builtin_vsx_xvcvsphp(__b);
+  return vec_pack(__resa, __resb);
 }
 
 #endif



More information about the cfe-commits mailing list