[PATCH] D123816: [InstCombine] Fold strnlen with a bound of zero and one.

Martin Sebor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 25 12:25:34 PDT 2022


msebor marked an inline comment as done.
msebor added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:649
+        Value *ZeroLen = ConstantInt::get(CI->getType(), 0);
+        return B.CreateSelect(Cmp, ZeroLen, BoundCst, "strnlen.sel");
+      }
----------------
nikic wrote:
> Isn't this select the wrong way around? You're doing `*s != 0 ? 0 : 1` here.
> 
> You might also want to directly emit the zext form if InstCombine is going to fold it anyway, so that would be `zext(s != 0)`.
Yes, it is backwards.  Good catch!  The test is wrong too.  I was worried about something like this happening after checking in the baseline tests first and then relying on `update_test_checks.py` to update the assertions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123816



More information about the llvm-commits mailing list