[PATCH] D134044: [ConstraintElimination] Move logic for replacing ssub overflow users (NFC)
Zain Jaffal via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 14 13:14:28 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0c8dde551c80: [ConstraintElimination] Move logic for replacing ssub overflow users (NFC) (authored by zjaffal).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D134044/new/
https://reviews.llvm.org/D134044
Files:
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
Index: llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -849,6 +849,38 @@
}
}
+static bool replaceSubOverflowUses(IntrinsicInst *II, Value *A, Value *B,
+ SmallVectorImpl<Instruction *> &ToRemove) {
+ bool Changed = false;
+ IRBuilder<> Builder(II->getParent(), II->getIterator());
+ Value *Sub = nullptr;
+ for (User *U : make_early_inc_range(II->users())) {
+ if (match(U, m_ExtractValue<0>(m_Value()))) {
+ if (!Sub)
+ Sub = Builder.CreateSub(A, B);
+ U->replaceAllUsesWith(Sub);
+ Changed = true;
+ } else if (match(U, m_ExtractValue<1>(m_Value()))) {
+ U->replaceAllUsesWith(Builder.getFalse());
+ Changed = true;
+ } else
+ continue;
+
+ if (U->use_empty()) {
+ auto *I = cast<Instruction>(U);
+ ToRemove.push_back(I);
+ I->setOperand(0, PoisonValue::get(II->getType()));
+ Changed = true;
+ }
+ }
+
+ if (II->use_empty()) {
+ II->eraseFromParent();
+ Changed = true;
+ }
+ return Changed;
+}
+
static bool
tryToSimplifyOverflowMath(IntrinsicInst *II, ConstraintInfo &Info,
SmallVectorImpl<Instruction *> &ToRemove) {
@@ -872,33 +904,7 @@
!DoesConditionHold(CmpInst::ICMP_SGE, B,
ConstantInt::get(A->getType(), 0), Info))
return false;
-
- IRBuilder<> Builder(II->getParent(), II->getIterator());
- Value *Sub = nullptr;
- for (User *U : make_early_inc_range(II->users())) {
- if (match(U, m_ExtractValue<0>(m_Value()))) {
- if (!Sub)
- Sub = Builder.CreateSub(A, B);
- U->replaceAllUsesWith(Sub);
- Changed = true;
- } else if (match(U, m_ExtractValue<1>(m_Value()))) {
- U->replaceAllUsesWith(Builder.getFalse());
- Changed = true;
- } else
- continue;
-
- if (U->use_empty()) {
- auto *I = cast<Instruction>(U);
- ToRemove.push_back(I);
- I->setOperand(0, PoisonValue::get(II->getType()));
- Changed = true;
- }
- }
-
- if (II->use_empty()) {
- II->eraseFromParent();
- Changed = true;
- }
+ Changed = replaceSubOverflowUses(II, A, B, ToRemove);
}
return Changed;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134044.467896.patch
Type: text/x-patch
Size: 2405 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221014/d4e325ff/attachment.bin>
More information about the llvm-commits
mailing list