[PATCH] D128954: [InstCombine] Transform strrchr to memrchr for constant strings
Martin Sebor via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 1 08:19:34 PDT 2022
msebor added inline comments.
================
Comment at: llvm/lib/Transforms/Utils/BuildLibCalls.cpp:1543
+Value *llvm::emitMemRChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
+ const DataLayout &DL, const TargetLibraryInfo *TLI) {
+ LLVMContext &Context = B.GetInsertBlock()->getContext();
----------------
nikic wrote:
> This one probably needs an isLibFuncEmittable check, because memrchr is a GNU extension. It looks like PS targets do mark it as unavailable.
`isLibFuncEmittable` is called from `emitLibCall` so I think this parts should be fine. Or am I missing something here?
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:362
+ Value *Size = ConstantInt::get(IntPtrType, NBytes);
+ return copyFlags(*CI, emitMemRChr(SrcStr, CharVal, Size, B, DL, TLI));
}
----------------
I did forget that `memrchr` isn't standard so this will fail on targets without it as you noted. Are we okay with losing that optimization on those targets or should I keep the existing optimization and use it when `emitMemRChr` fails?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128954/new/
https://reviews.llvm.org/D128954
More information about the llvm-commits
mailing list