https://github.com/phoebewang created 
https://github.com/llvm/llvm-project/pull/205040

Fixes: #203760

Assisted-by: Claude Sonnet 4.6

>From afc371bbe15bf87b96ec434a6cb396262c746041 Mon Sep 17 00:00:00 2001
From: Phoebe Wang <[email protected]>
Date: Sun, 21 Jun 2026 23:48:37 -0700
Subject: [PATCH] [clang] Exclude EmptyRecord calculating larger CXX records

Fixes: #203760

Assisted-by: Claude Sonnet 4.6
---
 clang/lib/CodeGen/Targets/X86.cpp         |  1 +
 clang/test/CodeGen/X86/avx-cxx-record.cpp | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index dbe4d656aabc5..abf903647336d 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2085,6 +2085,7 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
         Lo = merge(Lo, FieldLo);
         Hi = merge(Hi, FieldHi);
         if (returnCXXRecordGreaterThan128InMem() &&
+            !isEmptyRecord(getContext(), I.getType(), true) &&
             (Size > 128 && (Size != getContext().getTypeSize(I.getType()) ||
                             Size > getNativeVectorSizeForAVXABI(AVXLevel)))) {
           // The only case a 256(or 512)-bit wide vector could be used to 
return
diff --git a/clang/test/CodeGen/X86/avx-cxx-record.cpp 
b/clang/test/CodeGen/X86/avx-cxx-record.cpp
index b20bcdd616a43..e64cef32e78ec 100644
--- a/clang/test/CodeGen/X86/avx-cxx-record.cpp
+++ b/clang/test/CodeGen/X86/avx-cxx-record.cpp
@@ -46,3 +46,21 @@ YMM2 bar() {
   ((YMM1<1>*)&result)->x = UInt64x4{5, 6, 7, 8};
   return result;
 }
+
+// Test that empty base classes do not prevent structs with a single wide
+// vector member from being passed/returned in registers (issue #203760).
+struct EmptyBase {};
+
+struct YMMWithEmptyBase : EmptyBase {
+    UInt64x4 x;
+};
+
+// A struct with a single 256-bit vector and an empty base should use 
registers,
+// matching the behavior with no base class.
+// CHECK: define{{.*}} <4 x i64> @_Z18ymm_empty_base_retv()
+// CLANG-20: define{{.*}} <4 x i64> @_Z18ymm_empty_base_retv()
+YMMWithEmptyBase ymm_empty_base_ret() { return {}; }
+
+// CHECK: define{{.*}} i64 @_Z19ymm_empty_base_pass16YMMWithEmptyBase(<4 x i64>
+// CLANG-20: define{{.*}} i64 @_Z19ymm_empty_base_pass16YMMWithEmptyBase(<4 x 
i64>
+unsigned long long ymm_empty_base_pass(YMMWithEmptyBase x) { return x.x[0]; }

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

Reply via email to