|
18 | 18 | #include "llvm/Analysis/DomTreeUpdater.h"
|
19 | 19 | #include "llvm/Analysis/InstructionSimplify.h"
|
20 | 20 | #include "llvm/Analysis/LoopInfo.h"
|
| 21 | +#include "llvm/IR/AttributeMask.h" |
21 | 22 | #include "llvm/IR/CFG.h"
|
22 | 23 | #include "llvm/IR/Constants.h"
|
23 | 24 | #include "llvm/IR/DebugInfo.h"
|
@@ -696,6 +697,16 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
|
696 | 697 | }
|
697 | 698 | }
|
698 | 699 |
|
| 700 | + // Drop all incompatible return attributes that cannot be applied to NewFunc |
| 701 | + // during cloning, so as to allow instruction simplification later to reason |
| 702 | + // on the old state of the function. The original attributes are restored |
| 703 | + // before returning. |
| 704 | + AttributeMask IncompatibleAttrs = |
| 705 | + AttributeFuncs::typeIncompatible(OldFunc->getReturnType()); |
| 706 | + AttrBuilder RetAttrs(NewFunc->getContext(), |
| 707 | + NewFunc->getAttributes().getRetAttrs()); |
| 708 | + NewFunc->removeRetAttrs(IncompatibleAttrs); |
| 709 | + |
699 | 710 | // Clone the entry block, and anything recursively reachable from it.
|
700 | 711 | std::vector<const BasicBlock *> CloneWorklist;
|
701 | 712 | PFC.CloneBlock(StartingBB, StartingInst->getIterator(), CloneWorklist);
|
@@ -849,6 +860,9 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
|
849 | 860 | }
|
850 | 861 | }
|
851 | 862 |
|
| 863 | + // Restore attributes. |
| 864 | + NewFunc->addRetAttrs(RetAttrs); |
| 865 | + |
852 | 866 | // Remap debug intrinsic operands now that all values have been mapped.
|
853 | 867 | // Doing this now (late) preserves use-before-defs in debug intrinsics. If
|
854 | 868 | // we didn't do this, ValueAsMetadata(use-before-def) operands would be
|
|
0 commit comments