[PATCH] D110719: [Mangler] Calculate the argument list byte count suffix correctly when returning large values

Wesley Wiser via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 29 08:07:47 PDT 2021


wesleywiser created this revision.
wesleywiser added a reviewer: rnk.
Herald added subscribers: dexonsmith, pengfei, hiraditya.
wesleywiser requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

`__stdcall`, `__fastcall` and `__vectorcall` return large values via a hidden pointer argument. However, the size of that argument should not be included in the argument list byte count suffix added to the function's decorated name.

This patch fixes that issue so that LLVM generates the same decorated name as MSVC does.

MSVC example: https://godbolt.org/z/nc35MKPhr


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110719

Files:
  llvm/lib/IR/Mangler.cpp
  llvm/test/CodeGen/X86/stdcall.ll
  llvm/test/CodeGen/X86/vectorcall.ll


Index: llvm/test/CodeGen/X86/vectorcall.ll
===================================================================
--- llvm/test/CodeGen/X86/vectorcall.ll
+++ llvm/test/CodeGen/X86/vectorcall.ll
@@ -172,8 +172,7 @@
 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i1)
 
 define x86_vectorcallcc void @test_mixed_7(%struct.HVA5* noalias sret(%struct.HVA5) %agg.result) {
-; X86-LABEL: test_mixed_7@@4
-; X64-LABEL: test_mixed_7@@8
+; CHECK-LABEL: test_mixed_7@@0
 ; X64:         mov{{[ql]}}	%rcx, %rax
 ; CHECK:       movaps	%xmm{{[0-9]}}, 64(%{{rcx|eax}})
 ; CHECK:       movaps	%xmm{{[0-9]}}, 48(%{{rcx|eax}})
Index: llvm/test/CodeGen/X86/stdcall.ll
===================================================================
--- llvm/test/CodeGen/X86/stdcall.ll
+++ llvm/test/CodeGen/X86/stdcall.ll
@@ -18,6 +18,21 @@
   ret i32 %a
 }
 
+%struct.large_type = type { i64, i64, i64 }
+
+define x86_stdcallcc void @ReturnLargeType(%struct.large_type* noalias nocapture sret(%struct.large_type) align 8 %agg.result) {
+; CHECK: ReturnLargeType at 0:
+; CHECK: retl
+entry:
+  %a = getelementptr inbounds %struct.large_type, %struct.large_type* %agg.result, i32 0, i32 0
+  store i64 123, i64* %a, align 8
+  %b = getelementptr inbounds %struct.large_type, %struct.large_type* %agg.result, i32 0, i32 1
+  store i64 456, i64* %b, align 8
+  %c = getelementptr inbounds %struct.large_type, %struct.large_type* %agg.result, i32 0, i32 2
+  store i64 789, i64* %c, align 8
+  ret void
+}
+
 @B = global %0 { void (...)* bitcast (void ()* @MyFunc to void (...)*) }, align 4
 ; CHECK: _B:
 ; CHECK: .long _MyFunc at 0
Index: llvm/lib/IR/Mangler.cpp
===================================================================
--- llvm/lib/IR/Mangler.cpp
+++ llvm/lib/IR/Mangler.cpp
@@ -99,6 +99,11 @@
   const unsigned PtrSize = DL.getPointerSize();
 
   for (const Argument &A : F->args()) {
+    // For the purposes of the byte count suffix, structs returned by pointer
+    // do not count as function arguments.
+    if (A.hasStructRetAttr())
+      continue;
+
     // 'Dereference' type in case of byval or inalloca parameter attribute.
     uint64_t AllocSize = A.hasPassPointeeByValueCopyAttr() ?
       A.getPassPointeeByValueCopySize(DL) :


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110719.375885.patch
Type: text/x-patch
Size: 2261 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210929/c497d309/attachment.bin>


More information about the llvm-commits mailing list