diff options
author | Johannes Doerfert <johannes@jdoerfert.de> | 2020-01-25 20:21:41 -0600 |
---|---|---|
committer | Johannes Doerfert <johannes@jdoerfert.de> | 2020-02-10 01:11:32 -0600 |
commit | 87ddf1f4fad01bccb70f10a3ee5c5ad5b20e4de4 (patch) | |
tree | b729a144d30c64aada852cd13cc6e5f79a9f1dfa /llvm/lib | |
parent | 1c0ebcca6edd977194efbccb7b6c35777439bcd3 (diff) | |
download | llvm-87ddf1f4fad01bccb70f10a3ee5c5ad5b20e4de4.zip llvm-87ddf1f4fad01bccb70f10a3ee5c5ad5b20e4de4.tar.gz llvm-87ddf1f4fad01bccb70f10a3ee5c5ad5b20e4de4.tar.bz2 |
[Attributor] Simple casts preserve no-alias property
This is a minimal but important advancement over the existing code. A
cast with an operand that is only used in the cast retains the no-alias
property of the operand.
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/IPO/Attributor.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 91eb561..31a7e93 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -2496,13 +2496,29 @@ struct AANoAliasFloating final : AANoAliasImpl { /// See AbstractAttribute::initialize(...). void initialize(Attributor &A) override { AANoAliasImpl::initialize(A); - Value &Val = getAssociatedValue(); + Value *Val = &getAssociatedValue(); + do { + CastInst *CI = dyn_cast<CastInst>(Val); + if (!CI) + break; + Value *Base = CI->getOperand(0); + if (Base->getNumUses() != 1) + break; + Val = Base; + } while (true); + if (isa<AllocaInst>(Val)) indicateOptimisticFixpoint(); else if (isa<ConstantPointerNull>(Val) && !NullPointerIsDefined(getAnchorScope(), - Val.getType()->getPointerAddressSpace())) + Val->getType()->getPointerAddressSpace())) indicateOptimisticFixpoint(); + else if (Val != &getAssociatedValue()) { + const auto &ValNoAliasAA = + A.getAAFor<AANoAlias>(*this, IRPosition::value(*Val)); + if (ValNoAliasAA.isKnownNoAlias()) + indicateOptimisticFixpoint(); + } } /// See AbstractAttribute::updateImpl(...). |