[PATCH] D154725: [SimplifyLibCalls] Fold strcmp for short string literals
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 7 12:25:50 PDT 2023
nikic requested changes to this revision.
nikic added inline comments.
This revision now requires changes to proceed.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:576
+ if (Str2.size() == 1) {
+ return FirstCharacterSub;
+ }
----------------
This will return an incorrect result if the first character of Str1 and Str2 is the same, but Str1 has length greater than one.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:581
+ B.CreateLoad(B.getInt8Ty(),
+ B.CreateConstInBoundsGEP1_32(B.getInt8Ty(), Str1P, 1)),
+ B.getInt32Ty(), true);
----------------
This may perform an out of bounds access for zero-length strings.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:612
if (!HasStr1 && HasStr2) {
if (canTransformToMemCmp(CI, Str1P, Len2, DL))
return copyFlags(
----------------
This is the transform that implements what you're trying to do, but taking dereferenceability into account.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154725/new/
https://reviews.llvm.org/D154725
More information about the llvm-commits
mailing list