Skip to content

[X86_64] fix SSE type error in vaarg. #86377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2024
Merged

[X86_64] fix SSE type error in vaarg. #86377

merged 1 commit into from
Mar 26, 2024

Conversation

CoTinker
Copy link
Contributor

tweak the position of the ++neededSSE when Lo is NoClass and Hi is SSE. Fix #86371.

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:codegen IR generation bugs: mangling, exceptions, etc. labels Mar 23, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 23, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: Longsheng Mou (CoTinker)

Changes

tweak the position of the ++neededSSE when Lo is NoClass and Hi is SSE. Fix #86371.


Full diff: https://github.com/llvm/llvm-project/pull/86377.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/Targets/X86.cpp (+1-2)
  • (modified) clang/test/CodeGenCXX/x86_64-vaarg.cpp (+15)
diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp
index 1ec0f159ebcb8a..6931768147a9b2 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2788,12 +2788,11 @@ X86_64ABIInfo::classifyArgumentType(QualType Ty, unsigned freeIntRegs,
     // memory), except in situations involving unions.
   case X87Up:
   case SSE:
+    ++neededSSE;
     HighPart = GetSSETypeAtOffset(CGT.ConvertType(Ty), 8, Ty, 8);
 
     if (Lo == NoClass)  // Pass HighPart at offset 8 in memory.
       return ABIArgInfo::getDirect(HighPart, 8);
-
-    ++neededSSE;
     break;
 
     // AMD64-ABI 3.2.3p3: Rule 4. If the class is SSEUP, the
diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
index f0177906a09a81..82c32329502816 100644
--- a/clang/test/CodeGenCXX/x86_64-vaarg.cpp
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -21,3 +21,18 @@ empty empty_record_test(int z, ...) {
   __builtin_va_start(list, z);
   return __builtin_va_arg(list, empty);
 }
+
+typedef struct {
+  struct{} a;
+  double b;
+} s1;
+
+// CHECK-LABEL: define{{.*}} double @{{.*}}f
+// CHECK: vaarg.in_reg:
+// CHECK: vaarg.in_mem:
+// CHECK: vaarg.end:
+s1 f(int z, ...) {
+  __builtin_va_list list;
+  __builtin_va_start(list, z);
+  return __builtin_va_arg(list, s1);
+}

@llvmbot
Copy link
Member

llvmbot commented Mar 23, 2024

@llvm/pr-subscribers-clang-codegen

Author: Longsheng Mou (CoTinker)

Changes

tweak the position of the ++neededSSE when Lo is NoClass and Hi is SSE. Fix #86371.


Full diff: https://github.com/llvm/llvm-project/pull/86377.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/Targets/X86.cpp (+1-2)
  • (modified) clang/test/CodeGenCXX/x86_64-vaarg.cpp (+15)
diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp
index 1ec0f159ebcb8a..6931768147a9b2 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2788,12 +2788,11 @@ X86_64ABIInfo::classifyArgumentType(QualType Ty, unsigned freeIntRegs,
     // memory), except in situations involving unions.
   case X87Up:
   case SSE:
+    ++neededSSE;
     HighPart = GetSSETypeAtOffset(CGT.ConvertType(Ty), 8, Ty, 8);
 
     if (Lo == NoClass)  // Pass HighPart at offset 8 in memory.
       return ABIArgInfo::getDirect(HighPart, 8);
-
-    ++neededSSE;
     break;
 
     // AMD64-ABI 3.2.3p3: Rule 4. If the class is SSEUP, the
diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
index f0177906a09a81..82c32329502816 100644
--- a/clang/test/CodeGenCXX/x86_64-vaarg.cpp
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -21,3 +21,18 @@ empty empty_record_test(int z, ...) {
   __builtin_va_start(list, z);
   return __builtin_va_arg(list, empty);
 }
+
+typedef struct {
+  struct{} a;
+  double b;
+} s1;
+
+// CHECK-LABEL: define{{.*}} double @{{.*}}f
+// CHECK: vaarg.in_reg:
+// CHECK: vaarg.in_mem:
+// CHECK: vaarg.end:
+s1 f(int z, ...) {
+  __builtin_va_list list;
+  __builtin_va_start(list, z);
+  return __builtin_va_arg(list, s1);
+}

Copy link

✅ With the latest revision this PR passed the Python code formatter.

Copy link

✅ With the latest revision this PR passed the C/C++ code formatter.

@@ -21,3 +21,18 @@ empty empty_record_test(int z, ...) {
__builtin_va_start(list, z);
return __builtin_va_arg(list, empty);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please regenerate the CHECK lines with update_cc_test_checks.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

tweak the position of the ++neededSSE when Lo is NoClass
and Hi is SSE.
Copy link
Collaborator

@efriedma-quic efriedma-quic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

typedef struct {
struct{} a;
double b;
} s1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is really worth testing... at least, it's not testing anything relevant to this patch. (sizeof(s1)==8.) Up to you, I guess.

@CoTinker
Copy link
Contributor Author

Thanks.

@hstk30-hw hstk30-hw merged commit 9c8dd5e into llvm:main Mar 26, 2024
@CoTinker CoTinker deleted the sse branch March 26, 2024 01:51
@AZero13
Copy link
Contributor

AZero13 commented Mar 26, 2024

/cherry-pick 9c8dd5e

@llvmbot
Copy link
Member

llvmbot commented Mar 26, 2024

/cherry-pick 9c8dd5e

Error: Command failed due to missing milestone.

AZero13 pushed a commit to AZero13/llvm-project that referenced this pull request Mar 26, 2024
tweak the position of the ++neededSSE when Lo is NoClass and Hi is SSE.
Fix llvm#86371.

(cherry picked from commit 9c8dd5e)
AZero13 pushed a commit to AZero13/llvm-project that referenced this pull request Mar 26, 2024
tweak the position of the ++neededSSE when Lo is NoClass and Hi is SSE.
Fix llvm#86371.

(cherry picked from commit 9c8dd5e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[X86_64] va_arg with SSE type get error
5 participants