Author: Yashas Andaluri
Date: 2026-11-12T20:13:07Z
New Revision: 267deae940034d617a2778d41438661b04c4e297

URL: 
https://github.com/llvm/llvm-project/commit/267deae940034d617a2778d41438661b04c4e297
DIFF: 
https://github.com/llvm/llvm-project/commit/267deae940034d617a2778d41438661b04c4e297.diff

LOG: [Hexagon] Return HLX vectors in registers (#242014)

With HLX enabled, functions returning an HLX vector or vector pair
returned it indirectly through memory. Mark these returns inreg, as is
done for HVX vectors, so that they are returned in HLX registers.

Assisted by AI

Added: 
    clang/test/CodeGen/hexagon-hlx-return-inreg.c

Modified: 
    clang/lib/CodeGen/Targets/Hexagon.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/Targets/Hexagon.cpp 
b/clang/lib/CodeGen/Targets/Hexagon.cpp
index 5a3ce689bbfb4..0fdc1de4e5146 100644
--- a/clang/lib/CodeGen/Targets/Hexagon.cpp
+++ b/clang/lib/CodeGen/Targets/Hexagon.cpp
@@ -151,6 +151,12 @@ ABIArgInfo HexagonABIInfo::classifyReturnType(QualType 
RetTy) const {
       if (Size == VecSize || Size == 2*VecSize)
         return ABIArgInfo::getDirectInReg();
     }
+    // HLX vectors are returned in HLX registers or register pairs.
+    if (T.hasFeature("hlx")) {
+      uint64_t VecSize = 2048 * 8;
+      if (Size == VecSize || Size == 2 * VecSize)
+        return ABIArgInfo::getDirectInReg();
+    }
     // Large vector types should be returned via memory.
     if (Size > 64)
       return getNaturalAlignIndirect(RetTy,

diff  --git a/clang/test/CodeGen/hexagon-hlx-return-inreg.c 
b/clang/test/CodeGen/hexagon-hlx-return-inreg.c
new file mode 100644
index 0000000000000..846ac19588239
--- /dev/null
+++ b/clang/test/CodeGen/hexagon-hlx-return-inreg.c
@@ -0,0 +1,20 @@
+// REQUIRES: hexagon-registered-target
+// RUN: %clang_cc1 -triple hexagon -target-cpu hexagonv85 -target-feature +hlx 
\
+// RUN:   -emit-llvm %s -o - | FileCheck %s
+
+// HLX vectors and vector pairs are returned in HLX registers, not via memory.
+
+typedef short HLX_Vector __attribute__((__vector_size__(2048))) 
__attribute__((aligned(2048)));
+typedef long HLX_VectorPair __attribute__((__vector_size__(4096))) 
__attribute__((aligned(2048)));
+
+// CHECK: define dso_local inreg <1024 x i16> @hlx_add
+// CHECK: ret <1024 x i16>
+HLX_Vector hlx_add(HLX_Vector a, HLX_Vector b) {
+  return a + b;
+}
+
+// CHECK: define dso_local inreg <1024 x i32> @hlx_pair_add
+// CHECK: ret <1024 x i32>
+HLX_VectorPair hlx_pair_add(HLX_VectorPair a, HLX_VectorPair b) {
+  return a + b;
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to