[llvm] [ConstraintElim] Simplify `sadd_with_overflow` if A and B have different signs (PR #135784)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 15 08:21:10 PDT 2025


================
@@ -1675,6 +1676,38 @@ void ConstraintInfo::addFactImpl(CmpInst::Predicate Pred, Value *A, Value *B,
   }
 }
 
+static bool replaceAddOverflowUses(IntrinsicInst *II, Value *A, Value *B,
+                                   SmallVectorImpl<Instruction *> &ToRemove) {
+  bool Changed = false;
+  IRBuilder<> Builder(II->getParent(), II->getIterator());
+  Value *Add = nullptr;
+  for (User *U : make_early_inc_range(II->users())) {
+    if (match(U, m_ExtractValue<0>(m_Value()))) {
+      if (!Add)
+        Add = Builder.CreateAdd(A, B);
+      U->replaceAllUsesWith(Add);
+      Changed = true;
+    } else if (match(U, m_ExtractValue<1>(m_Value()))) {
+      U->replaceAllUsesWith(Builder.getFalse());
+      Changed = true;
+    } else
+      continue;
+
+    if (U->use_empty()) {
----------------
el-ev wrote:

Oops, I made a stupid mistake at L1759

https://github.com/llvm/llvm-project/pull/135784


More information about the llvm-commits mailing list