diff options
author | Florian Hahn <flo@fhahn.com> | 2023-11-23 11:35:21 +0000 |
---|---|---|
committer | Florian Hahn <flo@fhahn.com> | 2023-11-23 11:35:21 +0000 |
commit | 19e6d541889f24e21c7a9a6e021aeb82efd4dcb2 (patch) | |
tree | a8658fb0d430a5df4f238c94c9dfaad8f5b0cc32 /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
parent | 0d9f557b6c36da3aa92daff4c0d37ea821d7ae1e (diff) | |
download | llvm-19e6d541889f24e21c7a9a6e021aeb82efd4dcb2.zip llvm-19e6d541889f24e21c7a9a6e021aeb82efd4dcb2.tar.gz llvm-19e6d541889f24e21c7a9a6e021aeb82efd4dcb2.tar.bz2 |
[LV] Re-use existing compare if possible for diff checks.
SCEV simplifying the subtraction may result in redundant compares that
are all OR'd together. Keep track of the generated operands in
SeenCompares, with the key being the pair of operands for the compare.
If we alrady generated the same compare previously, skip it.
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index 85e28ea..acce8d1 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1787,17 +1787,28 @@ Value *llvm::addDiffRuntimeChecks( // Our instructions might fold to a constant. Value *MemoryRuntimeCheck = nullptr; + auto &SE = *Expander.getSE(); + // Map to keep track of created compares, The key is the pair of operands for + // the compare, to allow detecting and re-using redundant compares. + DenseMap<std::pair<Value *, Value *>, Value *> SeenCompares; for (const auto &C : Checks) { Type *Ty = C.SinkStart->getType(); // Compute VF * IC * AccessSize. auto *VFTimesUFTimesSize = ChkBuilder.CreateMul(GetVF(ChkBuilder, Ty->getScalarSizeInBits()), ConstantInt::get(Ty, IC * C.AccessSize)); - auto &SE = *Expander.getSE(); Value *Diff = Expander.expandCodeFor( SE.getMinusSCEV(C.SinkStart, C.SrcStart), Ty, Loc); - Value *IsConflict = + + // Check if the same compare has already been created earlier. In that case, + // there is no need to check it again. + Value *IsConflict = SeenCompares.lookup({Diff, VFTimesUFTimesSize}); + if (IsConflict) + continue; + + IsConflict = ChkBuilder.CreateICmpULT(Diff, VFTimesUFTimesSize, "diff.check"); + SeenCompares.insert({{Diff, VFTimesUFTimesSize}, IsConflict}); if (C.NeedsFreeze) IsConflict = ChkBuilder.CreateFreeze(IsConflict, IsConflict->getName() + ".fr"); |