[PATCH] D100724: [SimplifyLibCalls] Transform printf("%s", str"\n") --> puts(str).
Dawid Jurczak via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 22 02:48:27 PDT 2021
yurai007 added inline comments.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:2382
+ if (!getConstantStringInfo(CI->getOperand(1), OperandStr) ||
+ OperandStr.empty())
return nullptr;
----------------
spatel wrote:
> What does it mean if the operand string is empty?
> printf("%s", "");
>
> It can be another patch, but please leave a "TODO" comment. Looks like gcc removes the call entirely.
Ok, will add it to this patch if you don't mind.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:2383
+ OperandStr.empty())
return nullptr;
+ // printf("%s", "a") --> putchar('a')
----------------
xbolva00 wrote:
> We could even handle printf("%s", "");
>
> if (OperandStr.empty())
> return ConstantInt::get(CI->getType(), 0);
>
> https://godbolt.org/z/Ke5bcxWPK
Nice finding. I will include this optimization to patch.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100724/new/
https://reviews.llvm.org/D100724
More information about the llvm-commits
mailing list