From patchwork Thu Feb 6 19:33:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 317526 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 6A3FC2C007A for ; Fri, 7 Feb 2014 06:33:35 +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=Yd885iR4vWIq9Vleqqi7Tjwn1xtdx1LeGDO125ySrT0qPd jBbsC4tdXRguaVAsx2XKeJg9bvyNJQehLj9qvwZDxAenPKEOKJ5npcKsjZmWL9eC qKSYEm64+4s6rHpk5M7D6s2kf+JZaTU/QhbLPjZxITaFeiihFKUXQCYqmYuTk= 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=S5leFHFAT7gtF/AtiiCsi5Uq0C0=; b=jNI3Nwn671XnP03fpzgT 3u4uXGUGxe/8WJyHH+pTvHF0whpTcdnBtveoP4n56q43LsibfepGe5NA4SrorXI9 V2VBllNp66DzXOtxhFS29CXnmzUQrL7OV4j0H63t/fhHKgI/5U/SjErxF2bOpAkM NkfHJ7gWAXBEBjG+e2Cszbw= Received: (qmail 20232 invoked by alias); 6 Feb 2014 19:33:28 -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 20223 invoked by uid 89); 6 Feb 2014 19:33:28 -0000 Authentication-Results: sourceware.org; auth=none 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; Thu, 06 Feb 2014 19:33:16 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s16JXFr5001405 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 6 Feb 2014 14:33:15 -0500 Received: from stumpy.slc.redhat.com (ovpn-113-146.phx2.redhat.com [10.3.113.146]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s16JXEe3029350 for ; Thu, 6 Feb 2014 14:33:14 -0500 Message-ID: <52F3E37A.1010207@redhat.com> Date: Thu, 06 Feb 2014 12:33:14 -0700 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: gcc-patches Subject: [RFA] [middle-end/54041] Convert modes as needed from expand_expr X-IsSubscribed: yes expand_expr has, for as long as I can remember, had the ability to ignore the desired mode provided by its callers and instead returning something in a completely different mode. It's always been the caller's responsibility to deal with that. For the testcase in 54041, we call expand_expr with a desired mode of SImode, but it actually returns a HImode object. This causes the assertion in convert_memory_address_addr_space to trip because the passed mode must be the same as the mode of the memory address. The fix is simple. If expand_expr returns something in the wrong mode, convert it to the desired mode. I've reviewed the resulting code for the m68k target and it looks correct to me. I've also bootstrapped and regression tested on x86_64-unknown-linux-gnu, though the new code most certainly does not trigger there. I guess if someone really wanted to be thorough, they'd test on a target where pointers and integers are different sizes. OK for the trunk? Thanks, Jeff diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2dbab72..4c7da83 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2014-02-05 Jeff Law + + PR middle-end/54041 + * expr.c (expand_expr_addr_1): Handle expand_expr returning an + object with an undesirable mode. + 2014-02-05 Bill Schmidt * config/rs6000/rs6000.c (altivec_expand_vec_perm_const): Change diff --git a/gcc/expr.c b/gcc/expr.c index 878a51b..9609c45 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -7708,6 +7708,11 @@ expand_expr_addr_expr_1 (tree exp, rtx target, enum machine_mode tmode, modifier == EXPAND_INITIALIZER ? EXPAND_INITIALIZER : EXPAND_NORMAL); + /* expand_expr is allowed to return an object in a mode other + than TMODE. If it did, we need to convert. */ + if (tmode != GET_MODE (tmp)) + tmp = convert_modes (tmode, GET_MODE (tmp), + tmp, TYPE_UNSIGNED (TREE_TYPE (offset))); result = convert_memory_address_addr_space (tmode, result, as); tmp = convert_memory_address_addr_space (tmode, tmp, as); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c81a00d..283912d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-02-05 Jeff Law + + PR middle-end/54041 + * gcc.target/m68k/pr54041.c: New test. + 2014-02-05 Bill Schmidt * gcc.dg/vmx/sum2s.c: New. diff --git a/gcc/testsuite/gcc.target/m68k/pr54041.c b/gcc/testsuite/gcc.target/m68k/pr54041.c new file mode 100644 index 0000000..645cb6d --- /dev/null +++ b/gcc/testsuite/gcc.target/m68k/pr54041.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O -mshort" } */ + +extern int r[]; + +int *fn(int i) +{ + return &r[i]; +} +