diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-14 21:24:36 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-18 23:07:50 +0100 |
commit | 70e3c9a8b6684c49576aee38b5c90b18fdf00d2c (patch) | |
tree | b764e454cfb95873dab2fa482b3825ab0c56f1e2 /llvm/lib/IR/Value.cpp | |
parent | b006902b2dfac792e8ade73798ca1b216654faf7 (diff) | |
download | llvm-70e3c9a8b6684c49576aee38b5c90b18fdf00d2c.zip llvm-70e3c9a8b6684c49576aee38b5c90b18fdf00d2c.tar.gz llvm-70e3c9a8b6684c49576aee38b5c90b18fdf00d2c.tar.bz2 |
[BasicAA] Always strip single-argument phi nodes
We can always look through single-argument (LCSSA) phi nodes when
performing alias analysis. getUnderlyingObject() already does this,
but stripPointerCastsAndInvariantGroups() does not. We still look
through these phi nodes with the usual aliasPhi() logic, but
sometimes get sub-optimal results due to the restrictions on value
equivalence when looking through arbitrary phi nodes. I think it's
generally beneficial to keep the underlying object logic and the
pointer cast stripping logic in sync, insofar as it is possible.
With this patch we get marginally better results:
aa.NumMayAlias | 5010069 | 5009861
aa.NumMustAlias | 347518 | 347674
aa.NumNoAlias | 27201336 | 27201528
...
licm.NumPromoted | 1293 | 1296
I've renamed the relevant strip method to stripPointerCastsForAliasAnalysis(),
as we're past the point where we can explicitly spell out everything
that's getting stripped.
Differential Revision: https://reviews.llvm.org/D96668
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r-- | llvm/lib/IR/Value.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 572f37a..92ffae1 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -551,7 +551,7 @@ enum PointerStripKind { PSK_ZeroIndices, PSK_ZeroIndicesAndAliases, PSK_ZeroIndicesSameRepresentation, - PSK_ZeroIndicesAndInvariantGroups, + PSK_ForAliasAnalysis, PSK_InBoundsConstantIndices, PSK_InBounds }; @@ -577,7 +577,7 @@ static const Value *stripPointerCastsAndOffsets( case PSK_ZeroIndices: case PSK_ZeroIndicesAndAliases: case PSK_ZeroIndicesSameRepresentation: - case PSK_ZeroIndicesAndInvariantGroups: + case PSK_ForAliasAnalysis: if (!GEP->hasAllZeroIndices()) return V; break; @@ -602,6 +602,9 @@ static const Value *stripPointerCastsAndOffsets( V = cast<Operator>(V)->getOperand(0); } else if (StripKind == PSK_ZeroIndicesAndAliases && isa<GlobalAlias>(V)) { V = cast<GlobalAlias>(V)->getAliasee(); + } else if (StripKind == PSK_ForAliasAnalysis && isa<PHINode>(V) && + cast<PHINode>(V)->getNumIncomingValues() == 1) { + V = cast<PHINode>(V)->getIncomingValue(0); } else { if (const auto *Call = dyn_cast<CallBase>(V)) { if (const Value *RV = Call->getReturnedArgOperand()) { @@ -611,7 +614,7 @@ static const Value *stripPointerCastsAndOffsets( // The result of launder.invariant.group must alias it's argument, // but it can't be marked with returned attribute, that's why it needs // special case. - if (StripKind == PSK_ZeroIndicesAndInvariantGroups && + if (StripKind == PSK_ForAliasAnalysis && (Call->getIntrinsicID() == Intrinsic::launder_invariant_group || Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) { V = Call->getArgOperand(0); @@ -643,8 +646,8 @@ const Value *Value::stripInBoundsConstantOffsets() const { return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(this); } -const Value *Value::stripPointerCastsAndInvariantGroups() const { - return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndInvariantGroups>(this); +const Value *Value::stripPointerCastsForAliasAnalysis() const { + return stripPointerCastsAndOffsets<PSK_ForAliasAnalysis>(this); } const Value *Value::stripAndAccumulateConstantOffsets( |