[llvm] 0c8dde5 - [ConstraintElimination] Move logic for replacing ssub overflow users (NFC)

Zain Jaffal via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 14 13:14:31 PDT 2022


Author: Zain Jaffal
Date: 2022-10-14T21:14:21+01:00
New Revision: 0c8dde551c801f319271fe662e82fef462dd07e0

URL: https://github.com/llvm/llvm-project/commit/0c8dde551c801f319271fe662e82fef462dd07e0
DIFF: https://github.com/llvm/llvm-project/commit/0c8dde551c801f319271fe662e82fef462dd07e0.diff

LOG: [ConstraintElimination] Move logic for replacing ssub overflow users (NFC)

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D134044

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 261548af81069..81b15c0bfc5c0 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -849,6 +849,38 @@ void ConstraintInfo::addFact(CmpInst::Predicate Pred, Value *A, Value *B,
   }
 }
 
+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 @@ tryToSimplifyOverflowMath(IntrinsicInst *II, ConstraintInfo &Info,
         !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;
 }


        


More information about the llvm-commits mailing list