From patchwork Tue Jan 3 05:29:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 710376 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 3tt2bq3hk2z9svs for ; Tue, 3 Jan 2017 16:31:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="YVZWb+gD"; 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:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=LBoMc69Vv7PYqfSTfD7PH6sWOd+P/Oxjj5sLEO7Xyy08lOje4In2i mF0AhiXrbguenw5hM0/0VajmsFY9+CanypVOWFCGaAhdIaBbru9mD1Q/NE+VqJ/u hjp/O2RSz+efpVuvU1e7QiIVNIwv19DXIObH7w2zf6r/cKzu8x9B84= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=CAe0Ab24VuuyW0l4MeMoZISQEmg=; b=YVZWb+gDKNz7+go9THxF DfF1QKwL072aPlHRmiPC+ZW2db/+dyvpr4AqRrkePotC/aoQGXk2Fh7VbjbkWtV+ U2+Tz51UIZSm66oau/HL5Ov+Ay6Hwj824qklzwD+P+5Q3BrO0A6DwSdO1or6CZtr 5EonfWGlduEeUZZFfe2Kexg= Received: (qmail 15476 invoked by alias); 3 Jan 2017 05:29:23 -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 15327 invoked by uid 89); 3 Jan 2017 05:29:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.1 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=concluded, dfscanc, df-scan.c, UD:df-scan.c 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; Tue, 03 Jan 2017 05:29:20 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 198FDC057EC9 for ; Tue, 3 Jan 2017 05:29:20 +0000 (UTC) Received: from freie.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v035TI5Z017860 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 3 Jan 2017 00:29:19 -0500 Received: from livre (livre.home [172.31.160.2]) by freie.home (8.15.2/8.15.2) with ESMTP id v035T1ba011490; Tue, 3 Jan 2017 03:29:01 -0200 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [bootstrap-O3] use unsigned type for regno in df-scan Date: Tue, 03 Jan 2017 03:29:01 -0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 This patch fixes a false-positive warning in df-scan, at bootstrap-O3 failed, and enables GCC to optimize out the code that leads to the warning. df_ref_create_structure was inlined into the else part of df_ref_record. Due to the condition of the corresponding if, In the else part, VRP deduced unsigned regno >= FIRST_PSEUDO_REGISTER. In df_ref_create_structure, there's another regno variable, initialized with the same expression and value as the caller's. GCC can tell as much, but this regno variable is signed. It is used, shifted right, to index a hard regset bit array within a path that tests that this signed regno < FIRST_PSEUDO_REGISTER. GCC warned about the possible out-of-range indexing into the hard regset array. It shouldn't, after all, the same regno can't possibly be both < FIRST_PSEUDO_REGISTER and >= FIRST_PSEUDO_REGISTER, can it? Well, the optimizers correctly decide it could, if it was a negative int that, when converted to unsigned, became larger than FIRST_PSEUDO_REGISTER. But GCC doesn't know regno can't be negative, so the test could not be optimize out. What's more, given the constraints, VRP correctly concluded the hard regset array would always be indexed by a value way outside the array index range. This patch changes the inlined regno to unsigned, like the caller's, so that we can now tell the conditions can't both hold, so we optimize out the path containing the would-be out-of-range array indexing. Regstrapped on x86_64-linux-gnu and i686-linux-gnu. OK to install? for gcc/ChangeLog * df-scan.c (df_ref_create_structure): Make regno unsigned, to match the caller. --- gcc/df-scan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/df-scan.c b/gcc/df-scan.c index e6b55b5..ee8282f 100644 --- a/gcc/df-scan.c +++ b/gcc/df-scan.c @@ -2483,7 +2483,7 @@ df_ref_create_structure (enum df_ref_class cl, int ref_flags) { df_ref this_ref = NULL; - int regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg); + unsigned int regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg); struct df_scan_problem_data *problem_data = (struct df_scan_problem_data *) df_scan->problem_data;