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

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 2 07:55:29 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-selectiondag

Author: Nikita Popov (nikic)

<details>
<summary>Changes</summary>

Usually attributes that are missing on the call-site are inherited form the callee instead. This is fine for optional optimization attributes, but problematic for ABI-affecting attributes.

ABI attributes generally must be placed at the call-site as well, because there is no callee to inherit from for indirect calls. Failing to specify ABI attributes at the call-site generally indicates a bug.

The motivation for being stricter about this (apart from just being the right thing to do) is to properly support cases where the attributes at the call-site and the callee actually differ. Two examples I'm aware of are:

 * During cross-language LTO, it's possible to have one side use a `ptr` argument and the other a `ptr byval(ptr)` argument. Both represent the same ABI using different IR encodings, but you can't just inherit the `byval` attribute from one to the other (because the byval case requires an additional level of indirect in use of the argument).
 * To fix our incompatibility with the x86-64 psABI, I believe we'll want to do something like emit zeroext/signext at function returns and call-site arguments only, so that we both don't assume incoming values are zero/sign-extended, but still zero/sign-extend outgoing values. This makes sure we still remain compatible with old Clang-generated object files.

We've attempted to make a change like this previously, but ran into substantial issues with missing call-site attributes on compiler-inserted calls. The issue was particularly severed on s390x, which requires zeroext/signext on more values than other architectures. I believe that the situation here has approved a lot in the meantime, with libcalls not inferring mandatory ABI attributes, and s390x also using a noext attribute plus validation logic in the backend to detect cases where the necessary attributes are missing.

-----

ABI attributes on call-sites must be queried using `hasABIParamAttr()` and `hasABIRetAttr()` instead of `paramHasAttr()` and `hasRetAttr()` now. Passing an ABI attribute to the latter two will result in an assertion failure.

---

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


56 Files Affected:

- (modified) llvm/include/llvm/CodeGen/FastISel.h (+6-6) 
- (modified) llvm/include/llvm/CodeGen/TargetLowering.h (+3-3) 
- (modified) llvm/include/llvm/IR/Attributes.h (+3) 
- (modified) llvm/include/llvm/IR/InstrTypes.h (+34-38) 
- (modified) llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/GlobalISel/CallLowering.cpp (+5-4) 
- (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 (+22) 
- (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 (+3-3) 
- (modified) llvm/lib/Target/ARM/ARMFastISel.cpp (+8-8) 
- (modified) llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (+1-1) 
- (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 (+8-8) 
- (modified) llvm/lib/Transforms/Utils/CallPromotionUtils.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/InlineFunction.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/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 (+2-3) 
- (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 (+5-21) 
- (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/ExecutionEngine/Orc/IndirectionUtilsTest.cpp (+2-2) 
- (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 454ed4126213f..2075ad7818e0e 100644
--- a/llvm/include/llvm/CodeGen/FastISel.h
+++ b/llvm/include/llvm/CodeGen/FastISel.h
@@ -107,12 +107,12 @@ class LLVM_ABI FastISel {
       RetTy = ResultTy;
       Callee = Target;
 
-      IsInReg = Call.hasRetAttr(Attribute::InReg);
+      IsInReg = Call.hasABIRetAttr(Attribute::InReg);
       DoesNotReturn = Call.doesNotReturn();
       IsVarArg = FuncTy->isVarArg();
       IsReturnValueUsed = !Call.use_empty();
-      RetSExt = Call.hasRetAttr(Attribute::SExt);
-      RetZExt = Call.hasRetAttr(Attribute::ZExt);
+      RetSExt = Call.hasABIRetAttr(Attribute::SExt);
+      RetZExt = Call.hasABIRetAttr(Attribute::ZExt);
 
       CallConv = Call.getCallingConv();
       Args = std::move(ArgsList);
@@ -131,12 +131,12 @@ class LLVM_ABI FastISel {
       Callee = Call.getCalledOperand();
       Symbol = Target;
 
-      IsInReg = Call.hasRetAttr(Attribute::InReg);
+      IsInReg = Call.hasABIRetAttr(Attribute::InReg);
       DoesNotReturn = Call.doesNotReturn();
       IsVarArg = FuncTy->isVarArg();
       IsReturnValueUsed = !Call.use_empty();
-      RetSExt = Call.hasRetAttr(Attribute::SExt);
-      RetZExt = Call.hasRetAttr(Attribute::ZExt);
+      RetSExt = Call.hasABIRetAttr(Attribute::SExt);
+      RetZExt = Call.hasABIRetAttr(Attribute::ZExt);
 
       CallConv = Call.getCallingConv();
       Args = std::move(ArgsList);
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index 09f522742da4e..6f7bfaba61dc5 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -4931,14 +4931,14 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
                                 const CallBase &Call) {
       RetTy = OrigRetTy = ResultType;
 
-      IsInReg = Call.hasRetAttr(Attribute::InReg);
+      IsInReg = Call.hasABIRetAttr(Attribute::InReg);
       DoesNotReturn =
           Call.doesNotReturn() ||
           (!isa<InvokeInst>(Call) && isa<UnreachableInst>(Call.getNextNode()));
       IsVarArg = FTy->isVarArg();
       IsReturnValueUsed = !Call.use_empty();
-      RetSExt = Call.hasRetAttr(Attribute::SExt);
-      RetZExt = Call.hasRetAttr(Attribute::ZExt);
+      RetSExt = Call.hasABIRetAttr(Attribute::SExt);
+      RetZExt = Call.hasABIRetAttr(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 049f699b2980b..73dceab6cd751 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -160,6 +160,9 @@ 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/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 5f7df6a4eb6f8..8d3ff9c996daa 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1658,6 +1658,7 @@ 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.
@@ -1687,6 +1688,22 @@ 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);
@@ -1776,20 +1793,20 @@ class CallBase : public Instruction {
 
   /// Determine whether this argument is passed by value.
   bool isByValArgument(unsigned ArgNo) const {
-    return paramHasAttr(ArgNo, Attribute::ByVal);
+    return hasABIParamAttr(ArgNo, Attribute::ByVal);
   }
 
   /// Determine whether this argument is passed in an alloca.
   bool isInAllocaArgument(unsigned ArgNo) const {
-    return paramHasAttr(ArgNo, Attribute::InAlloca);
+    return hasABIParamAttr(ArgNo, Attribute::InAlloca);
   }
 
   /// Determine whether this argument is passed by value, in an alloca, or is
   /// preallocated.
   bool isPassPointeeByValueArgument(unsigned ArgNo) const {
-    return paramHasAttr(ArgNo, Attribute::ByVal) ||
-           paramHasAttr(ArgNo, Attribute::InAlloca) ||
-           paramHasAttr(ArgNo, Attribute::Preallocated);
+    return hasABIParamAttr(ArgNo, Attribute::ByVal) ||
+           hasABIParamAttr(ArgNo, Attribute::InAlloca) ||
+           hasABIParamAttr(ArgNo, Attribute::Preallocated);
   }
 
   /// Determine whether passing undef to this argument is undefined behavior.
@@ -1806,7 +1823,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() && paramHasAttr(arg_size() - 1, Attribute::InAlloca);
+    return !arg_empty() && hasABIParamAttr(arg_size() - 1, Attribute::InAlloca);
   }
 
   // FIXME: Once this API is no longer duplicated in `CallSite`, rename this to
@@ -1852,49 +1869,29 @@ class CallBase : public Instruction {
     return Attrs.getParamStackAlignment(ArgNo);
   }
 
-  /// Extract the byref type for a call or parameter.
+  /// Extract the byref type for a call argument.
   Type *getParamByRefType(unsigned ArgNo) const {
-    if (auto *Ty = Attrs.getParamByRefType(ArgNo))
-      return Ty;
-    if (const Function *F = getCalledFunction())
-      return F->getAttributes().getParamByRefType(ArgNo);
-    return nullptr;
+    return Attrs.getParamByRefType(ArgNo);
   }
 
-  /// Extract the byval type for a call or parameter.
+  /// Extract the byval type for a call argument.
   Type *getParamByValType(unsigned ArgNo) const {
-    if (auto *Ty = Attrs.getParamByValType(ArgNo))
-      return Ty;
-    if (const Function *F = getCalledFunction())
-      return F->getAttributes().getParamByValType(ArgNo);
-    return nullptr;
+    return Attrs.getParamByValType(ArgNo);
   }
 
-  /// Extract the preallocated type for a call or parameter.
+  /// Extract the preallocated type for a call argument.
   Type *getParamPreallocatedType(unsigned ArgNo) const {
-    if (auto *Ty = Attrs.getParamPreallocatedType(ArgNo))
-      return Ty;
-    if (const Function *F = getCalledFunction())
-      return F->getAttributes().getParamPreallocatedType(ArgNo);
-    return nullptr;
+    return Attrs.getParamPreallocatedType(ArgNo);
   }
 
-  /// Extract the inalloca type for a call or parameter.
+  /// Extract the inalloca type for a call argument.
   Type *getParamInAllocaType(unsigned ArgNo) const {
-    if (auto *Ty = Attrs.getParamInAllocaType(ArgNo))
-      return Ty;
-    if (const Function *F = getCalledFunction())
-      return F->getAttributes().getParamInAllocaType(ArgNo);
-    return nullptr;
+    return Attrs.getParamInAllocaType(ArgNo);
   }
 
-  /// Extract the sret type for a call or parameter.
+  /// Extract the sret type for a call argument.
   Type *getParamStructRetType(unsigned ArgNo) const {
-    if (auto *Ty = Attrs.getParamStructRetType(ArgNo))
-      return Ty;
-    if (const Function *F = getCalledFunction())
-      return F->getAttributes().getParamStructRetType(ArgNo);
-    return nullptr;
+    return Attrs.getParamStructRetType(ArgNo);
   }
 
   /// Extract the elementtype type for a parameter.
@@ -2043,8 +2040,7 @@ class CallBase : public Instruction {
     if (arg_empty())
       return false;
 
-    // Be friendly and also check the callee.
-    return paramHasAttr(0, Attribute::StructRet);
+    return hasABIParamAttr(0, Attribute::StructRet);
   }
 
   /// Determine if any call argument is an aggregate passed by value.
diff --git a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
index 4aebb4b9f37f6..0fe20977bc77e 100644
--- a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
+++ b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
@@ -2288,7 +2288,7 @@ static AssignmentTrackingLowering::OverlapMap buildOverlapMapAndRecordDeclares(
             CB->paramHasAttr(ArgIdx, Attribute::ReadNone))
           continue;
         // Skip byval args.  The callee gets a copy, not the original.
-        if (CB->paramHasAttr(ArgIdx, Attribute::ByVal))
+        if (CB->isByValArgument(ArgIdx))
           continue;
 
         auto *AI = dyn_cast<AllocaInst>(getUnderlyingObject(Arg));
diff --git a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
index a580b78462453..2993036697b6d 100644
--- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
@@ -84,8 +84,11 @@ ISD::ArgFlagsTy CallLowering::getAttributesForArgIdx(const CallBase &Call,
   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));
+  if (const Function *F = Call.getCalledFunction()) {
+    // "returned" is not an ABI attribute, so we can inherit it from the callee.
+    if (F->hasParamAttribute(ArgIdx, Attribute::Returned))
+      Flags.setReturned();
+  }
   return Flags;
 }
 
@@ -93,8 +96,6 @@ 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;
 }
 
diff --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
index 6ca0592644a08..7f9776fda5c0b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
@@ -73,8 +73,8 @@ static ISD::NodeType getPreferredExtendForValue(const Instruction *I) {
       if (!CallI->isArgOperand(&U))
         continue;
       unsigned ArgNo = CallI->getArgOperandNo(&U);
-      NumOfUnsigned += CallI->paramHasAttr(ArgNo, Attribute::ZExt);
-      NumOfSigned += CallI->paramHasAttr(ArgNo, Attribute::SExt);
+      NumOfUnsigned += CallI->hasABIParamAttr(ArgNo, Attribute::ZExt);
+      NumOfSigned += CallI->hasABIParamAttr(ArgNo, Attribute::SExt);
     }
   }
   if (NumOfSigned > NumOfUnsigned)
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 00153ef66cf2c..d2e95e14e70df 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -119,19 +119,19 @@ bool TargetLowering::parametersInCSRMatch(const MachineRegisterInfo &MRI,
 /// and called function attributes.
 void TargetLoweringBase::ArgListEntry::setAttributes(const CallBase *Call,
                                                      unsigned ArgIdx) {
-  IsSExt = Call->paramHasAttr(ArgIdx, Attribute::SExt);
-  IsZExt = Call->paramHasAttr(ArgIdx, Attribute::ZExt);
-  IsNoExt = Call->paramHasAttr(ArgIdx, Attribute::NoExt);
-  IsInReg = Call->paramHasAttr(ArgIdx, Attribute::InReg);
-  IsSRet = Call->paramHasAttr(ArgIdx, Attribute::StructRet);
-  IsNest = Call->paramHasAttr(ArgIdx, Attribute::Nest);
-  IsByVal = Call->paramHasAttr(ArgIdx, Attribute::ByVal);
-  IsPreallocated = Call->paramHasAttr(ArgIdx, Attribute::Preallocated);
-  IsInAlloca = Call->paramHasAttr(ArgIdx, Attribute::InAlloca);
+  IsSExt = Call->hasABIParamAttr(ArgIdx, Attribute::SExt);
+  IsZExt = Call->hasABIParamAttr(ArgIdx, Attribute::ZExt);
+  IsNoExt = Call->hasABIParamAttr(ArgIdx, Attribute::NoExt);
+  IsInReg = Call->hasABIParamAttr(ArgIdx, Attribute::InReg);
+  IsSRet = Call->hasABIParamAttr(ArgIdx, Attribute::StructRet);
+  IsNest = Call->hasABIParamAttr(ArgIdx, Attribute::Nest);
+  IsByVal = Call->hasABIParamAttr(ArgIdx, Attribute::ByVal);
+  IsPreallocated = Call->hasABIParamAttr(ArgIdx, Attribute::Preallocated);
+  IsInAlloca = Call->hasABIParamAttr(ArgIdx, Attribute::InAlloca);
   IsReturned = Call->paramHasAttr(ArgIdx, Attribute::Returned);
-  IsSwiftSelf = Call->paramHasAttr(ArgIdx, Attribute::SwiftSelf);
-  IsSwiftAsync = Call->paramHasAttr(ArgIdx, Attribute::SwiftAsync);
-  IsSwiftError = Call->paramHasAttr(ArgIdx, Attribute::SwiftError);
+  IsSwiftSelf = Call->hasABIParamAttr(ArgIdx, Attribute::SwiftSelf);
+  IsSwiftAsync = Call->hasABIParamAttr(ArgIdx, Attribute::SwiftAsync);
+  IsSwiftError = Call->hasABIParamAttr(ArgIdx, Attribute::SwiftError);
   Alignment = Call->getParamStackAlign(ArgIdx);
   IndirectType = nullptr;
   assert(IsByVal + IsPreallocated + IsInAlloca + IsSRet <= 1 &&
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp b/llvm/lib/CodeGen/TypePromotion.cpp
index 77f82b3851904..82f68611d318b 100644
--- a/llvm/lib/CodeGen/TypePromotion.cpp
+++ b/llvm/lib/CodeGen/TypePromotion.cpp
@@ -237,7 +237,7 @@ bool TypePromotionImpl::isSource(Value *V) {
   else if (isa<LoadInst>(V))
     return true;
   else if (auto *Call = dyn_cast<CallInst>(V))
-    return Call->hasRetAttr(Attribute::AttrKind::ZExt);
+    return Call->hasABIRetAttr(Attribute::AttrKind::ZExt);
   else if (auto *Trunc = dyn_cast<TruncInst>(V))
     return EqualTypeSize(Trunc);
   return false;
@@ -759,7 +759,7 @@ bool TypePromotionImpl::isSupportedValue(Value *V) {
       // can still be sinks.
       auto *Call = cast<CallInst>(I);
       return isSupportedType(Call) &&
-             Call->hasRetAttr(Attribute::AttrKind::ZExt);
+             Call->hasABIRetAttr(Attribute::AttrKind::ZExt);
     }
     }
   } else if (isa<Constant>(V) && !isa<ConstantExpr>(V)) {
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 4087b25951a1c..0f9f0c572b2c7 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -842,6 +842,28 @@ bool Attribute::canUseAsRetAttr(AttrKind Kind) {
   return hasAttributeProperty(Kind, AttributeProperty::RetAttr);
 }
 
+bool Attribute::isABIAttr(AttrKind Kind) {
+  switch (Kind) {
+  case Attribute::ByRef:
+  case Attribute::ByVal:
+  case Attribute::InAlloca:
+  case Attribute::InReg:
+  case Attribute::Nest:
+  case Attribute::NoExt:
+  case Attribute::Preallocated:
+  case Attribute::SExt:
+  case Attribute::StackAlignment:
+  case Attribute::StructRet:
+  case Attribute::SwiftAsync:
+  case Attribute::SwiftError:
+  case Attribute::SwiftSelf:
+  case Attribute::ZExt:
+    return true;
+  default:
+    return false;
+  }
+}
+
 static bool hasIntersectProperty(Attribute::AttrKind Kind,
                                  AttributeProperty Prop) {
   assert((Prop == AttributeProperty::IntersectPreserve ||
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index faa046729aff6..94f164cca2c16 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -415,6 +415,7 @@ Value *CallBase::getArgOperandWithAttribute(Attribute::AttrKind Kind) const {
 /// Determine whether the argument or parameter has the given attribute.
 bool CallBase::paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
   assert(ArgNo < arg_size() && "Param index out of bounds!");
+  assert(!Attribute::isABIAttr(Kind) && "Use hasABIParamAttr() instead");
 
   if (Attrs.hasParamAttr(ArgNo, Kind))
     return true;
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 5f8b5e187bf14..a3a3bc35783c5 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3861,7 +3861,7 @@ void Verifier::visitCallBase(CallBase &Call) {
   // make sure the underlying alloca/parameter it comes from has a swifterror as
   // well.
   for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
-    if (Call.paramHasAttr(i, Attribute::SwiftError)) {
+    if (Call.hasABIParamAttr(i, Attribute::SwiftError)) {
       Value *SwiftErrorArg = Call.getArgOperand(i);
       if (auto AI = dyn_cast<AllocaInst>(SwiftErrorArg->stripInBoundsOffsets())) {
         Check(AI->isSwiftError(),
@@ -3905,7 +3905,7 @@ void Verifier::visitCallBase(CallBase &Call) {
       }
     }
 
-    if (Call.paramHasAttr(i, Attribute::Preallocated)) {
+    if (Call.hasABIParamAttr(i, Attribute::Preallocated)) {
       Value *ArgVal = Call.getArgOperand(i);
       bool hasOB =
           Call.countOperandBundlesOfType(LLVMContext::OB_preallocated) != 0;
@@ -4586,7 +4586,7 @@ void Verifier::verifySwiftErrorCall(CallBase &Call,
                                     const Value *SwiftErrorVal) {
   for (const auto &I : llvm::enumerate(Call.args())) {
     if (I.value() == SwiftErrorVal) {
-      Check(Call.paramHasAttr(I.index(), Attribute::SwiftError),
+      Check(Call.hasABIParamAttr(I.index(), Attribute::SwiftError),
             "swifterror value when used in a callsite should be marked "
             "with swifterror attribute",
             SwiftErrorVal, Call);
@@ -6214,7 +6214,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
         FoundCall = true;
         size_t NumPreallocatedArgs = 0;
         for (unsigned i = 0; i < UseCall->arg_size(); i++) {
-          if (UseCall->paramHasAttr(i, Attribute::Preallocated)) {
+          if (UseCall->hasABIParamAttr(i, Attribute::Preallocated)) {
             ++NumPreallocatedArgs;
           }
         }
diff --git a/llvm/lib/IR/VerifierAMDGPU.cpp b/llvm/lib/IR/VerifierAMDGPU.cpp
index 04cb214ef2520..503cef418d335 100644
--- a/llvm/lib/IR/VerifierAMDGPU.cpp
+++ b/llvm/lib/IR/VerifierAMDGPU.cpp
@@ -171,9 +171,9 @@ void llvm::verifyAMDGPUIntrinsicCall(VerifierSupport &VS, Intrinsic::ID ID,
       break;
     }
 
-    Check(Call.paramHasAttr(2, Attribute::InReg),
+    Check(Call.hasABIParamAttr(2, Attribute::InReg),
           "SGPR arguments must have the `inreg` attribute", &Call);
-    Check(!Call.paramHasAttr(3, Attribute::InReg),
+    Check(!Call.hasABIParamAttr(3, Attribute::InReg),
           "VGPR arguments must not have the `inreg` attribute", &Call);
 
     ConstantInt *FlagsArg = cast<ConstantInt>(Call.getArgOperand(4));
@@ -211,7 +211,7 @@ void llvm::verifyAMDGPUIntrinsicCall(VerifierSupport &VS, Intrinsic::ID ID,
     }
 
     unsigned InactiveIdx = 1;
-    Check(!Call.paramHasAttr(InactiveIdx, Attribute::InReg),
+    Check(!Call.hasABIParamAttr(InactiveIdx, Attribute::InReg),
           "Value for inactive lanes must not have the `inreg` attribute",
           &Call);
     Check(isa<Argument>(Call.getArgOperand(InactiveIdx)),
@@ -241,7 +241,7 @@ void llvm::verifyAMDGPUIntrinsicCall(VerifierSupport &VS, Intrinsic::ID ID,
       Check(CallArg->getType() == FuncArg.getType(),
             "Argument types must match", &Call);
 
-      Check(Call.paramHasAttr(FuncArg.getArgNo(), Attribute::InReg) ==
+      Check(Call.hasABIParamAttr(FuncArg.getArgNo(), Attribute::InReg) ==
                 FuncArg.hasInRegAttr(),
             "Argument inreg attributes must match", &Call);
     }
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
index 3ae1ae40ca34a..15ee8906810de 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
@@ -3356,10 +3356,10 @@ bool isArgPassedInSGPR(const CallBase *CB, unsigned ArgNo) {
   case CallingConv::AMDG...
[truncated]

``````````

</details>


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


More information about the llvm-commits mailing list