[llvm] 649e3e0 - [X86][TTI] Handle structs in areTypesABICompatible() (#205308)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 23 02:57:14 PDT 2026


Author: Nikita Popov
Date: 2026-06-23T11:57:09+02:00
New Revision: 649e3e0e23222418bfbd8a4247875823be71143b

URL: https://github.com/llvm/llvm-project/commit/649e3e0e23222418bfbd8a4247875823be71143b
DIFF: https://github.com/llvm/llvm-project/commit/649e3e0e23222418bfbd8a4247875823be71143b.diff

LOG: [X86][TTI] Handle structs in areTypesABICompatible() (#205308)

Fixes a regression from #205106. getValueType() asserts on aggregate
types. Use CompuateValueVTs() to compute the de-aggregated VTs.

Performing argument promotion for struct types seems pretty
dubious to me, but it was previously allowed, so I'm retaining
that behavior. We may want to disable promotion of aggregates
in ArgPromotion entirely though.

Added: 
    llvm/test/Transforms/ArgumentPromotion/X86/struct-load.ll

Modified: 
    llvm/lib/Target/X86/X86TargetTransformInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
index 6ff621aca79d2..fba2f08912fed 100644
--- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
+++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
@@ -51,6 +51,7 @@
 #include "X86TargetTransformInfo.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/CodeGen/Analysis.h"
 #include "llvm/CodeGen/BasicTTIImpl.h"
 #include "llvm/CodeGen/CostTable.h"
 #include "llvm/CodeGen/TargetLowering.h"
@@ -6775,11 +6776,15 @@ bool X86TTIImpl::areTypesABICompatible(const Function *Caller,
       TM.getSubtargetImpl(*Callee)->getTargetLowering();
 
   LLVMContext &Ctx = Caller->getContext();
+  const DataLayout &DL = Caller->getDataLayout();
   CallingConv::ID CC = Callee->getCallingConv();
   return all_of(Types, [&](Type *Ty) {
-    EVT VT = CallerTLI->getValueType(DL, Ty);
-    return CallerTLI->getRegisterTypeForCallingConv(Ctx, CC, VT) ==
-           CalleeTLI->getRegisterTypeForCallingConv(Ctx, CC, VT);
+    SmallVector<EVT> VTs;
+    ComputeValueVTs(*CallerTLI, DL, Ty, VTs);
+    return all_of(VTs, [&](EVT VT) {
+      return CallerTLI->getRegisterTypeForCallingConv(Ctx, CC, VT) ==
+             CalleeTLI->getRegisterTypeForCallingConv(Ctx, CC, VT);
+    });
   });
 }
 

diff  --git a/llvm/test/Transforms/ArgumentPromotion/X86/struct-load.ll b/llvm/test/Transforms/ArgumentPromotion/X86/struct-load.ll
new file mode 100644
index 0000000000000..72d4239ba4bed
--- /dev/null
+++ b/llvm/test/Transforms/ArgumentPromotion/X86/struct-load.ll
@@ -0,0 +1,24 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -passes=argpromotion < %s | FileCheck %s
+
+target triple = "x86_64-unknown-linux-gnu"
+
+define { i32, i32 } @caller(ptr %p) {
+; CHECK-LABEL: define { i32, i32 } @caller(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[P_VAL:%.*]] = load { i32, i32 }, ptr [[P]], align 4
+; CHECK-NEXT:    [[RES:%.*]] = call { i32, i32 } @callee({ i32, i32 } [[P_VAL]])
+; CHECK-NEXT:    ret { i32, i32 } [[RES]]
+;
+  %res = call { i32, i32 } @callee(ptr %p)
+  ret { i32, i32 } %res
+}
+
+define internal { i32, i32 } @callee(ptr %p) {
+; CHECK-LABEL: define internal { i32, i32 } @callee(
+; CHECK-SAME: { i32, i32 } [[P_0_VAL:%.*]]) {
+; CHECK-NEXT:    ret { i32, i32 } [[P_0_VAL]]
+;
+  %res = load { i32, i32 }, ptr %p
+  ret { i32, i32 } %res
+}


        


More information about the llvm-commits mailing list