aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
diff options
context:
space:
mode:
authorMax Kazantsev <mkazantsev@azul.com>2023-02-10 15:20:03 +0700
committerMax Kazantsev <mkazantsev@azul.com>2023-02-10 15:23:16 +0700
commit79d2c26f89e116e0802aa83989c106bcd95522d4 (patch)
tree301859698ff3ec54db8c22f73a2b45a65eeff272 /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
parent288f688e294a0d2ee162f99f745c06d1e95d3620 (diff)
downloadllvm-79d2c26f89e116e0802aa83989c106bcd95522d4.zip
llvm-79d2c26f89e116e0802aa83989c106bcd95522d4.tar.gz
llvm-79d2c26f89e116e0802aa83989c106bcd95522d4.tar.bz2
[SimplifyIndVar][NFC] Refactor Binary Operator's flag strengthening
Extract complex logic of Binary Operator's flag strengthening to a separate method in order to reuse it. Patch by Aleksandr Popov! Differential Revision: https://reviews.llvm.org/D143562 Reviewed By: mkazantsev
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyIndVar.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index 4e83d2f..1458e61 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -93,6 +93,7 @@ namespace {
void replaceRemWithNumeratorOrZero(BinaryOperator *Rem);
void replaceSRemWithURem(BinaryOperator *Rem);
bool eliminateSDiv(BinaryOperator *SDiv);
+ bool strengthenBinaryOp(BinaryOperator *BO, Instruction *IVOperand);
bool strengthenOverflowingOperation(BinaryOperator *OBO,
Instruction *IVOperand);
bool strengthenRightShift(BinaryOperator *BO, Instruction *IVOperand);
@@ -747,6 +748,13 @@ bool SimplifyIndvar::eliminateIdentitySCEV(Instruction *UseInst,
return true;
}
+bool SimplifyIndvar::strengthenBinaryOp(BinaryOperator *BO,
+ Instruction *IVOperand) {
+ return (isa<OverflowingBinaryOperator>(BO) &&
+ strengthenOverflowingOperation(BO, IVOperand)) ||
+ (isa<ShlOperator>(BO) && strengthenRightShift(BO, IVOperand));
+}
+
/// Annotate BO with nsw / nuw if it provably does not signed-overflow /
/// unsigned-overflow. Returns true if anything changed, false otherwise.
bool SimplifyIndvar::strengthenOverflowingOperation(BinaryOperator *BO,
@@ -917,9 +925,7 @@ void SimplifyIndvar::simplifyUsers(PHINode *CurrIV, IVVisitor *V) {
}
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(UseInst)) {
- if ((isa<OverflowingBinaryOperator>(BO) &&
- strengthenOverflowingOperation(BO, IVOperand)) ||
- (isa<ShlOperator>(BO) && strengthenRightShift(BO, IVOperand))) {
+ if (strengthenBinaryOp(BO, IVOperand)) {
// re-queue uses of the now modified binary operator and fall
// through to the checks that remain.
pushIVUsers(IVOperand, L, Simplified, SimpleIVUsers);