From patchwork Wed Nov 16 16:49:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 695692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tJqwY2jQGz9ryk for ; Thu, 17 Nov 2016 03:49:16 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="PPnyEmAG"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:cc:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=K4zGrWl0retCKLDzr /G0ZRrCamfO3A9xwVtf84Pib/ilYlSAGzHqwLWOB1B8VyvaEBFcVX5aRhlG4PDDg u9zq+p/K/2+tTHUJsg2iQiREwlUGX/GU3K1Yh5GgyqMTVt4ZNyliWtM9oF/lkH3E dV2wlQC9531TEju27xPCZQStuo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:cc:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=yuqhk3FMw/m4Kf+AsCiAEWG BxxA=; b=PPnyEmAGyRO+q7VZQDAw66MSVQ5RhuE1ck6qs5J+c5ebseYz0Ior0je uEd9OkHLLxEr1OgXkR62eGwQorDXZ5RNaRDnMlmhL6GLRvLYYXpnSanJ9n5XA7OL 3+yKmTBOPt+4vsVitLziJku//R0ZMtdzyyKZCvQVEDF/uAv2sy3w= Received: (qmail 56277 invoked by alias); 16 Nov 2016 16:49:07 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 56265 invoked by uid 89); 16 Nov 2016 16:49:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=H*Ad:U*sandra X-HELO: mail-qt0-f177.google.com Received: from mail-qt0-f177.google.com (HELO mail-qt0-f177.google.com) (209.85.216.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Nov 2016 16:49:05 +0000 Received: by mail-qt0-f177.google.com with SMTP id w33so108938588qtc.3 for ; Wed, 16 Nov 2016 08:49:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:cc:message-id:date :user-agent:mime-version:in-reply-to; bh=vGKHvl6eRNE+sxACPAF9mbe8yoNjRKpd8ZDOCllt/m8=; b=J8/s854HrN6hH9jqp36p16uZXqfIMFXltxXSKwKO2jGDy9gyitWxZYtAcDBbdbyaFk HHg8rXlssnTUbX0du2MMgKdpvvznM+Ins6R6FZC6CayHA09C9LoZSX5vC6ABkT/AqtuQ x5kwxj/Bizo/K2v/cuHzD1VBYSYYEqMsgcZt0SvQVDS2K0uxNgzLgLE6n1G5LgSxqgKG n8GS4Eu6KbAMsleEEPF0xgyslt3xo4h3TVLErefM80oP9jmlnZzyP4lB85MaNfSnEDmz ijlsjBUKJdqiUSFy3OdS5WugFcAiiUbWKkziJyMbz7JQERe8xT/aLzkJ7mcHHez+Vj/5 Y4Tw== X-Gm-Message-State: AKaTC03yfxcuVItMaYDwV6uedwlBpu45JWE9GRdUyfEiWs8ZquhIrCAOg8cCz/bYEU+ong== X-Received: by 10.200.45.57 with SMTP id n54mr2757285qta.52.1479314944014; Wed, 16 Nov 2016 08:49:04 -0800 (PST) Received: from [192.168.0.26] (75-166-206-79.hlrn.qwest.net. [75.166.206.79]) by smtp.gmail.com with ESMTPSA id w34sm18167037qtw.10.2016.11.16.08.49.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Nov 2016 08:49:03 -0800 (PST) Subject: PING [PATCH] enable -fprintf-return-value by default To: Gcc Patch List References: <1e7776ca-c7f6-4d93-6b33-2c51dc5a8689@gmail.com> From: Martin Sebor Cc: Sandra Loosemore Message-ID: Date: Wed, 16 Nov 2016 09:49:01 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <1e7776ca-c7f6-4d93-6b33-2c51dc5a8689@gmail.com> X-IsSubscribed: yes I'm looking for an approval of the attached patch. I've adjusted the documentation based on Sandra's input (i.e., documented the negative of the option rather than the positive; thank you for the review, btw.) On 11/08/2016 08:13 PM, Martin Sebor wrote: > The -fprintf-return-value optimization has been disabled since > the last time it caused a bootstrap failure on powerpc64le. With > the underlying problems fixed GCC has bootstrapped fine on all of > powerpc64, powerpc64le and x86_64 and tested with no regressions. > I'd like to re-enable the option. The attached patch does that. > > Thanks > Martin > gcc/c-family/ChangeLog: * c.opt (-fprintf-return-value): Enable by default. gcc/ChangeLog: * doc/invoke.texi (-fprintf-return-value): Document that option is enabled by default. Index: gcc/c-family/c.opt =================================================================== --- gcc/c-family/c.opt (revision 242500) +++ gcc/c-family/c.opt (working copy) @@ -1550,7 +1550,7 @@ C++ ObjC++ Var(flag_pretty_templates) Init(1) -fno-pretty-templates Do not pretty-print template specializations as the template signature followed by the arguments. fprintf-return-value -C ObjC C++ ObjC++ LTO Optimization Var(flag_printf_return_value) Init(0) +C ObjC C++ ObjC++ LTO Optimization Var(flag_printf_return_value) Init(1) Treat known sprintf return values as constants. freplace-objc-classes Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 242500) +++ gcc/doc/invoke.texi (working copy) @@ -384,7 +384,7 @@ Objective-C and Objective-C++ Dialects}. -fno-toplevel-reorder -fno-trapping-math -fno-zero-initialized-in-bss @gol -fomit-frame-pointer -foptimize-sibling-calls @gol -fpartial-inlining -fpeel-loops -fpredictive-commoning @gol --fprefetch-loop-arrays -fprintf-return-value @gol +-fprefetch-loop-arrays -fno-printf-return-value @gol -fprofile-correction @gol -fprofile-use -fprofile-use=@var{path} -fprofile-values @gol -fprofile-reorder-functions @gol @@ -8286,18 +8286,19 @@ dependent on the structure of loops within the sou Disabled at level @option{-Os}. -@item -fprintf-return-value -@opindex fprintf-return-value -Substitute constants for known return value of formatted output functions -such as @code{sprintf}, @code{snprintf}, @code{vsprintf}, and @code{vsnprintf} -(but not @code{printf} of @code{fprintf}). This transformation allows GCC -to optimize or even eliminate branches based on the known return value of -these functions called with arguments that are either constant, or whose -values are known to be in a range that makes determining the exact return -value possible. For example, both the branch and the body of the @code{if} -statement (but not the call to @code{snprint}) can be optimized away when -@code{i} is a 32-bit or smaller integer because the return value is guaranteed -to be at most 8. +@item -fno-printf-return-value +@opindex fno-printf-return-value +Do not substitute constants for known return value of formatted output +functions such as @code{sprintf}, @code{snprintf}, @code{vsprintf}, and +@code{vsnprintf} (but not @code{printf} or @code{fprintf}). This +transformation allows GCC to optimize or even eliminate branches based +on the known return value of these functions called with arguments that +are either constant, or whose values are known to be in a range that +makes determining the exact return value possible. For example, when +@option{-fprintf-return-value} is in effect, both the branch and the +body of the @code{if} statement (but not the call to @code{snprintf}) +can be optimized away when @code{i} is a 32-bit or smaller integer +because the return value is guaranteed to be at most 8. @smallexample char buf[9]; @@ -8308,7 +8309,7 @@ if (snprintf (buf, "%08x", i) >= sizeof buf) The @option{-fprintf-return-value} option relies on other optimizations and yields best results with @option{-O2}. It works in tandem with the @option{-Wformat-length} option. The @option{-fprintf-return-value} -option is disabled by default. +option is enabled by default. @item -fno-peephole @itemx -fno-peephole2