summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-03-12 14:20:22 +0000
committerFangrui Song <maskray@google.com>2019-03-12 14:20:22 +0000
commitb1dfbebe8bfbeffcb389d941a370a89a161eb4da (patch)
treed1b4df0d0cbb5debb7a38495046a8d72c2372732
parent06bee01d2bc7d17e3ee378a1791946b81e2a4611 (diff)
downloadbcm5719-llvm-b1dfbebe8bfbeffcb389d941a370a89a161eb4da.tar.gz
bcm5719-llvm-b1dfbebe8bfbeffcb389d941a370a89a161eb4da.zip
[SimplifyLibCalls] Simplify optimizePuts
The code might intend to replace puts("") with putchar('\n') even if the return value is used. It failed because use_empty() was used to guard the whole block. While returning '\n' (putchar('\n')) is technically correct (puts is only required to return a nonnegative number on success), doing this looks weird and there is really little benefit to optimize puts whose return value is used. So don't do that. llvm-svn: 355921
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index b8a18a10f29..3920736a8d5 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2387,18 +2387,14 @@ Value *LibCallSimplifier::optimizeFRead(CallInst *CI, IRBuilder<> &B) {
}
Value *LibCallSimplifier::optimizePuts(CallInst *CI, IRBuilder<> &B) {
- // Check for a constant string.
- StringRef Str;
- if (!getConstantStringInfo(CI->getArgOperand(0), Str))
+ if (!CI->use_empty())
return nullptr;
- if (Str.empty() && CI->use_empty()) {
- // puts("") -> putchar('\n')
- Value *Res = emitPutChar(B.getInt32('\n'), B, TLI);
- if (CI->use_empty() || !Res)
- return Res;
- return B.CreateIntCast(Res, CI->getType(), true);
- }
+ // Check for a constant string.
+ // puts("") -> putchar('\n')
+ StringRef Str;
+ if (getConstantStringInfo(CI->getArgOperand(0), Str) && Str.empty())
+ return emitPutChar(B.getInt32('\n'), B, TLI);
return nullptr;
}
OpenPOWER on IntegriCloud