[llvm] [ExpandMemCmp] Improve memcmp optimisation for boolean results (PR #71221)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 12:22:00 PDT 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 5192e299cf444040025ccf3e75bfad36b4624050 05b0461db30a0d4a221e1cfc362b1f2eb13985ab -- llvm/lib/CodeGen/ExpandMemCmp.cpp
``````````

</details>

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

``````````diff
diff --git a/llvm/lib/CodeGen/ExpandMemCmp.cpp b/llvm/lib/CodeGen/ExpandMemCmp.cpp
index a3dd0feea..c3d73df58 100644
--- a/llvm/lib/CodeGen/ExpandMemCmp.cpp
+++ b/llvm/lib/CodeGen/ExpandMemCmp.cpp
@@ -667,11 +667,13 @@ Value *MemCmpExpansion::getMemCmpOneBlock() {
     ICmpInst::Predicate Pred = ICmpInst::Predicate::BAD_ICMP_PREDICATE;
     uint64_t Shift;
     bool NeedsZExt = false;
-    // This is a special case because instead of checking if the result is less than zero:
+    // This is a special case because instead of checking if the result is less
+    // than zero:
     //    bool result = memcmp(a, b, NBYTES) < 0;
     // Compiler is clever enough to generate the following code:
     //    bool result = memcmp(a, b, NBYTES) >> 31;
-    if (match(UI, m_LShr(m_Value(), m_ConstantInt(Shift))) && Shift == CI->getType()->getIntegerBitWidth() - 1) {
+    if (match(UI, m_LShr(m_Value(), m_ConstantInt(Shift))) &&
+        Shift == CI->getType()->getIntegerBitWidth() - 1) {
       Pred = ICmpInst::ICMP_SLT;
       NeedsZExt = true;
     } else {
@@ -680,7 +682,8 @@ Value *MemCmpExpansion::getMemCmpOneBlock() {
     }
     // Generate new code and remove the original memcmp call and the user
     if (ICmpInst::isSigned(Pred)) {
-      Value *Cmp = Builder.CreateICmp(CmpInst::getUnsignedPredicate(Pred), Loads.Lhs, Loads.Rhs);
+      Value *Cmp = Builder.CreateICmp(CmpInst::getUnsignedPredicate(Pred),
+                                      Loads.Lhs, Loads.Rhs);
       auto *Result = NeedsZExt ? Builder.CreateZExt(Cmp, U->getType()) : Cmp;
       UI->replaceAllUsesWith(Result);
       UI->eraseFromParent();

``````````

</details>


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


More information about the llvm-commits mailing list