From patchwork Wed Mar 26 17:02:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 334014 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 96AD614007B for ; Thu, 27 Mar 2014 04:03:02 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=AzcjxYzi/zYMuz+UFSywwiwSCZOkoI4SYoAHy2FiPgSLOd 59NEwiHOsitJTq3Us7KvNrKQmXVD8DWxRzbEYXx0ae84xJJ2pLkXQ2AaM2hTLnTx rQ4V/JdL/kuX6lW3h43JEbr/Pn/TrfULOvGLET6R4STc0IfSIQTpOUogwBrgI= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=/+2qlwnzsncw3xj6gwj6k4QofDw=; b=BpfxLwsL5V+NhI8nX/Ac u4SPmLrGiTPtMHPWTg2Wqd+I5FokEbEWfpwpFJc1MTrZ6a9CdXHEaaJy8iHk6Xa8 ei3kR2eCwP8vEDvOmnZxd5rp/nJn1udbDHV1w0Nm8dLsNHFrvMkZQDog6R5AFWA3 YLveurLPivy+ZdfyJ1un3eU= Received: (qmail 23998 invoked by alias); 26 Mar 2014 17:02:53 -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 23873 invoked by uid 89); 26 Mar 2014 17:02:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 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; Wed, 26 Mar 2014 17:02:49 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2QH2miH029824 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 26 Mar 2014 13:02:48 -0400 Received: from stumpy.slc.redhat.com (ovpn-113-90.phx2.redhat.com [10.3.113.90]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s2QH2mS2021104 for ; Wed, 26 Mar 2014 13:02:48 -0400 Message-ID: <53330838.7010402@redhat.com> Date: Wed, 26 Mar 2014 11:02:48 -0600 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: gcc-patches Subject: [RFA][PATCH][pr target/60648] Fix non-canonical RTL from x86 backend -- P1 regression X-IsSubscribed: yes The x86 backend can generate non-canonical RTL when it simplifies address expressions. In particular addresses which have the form (plus (mult) (A) (B) (label_ref)) If the multiplication can be simplified to a constant, the x86 backend will end up generating (plus (constant) (label_ref)) Which is obviously non-canonical and should be written (const (plus (label_ref) (constant)) This change merely canonicalizes the RTL, leaving it to other code to simplify. At first I wanted to simplify, but it just gets painful if, for example B above is (const_int 0), in which case our example collapses into (label_ref) The subsequent code in the ix86_legitimize_address assumes it's still working with a PLUS. Fixable, but painful. It's also the case that simplify_rtx might return NULL. So the code also has to DTRT in that case and the caller's don't DTRT if ix86_legitimize_address returns NULL. Anyway, I did verify that the relevant code in the short example gets optimized if we just fix the canonicalization (namely the addition of (const_int 0) is eliminated). Bootstrapped and regression tested on x86_64-unknown-linux-gnu. Verified it fixes the original and reduced testcase. OK for the trunk? diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 53d58b3..80f0ba8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2014-03-26 Jeff Law + + * i386/i386.c (ix86_legitimize_address): Canonicalize + (plus (const) (label_ref)). + 2014-03-26 Richard Biener * tree-pretty-print.c (percent_K_format): Implement special diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 842be68..79f4aff 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -13939,6 +13939,28 @@ ix86_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, && REG_P (XEXP (x, 0))) return x; + /* We might have started with something like + + (plus (mult (const_int 1) (const_int 4)) (label_ref)) + + Which we change into: + + (plus (const_int 4) (label_ref)) + + Which is obviously not canonical RTL. Passing the non + canonical RTL up to our caller is bad. + + Do not simplify, just canonicalize. Simplification opens up + a can of worms here as that can change the structure of X which + this code isn't really prepared to handle. */ + if (COMMUTATIVE_ARITH_P (x) + && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1))) + { + rtx temp = XEXP (x, 0); + XEXP (x, 0) = XEXP (x, 1); + XEXP (x, 1) = temp; + } + if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1))) { changed = 1; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cdc8e9a..789e27d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-02-27 Jeff Law + + PR target/60648 + * g++.dg/pr60648.C: New test. + 2014-03-26 Jakub Jelinek PR sanitizer/60636