[llvm] r355921 - [SimplifyLibCalls] Simplify optimizePuts
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 12 07:20:22 PDT 2019
Author: maskray
Date: Tue Mar 12 07:20:22 2019
New Revision: 355921
URL: http://llvm.org/viewvc/llvm-project?rev=355921&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=355921&r1=355920&r2=355921&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Tue Mar 12 07:20:22 2019
@@ -2387,18 +2387,14 @@ Value *LibCallSimplifier::optimizeFRead(
}
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;
}
More information about the llvm-commits
mailing list