[PATCH] D128089: [InstCombine] Fold strncmp of constant arrays and variable size

Martin Sebor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 08:39:31 PDT 2022


msebor added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:1173
+    if (Pos == MinSize ||
+        (StrNCmp && (LStr[Pos] == '\0' && RStr[Pos] == '\0'))) {
+      // One array is a leading part of the other of equal or greater
----------------
nikic wrote:
> Not really sure why the change in code structure is needed. As far as I can tell, the only thing that's actually changing here is that a
> ```
> if (StrNCmp && (LStr[Pos] == '\0' && RStr[Pos] == '\0'))
>   break;
> ```
> condition gets added to the top of the loop body? Or am I misunderstanding something here?
The result is zero in this case, not +/-1 as the current algorithm computes.  Either way it seems like six of one vs half a dozen of the other.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128089/new/

https://reviews.llvm.org/D128089



More information about the llvm-commits mailing list