[llvm] r274753 - Code size optimisation: don't rewrite fputs to fwrite when optimising for size

Sjoerd Meijer via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 7 07:23:58 PDT 2016


Thanks, I am fixing this; I will reopen the review and submit the fix.

-----Original Message-----
From: Benjamin Kramer [mailto:benny.kra at gmail.com]
Sent: 07 July 2016 15:10
To: Sjoerd Meijer
Cc: Chandler Carruth via llvm-commits
Subject: Re: [llvm] r274753 - Code size optimisation: don't rewrite fputs to fwrite when optimising for size

On Thu, Jul 7, 2016 at 3:56 PM, Sjoerd Meijer via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> Author: sjoerdmeijer
> Date: Thu Jul  7 08:56:23 2016
> New Revision: 274753
>
> URL: http://llvm.org/viewvc/llvm-project?rev=274753&view=rev
> Log:
> Code size optimisation: don't rewrite fputs to fwrite when optimising
> for size because fwrite requires more arguments and thus extra MOVs are required.
>
> Added:
>     llvm/trunk/test/Transforms/InstCombine/fputs-opt-size.ll
> 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/Si
> mplifyLibCalls.cpp?rev=274753&r1=274752&r2=274753&view=diff
> ======================================================================
> ========
> --- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Thu Jul  7
> +++ 08:56:23 2016
> @@ -2056,6 +2056,8 @@ Value *LibCallSimplifier::optimizeCall(C
>      case LibFunc::fwrite:
>        return optimizeFWrite(CI, Builder);
>      case LibFunc::fputs:
> +      if (CI->getParent()->getParent()->optForSize())
> +        return nullptr;

Why not do this check inside of optimizeFPuts? There should also be a comment on why we don't want to optimize it when targeting minimum size, i.e. replicate your commit message in the source code.

>        return optimizeFPuts(CI, Builder);
>      case LibFunc::log:
>      case LibFunc::log10:
>
> Added: llvm/trunk/test/Transforms/InstCombine/fputs-opt-size.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCom
> bine/fputs-opt-size.ll?rev=274753&view=auto
> ======================================================================
> ========
> --- llvm/trunk/test/Transforms/InstCombine/fputs-opt-size.ll (added)
> +++ llvm/trunk/test/Transforms/InstCombine/fputs-opt-size.ll Thu Jul
> +++ 7 08:56:23 2016
> @@ -0,0 +1,28 @@
> +; When optimising for size, we don't want to rewrite fputs to fwrite
> +; because it requires more arguments and thus extra MOVs are required.
> +;
> +; RUN: opt < %s -instcombine -S | FileCheck %s
> +
> +%struct._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*,
> +i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct._IO_FILE*, i32, i32,
> +i32, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i8*, i8*, i32, i32, [40 x
> +i8] } %struct._IO_marker = type { %struct._IO_marker*,
> +%struct._IO_FILE*, i32 }
> +
> + at .str = private unnamed_addr constant [10 x i8] c"mylog.txt\00",
> +align 1
> + at .str.1 = private unnamed_addr constant [2 x i8] c"a\00", align 1
> + at .str.2 = private unnamed_addr constant [27 x i8] c"Hello world this
> +is a test\00", align 1
> +
> +define i32 @main() local_unnamed_addr #0 {
> +entry:
> +; CHECK-LABEL: @main(
> +; CHECK-NOT: call i64 @fwrite
> +; CHECK: call i32 @fputs
> +
> +  %call = tail call %struct._IO_FILE* @fopen(i8* getelementptr
> +inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8*
> +getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0))
> +#2
> +  %call1 = tail call i32 @fputs(i8* getelementptr inbounds ([27 x
> +i8], [27 x i8]* @.str.2, i32 0, i32 0), %struct._IO_FILE* %call) #2
> +  ret i32 0
> +}
> +
> +declare noalias %struct._IO_FILE* @fopen(i8* nocapture readonly, i8*
> +nocapture readonly) local_unnamed_addr #1 declare i32 @fputs(i8*
> +nocapture readonly, %struct._IO_FILE* nocapture) local_unnamed_addr
> +#1
> +
> +attributes #0 = { nounwind optsize }
> +attributes #1 = { nounwind optsize  }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the llvm-commits mailing list