[clang] [llvm] [Inliner] Propagate more attributes to params when inlining (PR #91101)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 5 07:17:32 PDT 2024


================
@@ -1381,21 +1405,58 @@ static void AddParamAndFnBasicAttributes(const CallBase &CB,
       AttributeList AL = NewInnerCB->getAttributes();
       for (unsigned I = 0, E = InnerCB->arg_size(); I < E; ++I) {
         // Check if the underlying value for the parameter is an argument.
-        const Value *UnderlyingV =
-            getUnderlyingObject(InnerCB->getArgOperand(I));
-        const Argument *Arg = dyn_cast<Argument>(UnderlyingV);
-        if (!Arg)
-          continue;
+        const Argument *Arg = dyn_cast<Argument>(InnerCB->getArgOperand(I));
+        unsigned ArgNo;
+        if (Arg) {
+          ArgNo = Arg->getArgNo();
+          // For dereferenceable, dereferenceable_or_null, align, etc...
+          // we don't want to propagate if the existing param has the same
+          // attribute with "better" constraints. So, only remove from the
+          // existing AL if the region of the existing param is smaller than
+          // what we can propagate. AttributeList's merge API honours the
+          // already existing attribute value so we choose the "better"
+          // attribute by removing if the existing one is worse.
----------------
nikic wrote:

I think you got this the wrong way around? If you use addAttribute() you will always overwrite the new attribute, not keep the existing one.

Looking at your tests, you do indeed decrease alignment in some cases, e.g. prop_param_deref_align_no_update.

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


More information about the cfe-commits mailing list