[PATCH] D123816: [InstCombine] Fold strnlen with a bound of zero and one.
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 14 13:46:14 PDT 2022
nikic requested changes to this revision.
nikic added inline comments.
This revision now requires changes to proceed.
================
Comment at: llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h:242
+ Value *optimizeStringLength(CallInst *CI, IRBuilderBase &B, unsigned CharSize,
+ Value *Bound = nullptr);
};
----------------
nit: Indent not aligned.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:649
+ Value *ZeroLen = ConstantInt::get(CI->getType(), 0);
+ return B.CreateSelect(Cmp, ZeroLen, BoundCst, "strnlen.sel");
+ }
----------------
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)`.
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