[PATCH] D128939: [InstCombine] Fold memchr and strchr equality with first argument
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 1 01:09:58 PDT 2022
nikic added a comment.
This looks fine, only bit I'm uncertain about is the special-case for `strchr(A, '\0') == null`. Please precommit the tests to show current codegen. Possibly we can address that differently, in particular I notice that we're currently missing inbounds on GEPs, which might be limiting subsequent comparison folding.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:299
+// Helper to transform memchr(S, C, N) == S to N && *S == C and, when
+// NBytesis null, strchr(S, C) to *S == C. A precondition of the function
+// is that either S is dereferenceable or the value of N is nonzero.
----------------
NBytes is
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:301
+// is that either S is dereferenceable or the value of N is nonzero.
+static Value* MemChrToCharCompare(CallInst *CI, Value *NBytes,
+ IRBuilderBase &B, const DataLayout &DL)
----------------
`static Value *memChrToCharCompare`
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:1153
+ // S is dereferenceable so it's safe to load from it and fold
+ // memcmp(S, C, N) == S to N && *S == C for any C and N.
+ // TODO: This is safe even even for nonconstant S.
----------------
memcmp -> memchr
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128939/new/
https://reviews.llvm.org/D128939
More information about the llvm-commits
mailing list