[llvm] [Inline][Cloning] Drop incompatible attributes from `NewFunc` before `instSimplify` (PR #90489)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 30 19:32:54 PDT 2024
================
@@ -823,54 +820,48 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
}
}
- // Make a second pass over the PHINodes now that all of them have been
- // remapped into the new function, simplifying the PHINode and performing any
- // recursive simplifications exposed. This will transparently update the
- // WeakTrackingVH in the VMap. Notably, we rely on that so that if we coalesce
- // two PHINodes, the iteration over the old PHIs remains valid, and the
- // mapping will just map us to the new node (which may not even be a PHI
- // node).
+ // Drop all incompatible return attributes that cannot be applied to NewFunc
+ // during cloning, so as to allow instruction simplification to reason on the
+ // old state of the function. The original attributes are restored later.
+ AttributeMask IncompatibleAttrs =
+ AttributeFuncs::typeIncompatible(OldFunc->getReturnType());
+ AttrBuilder RetAttrs(NewFunc->getContext(),
+ NewFunc->getAttributes().getRetAttrs());
----------------
nikic wrote:
This is a bit of a roundabout way to restore the attributes. It would be better to do `AttributeList Attrs = NewFunc->getAttributes();` here and then `NewFunc->setAttributes(Attrs)` below, instead of going through AttrBuilder etc.
https://github.com/llvm/llvm-project/pull/90489
More information about the llvm-commits
mailing list