[llvm] Count CallInst Arguments Attributes to reduce unnecessary extension (PR #73501)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 28 00:12:57 PST 2023


================
@@ -64,11 +64,19 @@ static ISD::NodeType getPreferredExtendForValue(const Instruction *I) {
   // can be exposed.
   ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
   unsigned NumOfSigned = 0, NumOfUnsigned = 0;
-  for (const User *U : I->users()) {
-    if (const auto *CI = dyn_cast<CmpInst>(U)) {
+  for (const Use &U : I->uses()) {
+    if (const auto *CI = dyn_cast<CmpInst>(U.getUser())) {
       NumOfSigned += CI->isSigned();
       NumOfUnsigned += CI->isUnsigned();
     }
+    if (const auto *CallI = dyn_cast<CallBase>(U.getUser())) {
+      const AttributeList &PAL = CallI->getAttributes();
+      AttributeSet Attrs = PAL.getParamAttrs(U.getOperandNo());
+      if (Attrs.hasAttributes()) {
+        NumOfUnsigned += Attrs.hasAttribute(Attribute::ZExt);
----------------
nikic wrote:

```suggestion
        NumOfUnsigned += CallI->paramHasAttr(ArgNo, Attribute::ZExt);
```
Use the APIs on CallBase instead of accessing attributes directly. This will properly handle attribute inheritance.

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


More information about the llvm-commits mailing list