From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12471 invoked by alias); 5 May 2014 16:01:08 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 12456 invoked by uid 89); 5 May 2014 16:01:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-wg0-f52.google.com Received: from mail-wg0-f52.google.com (HELO mail-wg0-f52.google.com) (74.125.82.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 05 May 2014 16:01:06 +0000 Received: by mail-wg0-f52.google.com with SMTP id l18so6661351wgh.23 for ; Mon, 05 May 2014 09:01:03 -0700 (PDT) X-Received: by 10.194.89.168 with SMTP id bp8mr2396245wjb.73.1399305663271; Mon, 05 May 2014 09:01:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.89.4 with HTTP; Mon, 5 May 2014 09:00:43 -0700 (PDT) In-Reply-To: <5367A8BF.5010805@redhat.com> References: <53146FAA.8090802@redhat.com> <5367A8BF.5010805@redhat.com> From: =?ISO-8859-1?Q?Manuel_L=F3pez=2DIb=E1=F1ez?= Date: Mon, 05 May 2014 16:01:00 -0000 Message-ID: Subject: Re: Target dependence of conditional expression gimplification To: Florian Weimer Cc: "gcc-help@gcc.gnu.org" , "Joseph S. Myers" , mpolacek@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes X-SW-Source: 2014-05/txt/msg00017.txt.bz2 On 5 May 2014 17:05, Florian Weimer wrote: >> Obviously, this affects optimization-dependent warnings later in the >> compilation. >> >> I wonder why this happens. Shouldn't gimplification be roughly >> target-independent? > > > It turns out that it's not gimplification, but fold which is the culprit. > In fold-const.c:fold_truth_andor, we have this code: This is a known issue. See PR32643, PR60090 and specially http://gcc.gnu.org/ml/gcc/2013-11/msg00253.html And this quote from http://gcc.gnu.org/ml/gcc-patches/2008-10/msg01061.html >>> At present, there are still various "optimizations" done in the C front end while the trees for expressions are built up, and some cases where some folding still happens; such optimizations can be incrementally moved out of the front end into fold (or other optimizers) where they belong, and such folding during parsing incrementally disabled, moving towards trees that more closely correspond to the original source. In addition, the front end does not logically need all the transformations done by fold. In principle, fold should act on GIMPLE (so avoiding any present dependence on which subexpressions were combined into larger expressions in the source program) with the only folding done before gimplification being more limited folding required for initializers. With such a change, c_fully_fold would only need to do the more limited folding. If the C gimplification handled C_MAYBE_CONST_EXPR, some calls to c_fully_fold could be eliminated altogether; only those where the information about constancy is required, in particular for static initializers, would need to remain. However, c_fully_fold could also be thought of as a logical lowering step, converting front-end-specific structures (which presently are GENERIC plus the odd extra tree code) to GENERIC, with potentially further transformations needed in future, and increases in the amount of lowering involved (making datastructures correspond more closely to the source for longer in the front end) might require this lowering step everywhere even when folding isn't needed. <<< I'm not sure if Marek Polacek has started working on it but he probably will appreciate some help. I don't think there is even a plan or TODO list written up of what needs to be done. It would be nice to create that in the wiki and check with Joseph, Jason and the middle-end maintainers that this plan matches their expectations. My understanding at the moment is that: * Optimizations should be moved from the FEs to middle-end (or to the gimplification phase). There is the suspicion that many are already redundant or actually undone by the middle-end, but someone needs to go over each of them and verify this. * There should be a FE-specific fold limited to checking const-ness of expressions. * Another (possibly different) FE-specific fold should deal with lowering FE specific trees to pure GENERIC. * A more powerful fold should be available for more precise warnings from the FE in some specific cases (it is not clear to me if the desired behavior is to move these warnings and the folding to gimplification, or to keep this folding working on trees? Also, whether the result of this folding should be discarded or stored somewhere). * I think a result of the above is that fold in the FEs (for const-ness, warnings and lowering) should be different from fold in the middle-end (for optimization), but I am not sure if this is part of the plan. Cheers, Manuel.