[llvm] Revert [IR] Do not inherit ABI attributes from the callee (PR #222384)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 09:53:20 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-webassembly

@llvm/pr-subscribers-backend-systemz

Author: Nikita Popov (nikic)

<details>
<summary>Changes</summary>

Reverts #<!-- -->207173, plus #<!-- -->221892 due to a merge conflict.

Apparently we have some issues with call-site zeroext/signext on libcalls, see https://github.com/llvm/llvm-project/pull/207173#issuecomment-5604972674.

---

Patch is 73.84 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/222384.diff


56 Files Affected:

- (modified) llvm/include/llvm/CodeGen/FastISel.h (+6-6) 
- (modified) llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h (+8) 
- (modified) llvm/include/llvm/CodeGen/TargetLowering.h (+3-3) 
- (modified) llvm/include/llvm/IR/Attributes.h (-3) 
- (modified) llvm/include/llvm/IR/Attributes.td (+17-20) 
- (modified) llvm/include/llvm/IR/InstrTypes.h (+38-34) 
- (modified) llvm/lib/Analysis/Lint.cpp (+5-6) 
- (modified) llvm/lib/CodeGen/GlobalISel/CallLowering.cpp (+24-15) 
- (modified) llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp (+12-12) 
- (modified) llvm/lib/CodeGen/TypePromotion.cpp (+2-2) 
- (modified) llvm/lib/IR/Attributes.cpp (-5) 
- (modified) llvm/lib/IR/Instructions.cpp (-1) 
- (modified) llvm/lib/IR/Verifier.cpp (+4-4) 
- (modified) llvm/lib/IR/VerifierAMDGPU.cpp (+4-4) 
- (modified) llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp (+2-2) 
- (modified) llvm/lib/Target/ARM/ARMFastISel.cpp (+8-8) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp (+2-2) 
- (modified) llvm/lib/Target/X86/X86FastISel.cpp (+2-2) 
- (modified) llvm/lib/Target/X86/X86ISelLoweringCall.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/ExpandVariadics.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Utils/CallPromotionUtils.cpp (+1-1) 
- (modified) llvm/test/Analysis/BasicAA/call-attrs.ll (+2-2) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/call-translator-tail-call-sret.ll (+6-6) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/call-translator.ll (+8-8) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/swifterror.ll (+2-2) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/swiftself.ll (+2-2) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-return-values.ll (+6-6) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call-sret.ll (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-call.ll (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/fncall-implicitdef.ll (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/swdev504645-global-fold.ll (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/waterfall-call-inreg-agpr.ll (+1-1) 
- (modified) llvm/test/CodeGen/ARM/returned-ext.ll (+2-2) 
- (modified) llvm/test/CodeGen/ARM/struct-byval-loop.ll (+2-2) 
- (modified) llvm/test/CodeGen/M68k/multiple-return.ll (+1-1) 
- (modified) llvm/test/CodeGen/NVPTX/forward-ld-param.ll (+1-1) 
- (modified) llvm/test/CodeGen/RISCV/rvv/shrinkwrap.ll (+2-2) 
- (modified) llvm/test/CodeGen/RISCV/shrinkwrap.ll (+7-7) 
- (modified) llvm/test/CodeGen/SPARC/64abi.ll (+4-4) 
- (modified) llvm/test/CodeGen/SystemZ/args-14.ll (+3-2) 
- (modified) llvm/test/CodeGen/SystemZ/call-zos-01.ll (+4-4) 
- (modified) llvm/test/CodeGen/VE/Scalar/call.ll (+1-1) 
- (modified) llvm/test/CodeGen/VE/Scalar/va_callee.ll (+12-12) 
- (modified) llvm/test/CodeGen/VE/Vector/fastcc_caller.ll (+1-1) 
- (modified) llvm/test/CodeGen/WebAssembly/signext-zeroext-callsite.ll (+21-5) 
- (modified) llvm/test/CodeGen/X86/bool-zext.ll (+1-1) 
- (modified) llvm/test/CodeGen/X86/return-ext.ll (+3-3) 
- (modified) llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll (+1-1) 
- (modified) llvm/test/Transforms/DeadArgElim/deadexternal.ll (+1-1) 
- (modified) llvm/test/Transforms/Inline/access-attributes-prop.ll (+3-3) 
- (modified) llvm/test/Transforms/PhaseOrdering/pr64289-tce.ll (+1-1) 
- (modified) llvm/test/Transforms/SROA/readonlynocapture.ll (+2-2) 
- (modified) llvm/test/Transforms/SimplifyCFG/hoist-sink-swifterror-store.ll (+7-7) 
- (modified) llvm/unittests/IR/AttributesTest.cpp (+5-5) 


``````````diff
diff --git a/llvm/include/llvm/CodeGen/FastISel.h b/llvm/include/llvm/CodeGen/FastISel.h
index 04ad564843116..02d2059d54785 100644
--- a/llvm/include/llvm/CodeGen/FastISel.h
+++ b/llvm/include/llvm/CodeGen/FastISel.h
@@ -108,12 +108,12 @@ class LLVM_ABI FastISel {
       RetTy = ResultTy;
       Callee = Target;
 
-      IsInReg = Call.hasABIRetAttr(Attribute::InReg);
+      IsInReg = Call.hasRetAttr(Attribute::InReg);
       DoesNotReturn = Call.doesNotReturn();
       IsVarArg = FuncTy->isVarArg();
       IsReturnValueUsed = !Call.use_empty();
-      RetSExt = Call.hasABIRetAttr(Attribute::SExt);
-      RetZExt = Call.hasABIRetAttr(Attribute::ZExt);
+      RetSExt = Call.hasRetAttr(Attribute::SExt);
+      RetZExt = Call.hasRetAttr(Attribute::ZExt);
 
       CallConv = Call.getCallingConv();
       Args = std::move(ArgsList);
@@ -132,12 +132,12 @@ class LLVM_ABI FastISel {
       Callee = Call.getCalledOperand();
       Symbol = Target;
 
-      IsInReg = Call.hasABIRetAttr(Attribute::InReg);
+      IsInReg = Call.hasRetAttr(Attribute::InReg);
       DoesNotReturn = Call.doesNotReturn();
       IsVarArg = FuncTy->isVarArg();
       IsReturnValueUsed = !Call.use_empty();
-      RetSExt = Call.hasABIRetAttr(Attribute::SExt);
-      RetZExt = Call.hasABIRetAttr(Attribute::ZExt);
+      RetSExt = Call.hasRetAttr(Attribute::SExt);
+      RetZExt = Call.hasRetAttr(Attribute::ZExt);
 
       CallConv = Call.getCallingConv();
       Args = std::move(ArgsList);
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h b/llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h
index 60dc219387cbc..110f40a817770 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h
@@ -364,6 +364,14 @@ class LLVM_ABI CallLowering {
     return static_cast<const XXXTargetLowering *>(TLI);
   }
 
+  /// \returns Flags corresponding to the attributes on the \p ArgIdx-th
+  /// parameter of \p Call.
+  ISD::ArgFlagsTy getAttributesForArgIdx(const CallBase &Call,
+                                         unsigned ArgIdx) const;
+
+  /// \returns Flags corresponding to the attributes on the return from \p Call.
+  ISD::ArgFlagsTy getAttributesForReturn(const CallBase &Call) const;
+
   /// Adds flags to \p Flags based off of the attributes in \p Attrs.
   /// \p OpIdx is the index in \p Attrs to add flags from.
   void addArgFlagsFromAttributes(ISD::ArgFlagsTy &Flags,
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index 71a8438fd4999..69f5e0e4e3011 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -5060,14 +5060,14 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
                                 const CallBase &Call) {
       RetTy = OrigRetTy = ResultType;
 
-      IsInReg = Call.hasABIRetAttr(Attribute::InReg);
+      IsInReg = Call.hasRetAttr(Attribute::InReg);
       DoesNotReturn =
           Call.doesNotReturn() ||
           (!isa<InvokeInst>(Call) && isa<UnreachableInst>(Call.getNextNode()));
       IsVarArg = FTy->isVarArg();
       IsReturnValueUsed = !Call.use_empty();
-      RetSExt = Call.hasABIRetAttr(Attribute::SExt);
-      RetZExt = Call.hasABIRetAttr(Attribute::ZExt);
+      RetSExt = Call.hasRetAttr(Attribute::SExt);
+      RetZExt = Call.hasRetAttr(Attribute::ZExt);
       NoMerge = Call.hasFnAttr(Attribute::NoMerge);
 
       Callee = Target;
diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h
index d9ab56cdcc1f6..f8185c76dfb5c 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -162,9 +162,6 @@ class Attribute {
   LLVM_ABI static bool intersectWithMin(AttrKind Kind);
   LLVM_ABI static bool intersectWithCustom(AttrKind Kind);
 
-  /// Whether this is an ABI attribute (for returns or arguments).
-  LLVM_ABI static bool isABIAttr(AttrKind Kind);
-
 private:
   AttributeImpl *pImpl = nullptr;
 
diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td
index a649430424b9e..ea523cad69cd5 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -22,8 +22,7 @@ def ParamAttr : AttrProperty;
 /// Can be used as return attribute.
 def RetAttr : AttrProperty;
 
-/// This is an ABI-affecting attribute.
-def ABIAttr : AttrProperty;
+
 
 /// Intersection rules. Used for example in sinking/hoisting two
 /// callbases to find a set of attributes that apply to both.
@@ -46,6 +45,8 @@ def IntersectMin : AttrProperty;
 /// When intersecting rely on some specially defined code.
 def IntersectCustom : AttrProperty;
 
+
+
 /// Attribute base class.
 class Attr<string S, AttrProperty I, list<AttrProperty> P> {
   // String representation of this attribute in the IR.
@@ -102,10 +103,10 @@ def AlwaysInline : EnumAttr<"alwaysinline", IntersectPreserve, [FnAttr]>;
 def Builtin : EnumAttr<"builtin", IntersectPreserve, [FnAttr]>;
 
 /// Pass structure by value.
-def ByVal : TypeAttr<"byval", IntersectPreserve, [ParamAttr, ABIAttr]>;
+def ByVal : TypeAttr<"byval", IntersectPreserve, [ParamAttr]>;
 
 /// Mark in-memory ABI type.
-def ByRef : TypeAttr<"byref", IntersectPreserve, [ParamAttr, ABIAttr]>;
+def ByRef : TypeAttr<"byref", IntersectPreserve, [ParamAttr]>;
 
 /// Parameter or return value may not contain uninitialized or poison bits.
 def NoUndef : EnumAttr<"noundef", IntersectAnd, [ParamAttr, RetAttr]>;
@@ -144,7 +145,7 @@ def FnRetThunkExtern : EnumAttr<"fn_ret_thunk_extern", IntersectPreserve, [FnAtt
 def HybridPatchable : EnumAttr<"hybrid_patchable", IntersectPreserve, [FnAttr]>;
 
 /// Pass structure in an alloca.
-def InAlloca : TypeAttr<"inalloca", IntersectPreserve, [ParamAttr, ABIAttr]>;
+def InAlloca : TypeAttr<"inalloca", IntersectPreserve, [ParamAttr]>;
 
 /// Pointer argument memory is initialized.
 def Initializes : ConstantRangeListAttr<"initializes", IntersectPreserve, [ParamAttr]>;
@@ -153,7 +154,7 @@ def Initializes : ConstantRangeListAttr<"initializes", IntersectPreserve, [Param
 def InlineHint : EnumAttr<"inlinehint", IntersectAnd, [FnAttr]>;
 
 /// Force argument to be passed in register.
-def InReg : EnumAttr<"inreg", IntersectPreserve, [ParamAttr, RetAttr, ABIAttr]>;
+def InReg : EnumAttr<"inreg", IntersectPreserve, [ParamAttr, RetAttr]>;
 
 /// Build jump-instruction tables and replace refs.
 def JumpTable : EnumAttr<"jumptable", IntersectPreserve, [FnAttr]>;
@@ -171,7 +172,7 @@ def MinSize : EnumAttr<"minsize", IntersectPreserve, [FnAttr]>;
 def Naked : EnumAttr<"naked", IntersectPreserve, [FnAttr]>;
 
 /// Nested function static chain.
-def Nest : EnumAttr<"nest", IntersectPreserve, [ParamAttr, ABIAttr]>;
+def Nest : EnumAttr<"nest", IntersectPreserve, [ParamAttr]>;
 
 /// Considered to not alias after call.
 def NoAlias : EnumAttr<"noalias", IntersectAnd, [ParamAttr, RetAttr]>;
@@ -197,7 +198,7 @@ def NoDivergenceSource : EnumAttr<"nodivergencesource", IntersectAnd, [FnAttr]>;
 def NoDuplicate : EnumAttr<"noduplicate", IntersectPreserve, [FnAttr]>;
 
 /// No extension needed before/after call (high bits are undefined).
-def NoExt : EnumAttr<"noext", IntersectPreserve, [ParamAttr, RetAttr, ABIAttr]>;
+def NoExt : EnumAttr<"noext", IntersectPreserve, [ParamAttr, RetAttr]>;
 
 /// Function does not deallocate memory.
 /// Argument cannot be freed based on the argument pointer.
@@ -280,8 +281,7 @@ def OptimizeForSize : EnumAttr<"optsize", IntersectPreserve, [FnAttr]>;
 def OptimizeNone : EnumAttr<"optnone", IntersectPreserve, [FnAttr]>;
 
 /// Similar to byval but without a copy.
-def Preallocated : TypeAttr<"preallocated", IntersectPreserve,
-                            [FnAttr, ParamAttr, ABIAttr]>;
+def Preallocated : TypeAttr<"preallocated", IntersectPreserve, [FnAttr, ParamAttr]>;
 
 /// Parameter or return value is within the specified range.
 def Range : ConstantRangeAttr<"range", IntersectCustom, [ParamAttr, RetAttr]>;
@@ -308,13 +308,11 @@ def SafeStack : EnumAttr<"safestack", IntersectPreserve, [FnAttr]>;
 def ShadowCallStack : EnumAttr<"shadowcallstack", IntersectPreserve, [FnAttr]>;
 
 /// Sign extended before/after call.
-def SExt : EnumAttr<"signext", IntersectPreserve,
-                    [ParamAttr, RetAttr, ABIAttr]>;
+def SExt : EnumAttr<"signext", IntersectPreserve, [ParamAttr, RetAttr]>;
 
 /// Alignment of stack for function (3 bits)  stored as log2 of alignment with
 /// +1 bias 0 means unaligned (different from alignstack=(1)).
-def StackAlignment : IntAttr<"alignstack", IntersectPreserve,
-                             [FnAttr, ParamAttr, RetAttr, ABIAttr]>;
+def StackAlignment : IntAttr<"alignstack", IntersectPreserve, [FnAttr, ParamAttr, RetAttr]>;
 
 /// Function can be speculated.
 def Speculatable : EnumAttr<"speculatable", IntersectAnd, [FnAttr]>;
@@ -332,7 +330,7 @@ def StackProtectStrong : EnumAttr<"sspstrong", IntersectPreserve, [FnAttr]>;
 def StrictFP : EnumAttr<"strictfp", IntersectPreserve, [FnAttr]>;
 
 /// Hidden pointer to structure to return.
-def StructRet : TypeAttr<"sret", IntersectPreserve, [ParamAttr, ABIAttr]>;
+def StructRet : TypeAttr<"sret", IntersectPreserve, [ParamAttr]>;
 
 /// AddressSanitizer is on.
 def SanitizeAddress : EnumAttr<"sanitize_address", IntersectPreserve, [FnAttr]>;
@@ -376,13 +374,13 @@ def SpeculativeLoadHardening : EnumAttr<"speculative_load_hardening",
                                         [FnAttr]>;
 
 /// Argument is swift error.
-def SwiftError : EnumAttr<"swifterror", IntersectPreserve, [ParamAttr, ABIAttr]>;
+def SwiftError : EnumAttr<"swifterror", IntersectPreserve, [ParamAttr]>;
 
 /// Argument is swift self/context.
-def SwiftSelf : EnumAttr<"swiftself", IntersectPreserve, [ParamAttr, ABIAttr]>;
+def SwiftSelf : EnumAttr<"swiftself", IntersectPreserve, [ParamAttr]>;
 
 /// Argument is swift async context.
-def SwiftAsync : EnumAttr<"swiftasync", IntersectPreserve, [ParamAttr, ABIAttr]>;
+def SwiftAsync : EnumAttr<"swiftasync", IntersectPreserve, [ParamAttr]>;
 
 /// Function must be in a unwind table.
 def UWTable : IntAttr<"uwtable", IntersectPreserve, [FnAttr]>;
@@ -400,8 +398,7 @@ def Writable : EnumAttr<"writable", IntersectAnd, [ParamAttr]>;
 def WriteOnly : EnumAttr<"writeonly", IntersectAnd, [ParamAttr]>;
 
 /// Zero extended before/after call.
-def ZExt : EnumAttr<"zeroext", IntersectPreserve,
-                    [ParamAttr, RetAttr, ABIAttr]>;
+def ZExt : EnumAttr<"zeroext", IntersectPreserve, [ParamAttr, RetAttr]>;
 
 /// Function is required to make Forward Progress.
 def MustProgress : EnumAttr<"mustprogress", IntersectAnd, [FnAttr]>;
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 8d3ff9c996daa..5f7df6a4eb6f8 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1658,7 +1658,6 @@ class CallBase : public Instruction {
 
   /// Determine whether the return value has the given attribute.
   bool hasRetAttr(Attribute::AttrKind Kind) const {
-    assert(!Attribute::isABIAttr(Kind) && "Use hasABIRetAttr() instead");
     return hasRetAttrImpl(Kind);
   }
   /// Determine whether the return value has the given attribute.
@@ -1688,22 +1687,6 @@ class CallBase : public Instruction {
   LLVM_ABI bool paramHasNonNullAttr(unsigned ArgNo,
                                     bool AllowUndefOrPoison) const;
 
-  /// Determine whether the argument has the given ABI attribute. As this is
-  /// an ABI attribute, only check the call-site and do not inherit from the
-  /// callee.
-  bool hasABIParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
-    assert(Attribute::isABIAttr(Kind) && "Expected ABI attribute");
-    return Attrs.hasParamAttr(ArgNo, Kind);
-  }
-
-  /// Determine whether the return value has the given ABI attribute. As this
-  /// is an ABI attribute, only check the call-site and do not inherit from the
-  /// callee.
-  bool hasABIRetAttr(Attribute::AttrKind Kind) const {
-    assert(Attribute::isABIAttr(Kind) && "Expected ABI attribute");
-    return Attrs.hasRetAttr(Kind);
-  }
-
   /// Get the attribute of a given kind at a position.
   Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const {
     return getAttributes().getAttributeAtIndex(i, Kind);
@@ -1793,20 +1776,20 @@ class CallBase : public Instruction {
 
   /// Determine whether this argument is passed by value.
   bool isByValArgument(unsigned ArgNo) const {
-    return hasABIParamAttr(ArgNo, Attribute::ByVal);
+    return paramHasAttr(ArgNo, Attribute::ByVal);
   }
 
   /// Determine whether this argument is passed in an alloca.
   bool isInAllocaArgument(unsigned ArgNo) const {
-    return hasABIParamAttr(ArgNo, Attribute::InAlloca);
+    return paramHasAttr(ArgNo, Attribute::InAlloca);
   }
 
   /// Determine whether this argument is passed by value, in an alloca, or is
   /// preallocated.
   bool isPassPointeeByValueArgument(unsigned ArgNo) const {
-    return hasABIParamAttr(ArgNo, Attribute::ByVal) ||
-           hasABIParamAttr(ArgNo, Attribute::InAlloca) ||
-           hasABIParamAttr(ArgNo, Attribute::Preallocated);
+    return paramHasAttr(ArgNo, Attribute::ByVal) ||
+           paramHasAttr(ArgNo, Attribute::InAlloca) ||
+           paramHasAttr(ArgNo, Attribute::Preallocated);
   }
 
   /// Determine whether passing undef to this argument is undefined behavior.
@@ -1823,7 +1806,7 @@ class CallBase : public Instruction {
   /// Determine if there are is an inalloca argument. Only the last argument can
   /// have the inalloca attribute.
   bool hasInAllocaArgument() const {
-    return !arg_empty() && hasABIParamAttr(arg_size() - 1, Attribute::InAlloca);
+    return !arg_empty() && paramHasAttr(arg_size() - 1, Attribute::InAlloca);
   }
 
   // FIXME: Once this API is no longer duplicated in `CallSite`, rename this to
@@ -1869,29 +1852,49 @@ class CallBase : public Instruction {
     return Attrs.getParamStackAlignment(ArgNo);
   }
 
-  /// Extract the byref type for a call argument.
+  /// Extract the byref type for a call or parameter.
   Type *getParamByRefType(unsigned ArgNo) const {
-    return Attrs.getParamByRefType(ArgNo);
+    if (auto *Ty = Attrs.getParamByRefType(ArgNo))
+      return Ty;
+    if (const Function *F = getCalledFunction())
+      return F->getAttributes().getParamByRefType(ArgNo);
+    return nullptr;
   }
 
-  /// Extract the byval type for a call argument.
+  /// Extract the byval type for a call or parameter.
   Type *getParamByValType(unsigned ArgNo) const {
-    return Attrs.getParamByValType(ArgNo);
+    if (auto *Ty = Attrs.getParamByValType(ArgNo))
+      return Ty;
+    if (const Function *F = getCalledFunction())
+      return F->getAttributes().getParamByValType(ArgNo);
+    return nullptr;
   }
 
-  /// Extract the preallocated type for a call argument.
+  /// Extract the preallocated type for a call or parameter.
   Type *getParamPreallocatedType(unsigned ArgNo) const {
-    return Attrs.getParamPreallocatedType(ArgNo);
+    if (auto *Ty = Attrs.getParamPreallocatedType(ArgNo))
+      return Ty;
+    if (const Function *F = getCalledFunction())
+      return F->getAttributes().getParamPreallocatedType(ArgNo);
+    return nullptr;
   }
 
-  /// Extract the inalloca type for a call argument.
+  /// Extract the inalloca type for a call or parameter.
   Type *getParamInAllocaType(unsigned ArgNo) const {
-    return Attrs.getParamInAllocaType(ArgNo);
+    if (auto *Ty = Attrs.getParamInAllocaType(ArgNo))
+      return Ty;
+    if (const Function *F = getCalledFunction())
+      return F->getAttributes().getParamInAllocaType(ArgNo);
+    return nullptr;
   }
 
-  /// Extract the sret type for a call argument.
+  /// Extract the sret type for a call or parameter.
   Type *getParamStructRetType(unsigned ArgNo) const {
-    return Attrs.getParamStructRetType(ArgNo);
+    if (auto *Ty = Attrs.getParamStructRetType(ArgNo))
+      return Ty;
+    if (const Function *F = getCalledFunction())
+      return F->getAttributes().getParamStructRetType(ArgNo);
+    return nullptr;
   }
 
   /// Extract the elementtype type for a parameter.
@@ -2040,7 +2043,8 @@ class CallBase : public Instruction {
     if (arg_empty())
       return false;
 
-    return hasABIParamAttr(0, Attribute::StructRet);
+    // Be friendly and also check the callee.
+    return paramHasAttr(0, Attribute::StructRet);
   }
 
   /// Determine if any call argument is an aggregate passed by value.
diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index 54df723c69e85..26e78826848e7 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -264,13 +264,12 @@ void Lint::visitCallBase(CallBase &I) {
 
         // Check that ABI attributes for the function and call-site match.
         unsigned ArgNo = AI->getOperandNo();
+        Attribute::AttrKind ABIAttributes[] = {
+            Attribute::ZExt,         Attribute::SExt,     Attribute::InReg,
+            Attribute::ByVal,        Attribute::ByRef,    Attribute::InAlloca,
+            Attribute::Preallocated, Attribute::StructRet};
         AttributeList CallAttrs = I.getAttributes();
-        for (Attribute::AttrKind Attr :
-             drop_begin(enum_seq(Attribute::None, Attribute::EndAttrKinds,
-                                 force_iteration_on_noniterable_enum))) {
-          if (!Attribute::isABIAttr(Attr))
-            continue;
-
+        for (Attribute::AttrKind Attr : ABIAttributes) {
           Attribute CallAttr = CallAttrs.getParamAttr(ArgNo, Attr);
           Attribute FnAttr = F->getParamAttribute(ArgNo, Attr);
           Check(CallAttr.isValid() == FnAttr.isValid(),
diff --git a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
index f8193fdd86a78..4d97001eb7420 100644
--- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
@@ -99,6 +99,25 @@ static void addFlagsFromAttrSet(ISD::ArgFlagsTy &Flags, AttributeSet Attrs) {
   }
 }
 
+ISD::ArgFlagsTy CallLowering::getAttributesForArgIdx(const CallBase &Call,
+                                                     unsigned ArgIdx) const {
+  ISD::ArgFlagsTy Flags;
+  const AttributeList &Attrs = Call.getAttributes();
+  addFlagsFromAttrSet(Flags, Attrs.getParamAttrs(ArgIdx));
+  if (const Function *F = Call.getCalledFunction())
+    addFlagsFromAttrSet(Flags, F->getAttributes().getParamAttrs(ArgIdx));
+  return Flags;
+}
+
+ISD::ArgFlagsTy
+CallLowering::getAttributesForReturn(const CallBase &Call) const {
+  ISD::ArgFlagsTy Flags;
+  addFlagsFromAttrSet(Flags, Call.getAttributes().getRetAttrs());
+  if (const Function *F = Call.getCalledFunction())
+    addFlagsFromAttrSet(Flags, F->getAttributes().getRetAttrs());
+  return Flags;
+}
+
 void CallLowering::addArgFlagsFromAttributes(ISD::ArgFlagsTy &Flags,
                                              const AttributeList &Attrs,
                                              unsigned OpIdx) const {
@@ -125,15 +144,10 @@ bool CallLowering::lowerCall(MachineIRBuilder &MIRBuilder, const CallBase &CB,
   CallingConv::ID CallConv = CB.getCallingConv();
   Type *RetTy = CB.getType();
   bool IsVarArg = CB.getFunctionType()->isVarArg();
-  const Function *Callee = CB.getCalledFunction();
 
-  if (RetTy->isVoidTy()) {
-    Info.CanLowerReturn = true;
-  } else {
-    SmallVector<BaseArgInfo, 4> SplitArgs;
-    getReturnInfo(CallConv, RetTy, CB.getAttributes(), SplitArgs, DL);
-    Info.CanLowerReturn = canLowerReturn(MF, CallConv, SplitArgs, IsVarArg);
-  }
+  SmallVector<BaseArgInfo, 4> SplitArgs;
+  getReturnInfo(CallConv, RetTy, CB.getAttributes(), SplitArgs, DL);
+  Info.CanLowerReturn = canLowerReturn(MF, CallConv, SplitArgs, IsVarArg);
 
   Info.IsConvergent = CB.isConvergent();
 
@@ -152,11 +166,7 @@ bool CallLowering::lowerCall(MachineIRBuilder &MIRBuilder, const CallBase &CB,
   unsigned i = 0;
   unsigned NumFixedArgs = CB.getFunctionType()->getNumParams();
   for (const auto &Arg : CB.args()) {
-    ISD::ArgFlagsTy Flags;
-    // "returned" is not an ABI attribute, so we can inherit it from the callee.
-    if (Callee && Callee->hasParamAttribute(i, Attribute::Returned))
-      Flags.setReturned();
-    ArgInfo OrigArg{ArgRegs[i], *Arg.get(), i, Flags};
+    ArgInfo OrigArg{ArgRegs[i], *Arg.get(), i, getAttributesForArgIdx(CB, i)};
     setArgFlags(OrigArg, i + AttributeList::FirstArgIndex, DL, CB);
     if (i >= NumFixedArgs)
...
[truncated]

``````````

</details>


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


More information about the llvm-commits mailing list