1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00

Only replace fwrite with fputc, if the return value is unused.

llvm-svn: 146411
This commit is contained in:
Joerg Sonnenberger 2011-12-12 20:18:31 +00:00
parent 30d6a45140
commit 5b25b4d437
2 changed files with 15 additions and 1 deletions

View File

@ -1293,7 +1293,8 @@ struct FWriteOpt : public LibCallOptimization {
return ConstantInt::get(CI->getType(), 0);
// If this is writing one byte, turn it into fputc.
if (Bytes == 1) { // fwrite(S,1,1,F) -> fputc(S[0],F)
// This optimisation is only valid, if the return value is unused.
if (Bytes == 1 && CI->use_empty()) { // fwrite(S,1,1,F) -> fputc(S[0],F)
Value *Char = B.CreateLoad(CastToCStr(CI->getArgOperand(0), B), "char");
EmitFPutC(Char, CI->getArgOperand(3), B, TD);
return ConstantInt::get(CI->getType(), 1);

View File

@ -0,0 +1,13 @@
; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
%FILE = type { i32 }
@.str = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
define i64 @foo(%FILE* %f) {
; CHECK: %retval = call i64 @fwrite
%retval = call i64 @fwrite(i8* getelementptr inbounds ([1 x i8]* @.str, i64 0, i64 0), i64 1, i64 1, %FILE* %f)
ret i64 %retval
}
declare i64 @fwrite(i8*, i64, i64, %FILE *)