[PATCH] D122836: [SimplifyLibCalls] Fold more memchr calls

Martin Sebor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 1 13:48:13 PDT 2022


msebor added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:900
+
+  if (MaxLen == 1) {
+    // Fold memchr(x, y, 1) --> *x == y ? x : null for any x and y,
----------------
nikic wrote:
> I think MaxLen has lost most of it's purpose now, and you can just do a `LenC->isOne()` check in the preceding branch?
There's another use in `Str = Str.substr(0, MaxLen);` on line 939.

The latest diff is harder to follow because of the new early return from the function.  Sorry about that.  I debated making that change and maybe I shouldn't have...


================
Comment at: llvm/test/Transforms/InstCombine/memchr-2.ll:108
 
 ; Fold memchr(a12345, 259, n) to n < 4 ? null : a12345 + 3
 ; to verify the constant 259 is converted to unsigned char (yielding 3).
----------------
xbolva00 wrote:
> But IR says N < 3
> 
> And gep is 2, not 3.
> 
> Confusing.
Sadly there are a few copy and paste typos in the comments and names of the functions (should be `fold_xxx` not `call_xxx`).  Let me fix them.


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

https://reviews.llvm.org/D122836



More information about the llvm-commits mailing list