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

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 00:01:59 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-globalisel

Author: Cullen Rhodes (c-rhodes)

<details>
<summary>Changes</summary>

Avoid processing call-site attributes twice: once in the attribute helpers (now dead and deleted) and again in setArgFlags. Initialize flags from callee attributes only and 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

---
Full diff: https://github.com/llvm/llvm-project/pull/221892.diff


2 Files Affected:

- (modified) llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h (-8) 
- (modified) llvm/lib/CodeGen/GlobalISel/CallLowering.cpp (+16-24) 


``````````diff
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 90a0791a04e06..7566c766656bb 100644
--- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
@@ -99,25 +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())
-    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 {
@@ -144,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();
 
@@ -166,7 +152,10 @@ 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;
+    if (Callee)
+      addFlagsFromAttrSet(Flags, Callee->getAttributes().getParamAttrs(i));
+    ArgInfo OrigArg{ArgRegs[i], *Arg.get(), i, Flags};
     setArgFlags(OrigArg, i + AttributeList::FirstArgIndex, DL, CB);
     if (i >= NumFixedArgs)
       OrigArg.Flags[0].setVarArg();
@@ -210,7 +199,10 @@ bool CallLowering::lowerCall(MachineIRBuilder &MIRBuilder, const CallBase &CB,
   Register ReturnHintAlignReg;
   Align ReturnHintAlign;
 
-  Info.OrigRet = ArgInfo{ResRegs, RetTy, 0, getAttributesForReturn(CB)};
+  ISD::ArgFlagsTy RetFlags;
+  if (Callee)
+    addFlagsFromAttrSet(RetFlags, Callee->getAttributes().getRetAttrs());
+  Info.OrigRet = ArgInfo{ResRegs, RetTy, 0, RetFlags};
 
   if (!Info.OrigRet.Ty->isVoidTy()) {
     setArgFlags(Info.OrigRet, AttributeList::ReturnIndex, DL, CB);

``````````

</details>


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


More information about the llvm-commits mailing list