From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30264 invoked by alias); 5 May 2014 15:05:41 -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 30252 invoked by uid 89); 5 May 2014 15:05:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 May 2014 15:05:40 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s45F5cWU030321 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 5 May 2014 11:05:38 -0400 Received: from oldenburg.str.redhat.com (oldenburg.str.redhat.com [10.33.200.60]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s45F5ZIG012842 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Mon, 5 May 2014 11:05:37 -0400 Message-ID: <5367A8BF.5010805@redhat.com> Date: Mon, 05 May 2014 15:05:00 -0000 From: Florian Weimer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: "gcc-help@gcc.gnu.org" Subject: Re: Target dependence of conditional expression gimplification References: <53146FAA.8090802@redhat.com> In-Reply-To: <53146FAA.8090802@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2014-05/txt/msg00014.txt.bz2 On 03/03/2014 01:03 PM, Florian Weimer wrote: > I have code like this: > > if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN) { > preferred = 1; > } else { > preferred = current; > /* PINs are even numbered, PUKs are odd */ > if (!(preferred & 1)) > preferred++; > if (preferred >= 126) > return SC_ERROR_TOO_MANY_OBJECTS; > } > > if (current > preferred || preferred > CARDOS_PIN_ID_MAX) > return SC_ERROR_TOO_MANY_OBJECTS; > > On x86_64, the condition in the final if statement is gimplified as: > > - D.8003 = current > preferred; > - D.8004 = preferred > 15; > - D.8005 = D.8003 | D.8004; > - if (D.8005 != 0) goto ; else goto ; > > On rs6000 (-mtune=power7 -mcpu=power7), I get this instead: > > + if (current > preferred) goto ; else goto ; > + : > + if (preferred > 15) goto ; else goto ; Here's a self-contained reproducer: int g(void); int f(int flags, int current) { int preferred; if (flags & 0x80) { preferred = 1; } else { preferred = current; if (!(preferred & 1)) preferred++; if (preferred >= 126) return 55; } if (current > preferred || preferred > 17) return 55; return g(); } > 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: if (LOGICAL_OP_NON_SHORT_CIRCUIT && (code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR || code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR)) { … /* Transform (A AND-IF B) into (A AND B), or (A OR-IF B) into (A OR B). For sequence point consistancy, we need to check for trapping, and side-effects. */ else if (code == icode && simple_operand_p_2 (arg0) && simple_operand_p_2 (arg1)) return fold_build2_loc (loc, ncode, type, arg0, arg1); rs6000 defines LOGICAL_OP_NON_SHORT_CIRCUIT as 0, so this code never runs, and the gimplifier produces two separate if statements. -- Florian Weimer / Red Hat Product Security Team