[PATCH] D100724: [SimplifyLibCalls] Transform printf("%s", str) to puts(str) or noop.

Dawid Jurczak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 22 05:38:58 PDT 2021


yurai007 marked 4 inline comments as done.
yurai007 added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:2379
+  // Try to emit putchar or puts.
   if (FormatStr == "%s" && CI->getNumArgOperands() > 1) {
+    StringRef OperandStr;
----------------
yurai007 wrote:
> spatel wrote:
> > Why is this checking for `args > 1` instead of exactly `args == 2`?
> That's interesting. It's part of legacy and I think it's deliberate to handle (pathological but accepted by frontend) cases 
> when printf has redundant arguments and we still want to emit puts or putchar: https://godbolt.org/z/xjxG98jKh
> Notice that thanks to this condition llvm is more aggresive then gcc. I don't have strong opinion about such behaviour but I would vote for leaving it as it is. Maybe in such case it would be worth to add one more test to catch and document this behaviour.
test_simplify10 demonstrates mentioned behavior. 


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