aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2021-03-09 11:44:43 -0800
committerPhilip Reames <listmail@philipreames.com>2021-03-09 11:52:08 -0800
commitd6394d86cadf20f09cba9c013bfccc277f565212 (patch)
treeaaf725396d45e08309a5f270f0516d29d0160dda /llvm/lib/CodeGen/CodeGenPrepare.cpp
parent34637bbe27d3971025cba02dfd4e52a46024f3d7 (diff)
downloadllvm-d6394d86cadf20f09cba9c013bfccc277f565212.zip
llvm-d6394d86cadf20f09cba9c013bfccc277f565212.tar.gz
llvm-d6394d86cadf20f09cba9c013bfccc277f565212.tar.bz2
[cgp] improve robustness of uadd/usub transforms
LSR prefers to schedule iv increments just before the latch. The recent 80511565 broadened this to moving increments in the original IR. This pointed out a robustness problem with the CGP transform. When we have a use of an induction increment outside of the loop (we canonicalize away from this form, but it happens e.g. unanalyzeable loops) we'd avoid performing the uadd/usub transform. Interestingly, all of these involve moving the increment closer to it's operands, so there's no concern about dominating all uses. We can handle that case cheaply, resulting in a more robust transform.
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index b6fbfa84..9de4261 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -1352,16 +1352,17 @@ bool CodeGenPrepare::replaceMathCmpWithIntrinsic(BinaryOperator *BO,
if (LI->getLoopFor(Cmp->getParent()) != L)
return false;
- // IV increment may have other users than the IV. We do not want to make
- // dominance queries to analyze the legality of moving it towards the cmp,
- // so just check that there is no other users.
- if (!BO->hasOneUse())
- return false;
- // Ultimately, the insertion point must dominate latch. This should be a
- // cheap check because no CFG changes & dom tree recomputation happens
- // during the transform.
- Function *F = BO->getParent()->getParent();
- return getDT(*F).dominates(Cmp->getParent(), L->getLoopLatch());
+ // Finally, we need to ensure that the insert point will dominate all
+ // existing uses of the increment.
+
+ auto &DT = getDT(*BO->getParent()->getParent());
+ if (DT.dominates(Cmp->getParent(), BO->getParent()))
+ // If we're moving up the dom tree, all uses are trivially dominated.
+ // (This is the common case for code produced by LSR.)
+ return true;
+
+ // Otherwise, special case the single use in the phi recurrence.
+ return BO->hasOneUse() && DT.dominates(Cmp->getParent(), L->getLoopLatch());
};
if (BO->getParent() != Cmp->getParent() && !IsReplacableIVIncrement(BO)) {
// We used to use a dominator tree here to allow multi-block optimization.