[llvm] [InstCombine] Fold values to 0 on eq-dominated paths (PR #174083)

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 31 05:26:55 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index b539c4848..a8c6c57ce 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -2295,24 +2295,29 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
   for (User *U : I.users()) {
     auto *UseI = dyn_cast<Instruction>(U);
 
-    if (!UseI) continue;
+    if (!UseI)
+      continue;
 
     BasicBlock *BB = UseI->getParent();
     BasicBlock *Pred = BB->getSinglePredecessor();
 
-    if (!Pred) continue;
+    if (!Pred)
+      continue;
 
     auto *Br = dyn_cast<BranchInst>(Pred->getTerminator());
 
-    if (!Br || !Br->isConditional()) continue;
+    if (!Br || !Br->isConditional())
+      continue;
 
     auto *Cmp = dyn_cast<ICmpInst>(Br->getCondition());
 
-    if (!Cmp || Cmp->getPredicate() != ICmpInst::ICMP_EQ) continue;
+    if (!Cmp || Cmp->getPredicate() != ICmpInst::ICMP_EQ)
+      continue;
     if (!((Cmp->getOperand(0) == Op0 && Cmp->getOperand(1) == Op1) ||
-        (Cmp->getOperand(0) == Op1 && Cmp->getOperand(1) == Op0)))
+          (Cmp->getOperand(0) == Op1 && Cmp->getOperand(1) == Op0)))
+      continue;
+    if (Br->getSuccessor(0) != BB)
       continue;
-    if (Br->getSuccessor(0) != BB) continue;
 
     UseI->replaceUsesOfWith(&I, ConstantInt::get(I.getType(), 0));
   }

``````````

</details>


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


More information about the llvm-commits mailing list