[llvm] [InstCombine] Extend `foldICmpAddConstant` to disjoint `or`. (PR #75899)

via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 18 23:06:26 PST 2023


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 620280c4f97ea066d63edcf59b7378c6025999a1 ac71355307853b9e017af7ecca500b4b4d1c5d1f -- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp llvm/lib/Transforms/InstCombine/InstCombineInternal.h llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
``````````

</details>

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

``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 1cbcec3f21..0ba3e90efe 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2919,8 +2919,8 @@ static Value *createLogicFromTable(const std::bitset<4> &Table, Value *Op0,
 
 /// Fold icmp (add X, Y), C.
 Instruction *InstCombinerImpl::foldICmpAddLikeConstant(ICmpInst &Cmp,
-                                                   BinaryOperator *AddLike,
-                                                   const APInt &C) {
+                                                       BinaryOperator *AddLike,
+                                                       const APInt &C) {
   Value *X = nullptr;
   Value *Y = nullptr;
   if (!match(AddLike, m_AddLike(m_Value(X), m_Value(Y))))
@@ -2929,10 +2929,10 @@ Instruction *InstCombinerImpl::foldICmpAddLikeConstant(ICmpInst &Cmp,
   Value *Op0, *Op1;
   Instruction *Ext0, *Ext1;
   const CmpInst::Predicate Pred = Cmp.getPredicate();
-  if (match(AddLike,
-            m_AddLike(m_CombineAnd(m_Instruction(Ext0), m_ZExtOrSExt(m_Value(Op0))),
-                  m_CombineAnd(m_Instruction(Ext1),
-                               m_ZExtOrSExt(m_Value(Op1))))) &&
+  if (match(AddLike, m_AddLike(m_CombineAnd(m_Instruction(Ext0),
+                                            m_ZExtOrSExt(m_Value(Op0))),
+                               m_CombineAnd(m_Instruction(Ext1),
+                                            m_ZExtOrSExt(m_Value(Op1))))) &&
       Op0->getType()->isIntOrIntVectorTy(1) &&
       Op1->getType()->isIntOrIntVectorTy(1)) {
     unsigned BW = C.getBitWidth();
@@ -2950,8 +2950,8 @@ Instruction *InstCombinerImpl::foldICmpAddLikeConstant(ICmpInst &Cmp,
     Table[1] = ComputeTable(false, true);
     Table[2] = ComputeTable(true, false);
     Table[3] = ComputeTable(true, true);
-    if (auto *Cond =
-            createLogicFromTable(Table, Op0, Op1, Builder, AddLike->hasOneUse()))
+    if (auto *Cond = createLogicFromTable(Table, Op0, Op1, Builder,
+                                          AddLike->hasOneUse()))
       return replaceInstUsesWith(Cmp, Cond);
   }
   const APInt *C2;
@@ -2965,7 +2965,7 @@ Instruction *InstCombinerImpl::foldICmpAddLikeConstant(ICmpInst &Cmp,
   // the constants. Equality comparisons are handled elsewhere. SGE/SLE/UGE/ULE
   // are canonicalized to SGT/SLT/UGT/ULT.
   if (AddLike->getOpcode() == Instruction::Or ||
-    (AddLike->hasNoSignedWrap() &&
+      (AddLike->hasNoSignedWrap() &&
        (Pred == ICmpInst::ICMP_SGT || Pred == ICmpInst::ICMP_SLT)) ||
       (AddLike->hasNoUnsignedWrap() &&
        (Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_ULT))) {
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 756da48a18..475c250600 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -672,7 +672,7 @@ public:
   Instruction *foldICmpSubConstant(ICmpInst &Cmp, BinaryOperator *Sub,
                                    const APInt &C);
   Instruction *foldICmpAddLikeConstant(ICmpInst &Cmp, BinaryOperator *AddLike,
-                                   const APInt &C);
+                                       const APInt &C);
   Instruction *foldICmpAndConstConst(ICmpInst &Cmp, BinaryOperator *And,
                                      const APInt &C1);
   Instruction *foldICmpAndShift(ICmpInst &Cmp, BinaryOperator *And,

``````````

</details>


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


More information about the llvm-commits mailing list