[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 Sep 16 06:48:03 PDT 2022
zjaffal created this revision.
zjaffal added a reviewer: fhahn.
Herald added a subscriber: hiraditya.
Herald added a project: All.
zjaffal requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
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
@@ -638,6 +638,31 @@
}
}
+static void replaceSubOverflowUses(IntrinsicInst *II, Value *A, Value *B,
+ SmallVectorImpl<Instruction *> &ToRemove) {
+ 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);
+ } else if (match(U, m_ExtractValue<1>(m_Value())))
+ U->replaceAllUsesWith(Builder.getFalse());
+ else
+ continue;
+
+ if (U->use_empty()) {
+ auto *I = cast<Instruction>(U);
+ ToRemove.push_back(I);
+ I->setOperand(0, PoisonValue::get(II->getType()));
+ }
+ }
+
+ if (II->use_empty())
+ II->eraseFromParent();
+}
+
static void
tryToSimplifyOverflowMath(IntrinsicInst *II, ConstraintInfo &Info,
SmallVectorImpl<Instruction *> &ToRemove) {
@@ -661,28 +686,7 @@
!DoesConditionHold(CmpInst::ICMP_SGE, B,
ConstantInt::get(A->getType(), 0), Info))
return;
-
- 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);
- } else if (match(U, m_ExtractValue<1>(m_Value())))
- U->replaceAllUsesWith(Builder.getFalse());
- else
- continue;
-
- if (U->use_empty()) {
- auto *I = cast<Instruction>(U);
- ToRemove.push_back(I);
- I->setOperand(0, PoisonValue::get(II->getType()));
- }
- }
-
- if (II->use_empty())
- II->eraseFromParent();
+ replaceSubOverflowUses(II, A, B, ToRemove);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134044.460725.patch
Type: text/x-patch
Size: 2116 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220916/4a3aebb1/attachment.bin>
More information about the llvm-commits
mailing list