[llvm] a6aa47a - [GlobalISel] Avoid unnecessary call setup work (NFC) (#221892)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 05:24:40 PDT 2026


Author: Cullen Rhodes
Date: 2026-09-09T13:24:36+01:00
New Revision: a6aa47a28dcffa1197fd42cd5b61cc8d5693e0f7

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

LOG: [GlobalISel] Avoid unnecessary call setup work (NFC) (#221892)

Avoid processing call-site attributes twice: once in the attribute
helpers (now dead and deleted) and again in setArgFlags. Let setArgFlags
handle the call-site attributes. Also skip return setup for void calls.

Small -0.03% geomean improvement on CTMark aarch64-O0-g, but consistent
little improvements across the board.

https://llvm-compile-time-tracker.com/compare.php?from=97cbc1e404b980edc58bfbcabb6f1c61793b624b&to=d2dfca2db156c259a66cfe2c749f786fec2946f0&stat=instructions:u

Assisted-by: codex

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h
    llvm/lib/CodeGen/GlobalISel/CallLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h b/llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h
index 110f40a817770..60dc219387cbc 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h
@@ -364,14 +364,6 @@ 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/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
index eedb70b6ac522..f8193fdd86a78 100644
--- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
@@ -99,26 +99,6 @@ 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()) {
-    // "returned" is not an ABI attribute, so we can inherit it from the callee.
-    if (F->hasParamAttribute(ArgIdx, Attribute::Returned))
-      Flags.setReturned();
-  }
-  return Flags;
-}
-
-ISD::ArgFlagsTy
-CallLowering::getAttributesForReturn(const CallBase &Call) const {
-  ISD::ArgFlagsTy Flags;
-  addFlagsFromAttrSet(Flags, Call.getAttributes().getRetAttrs());
-  return Flags;
-}
-
 void CallLowering::addArgFlagsFromAttributes(ISD::ArgFlagsTy &Flags,
                                              const AttributeList &Attrs,
                                              unsigned OpIdx) const {
@@ -145,10 +125,15 @@ 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();
 
-  SmallVector<BaseArgInfo, 4> SplitArgs;
-  getReturnInfo(CallConv, RetTy, CB.getAttributes(), SplitArgs, DL);
-  Info.CanLowerReturn = canLowerReturn(MF, CallConv, SplitArgs, IsVarArg);
+  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);
+  }
 
   Info.IsConvergent = CB.isConvergent();
 
@@ -167,7 +152,11 @@ bool CallLowering::lowerCall(MachineIRBuilder &MIRBuilder, const CallBase &CB,
   unsigned i = 0;
   unsigned NumFixedArgs = CB.getFunctionType()->getNumParams();
   for (const auto &Arg : CB.args()) {
-    ArgInfo OrigArg{ArgRegs[i], *Arg.get(), i, getAttributesForArgIdx(CB, i)};
+    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};
     setArgFlags(OrigArg, i + AttributeList::FirstArgIndex, DL, CB);
     if (i >= NumFixedArgs)
       OrigArg.Flags[0].setVarArg();
@@ -211,7 +200,8 @@ bool CallLowering::lowerCall(MachineIRBuilder &MIRBuilder, const CallBase &CB,
   Register ReturnHintAlignReg;
   Align ReturnHintAlign;
 
-  Info.OrigRet = ArgInfo{ResRegs, RetTy, 0, getAttributesForReturn(CB)};
+  ISD::ArgFlagsTy RetFlags;
+  Info.OrigRet = ArgInfo{ResRegs, RetTy, 0, RetFlags};
 
   if (!Info.OrigRet.Ty->isVoidTy()) {
     setArgFlags(Info.OrigRet, AttributeList::ReturnIndex, DL, CB);


        


More information about the llvm-commits mailing list