[PATCH] D31598: [SCEV] Try to get RHS from sext in implication via operations
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 3 06:16:42 PDT 2017
mkazantsev created this revision.
Herald added a subscriber: mzolotukhin.
When proving implication via operations and LHS was taken from sext, it makes sense to try
to take RHS from extension also in case of type sizes mismatch.
https://reviews.llvm.org/D31598
Files:
lib/Analysis/ScalarEvolution.cpp
Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -8617,17 +8617,23 @@
// going to compare the operands to RHS, we should be certain that we don't
// need any size extensions for this. So let's decline all cases when the
// sizes of types of LHS and RHS do not match.
- // TODO: Maybe try to get RHS from sext to catch more cases?
- if (getTypeSizeInBits(LHS->getType()) != getTypeSizeInBits(RHS->getType()))
+ auto *LTy = LHS->getType();
+ // If RHS has a wider type, there is a chance that RHS can be stripped from
+ // extension.
+ if (getTypeSizeInBits(LTy) < getTypeSizeInBits(RHS->getType()))
+ RHS = GetOpFromSExt(RHS);
+
+ // If the sizes still don't match, there is nothing we can do.
+ if (getTypeSizeInBits(LTy) != getTypeSizeInBits(RHS->getType()))
return false;
// Should not overflow.
if (!LHSAddExpr->hasNoSignedWrap())
return false;
auto *LL = LHSAddExpr->getOperand(0);
auto *LR = LHSAddExpr->getOperand(1);
- auto *MinusOne = getNegativeSCEV(getOne(RHS->getType()));
+ auto *MinusOne = getNegativeSCEV(getOne(LTy));
// Checks that S1 >= 0 && S2 > RHS, trivially or using the found context.
auto IsSumGreaterThanRHS = [&](const SCEV *S1, const SCEV *S2) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31598.93849.patch
Type: text/x-patch
Size: 1408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170403/b7bc9530/attachment.bin>
More information about the llvm-commits
mailing list