[clang] [AArch64] Change the coercion type of structs with pointer members. (PR #135064)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 9 11:37:34 PDT 2025


================
@@ -485,6 +485,24 @@ ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType Ty, bool IsVariadicFn,
     }
     Size = llvm::alignTo(Size, Alignment);
 
+    // If the Aggregate is made up of pointers, use an array of pointers for the
+    // coerced type. This prevents having to convert ptr2int->int2ptr through
+    // the call, allowing alias analysis to produce better code.
+    if (const RecordType *RT = Ty->getAs<RecordType>()) {
+      if (const RecordDecl *RD = RT->getDecl()) {
+        if (all_of(RD->fields(), [](FieldDecl *FD) {
+              return FD->getType()->isPointerOrReferenceType();
----------------
efriedma-quic wrote:

Correctly collecting all the relevant information is much more complicated than this, in general.  See ABIInfo::isHomogeneousAggregate.  This mostly results in missed optimizations, probably, but I'm concerned this could impact correctness in some C++ corner cases.

You also need to worry about pointers that aren't 64 bits wide.

Please add some testcases for unions. (I don't care if we're conservative for now, just make sure it doesn't explode.)

https://github.com/llvm/llvm-project/pull/135064


More information about the cfe-commits mailing list