From patchwork Thu Jan 17 18:22:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 213343 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]) by ozlabs.org (Postfix) with SMTP id 0379B2C007E for ; Fri, 18 Jan 2013 05:23:07 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1359051788; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=24WY9YPi07cnnWKBAaJ4 XA6Qkbw=; b=bdOayin6TLQA+xMSIPXNksYlN93z1n+d2sG4z8Bq+0NWuuztmavi j/eZ2znMHLiGQqsL1P3OcMDfWzvlTlH7bPWDqaqDS2ry4/ni3xNqKjDBpv1x/FRW b5A5/ekvmtgrDtNJHnI7aRFdPXYsFCHojURcrtqPPZaAPkeHAyLTyXI= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=oRZXljm5NYFXHwcpttLVfkDiuoA1cCdI/tybD4YDUcBaCIUSx62aEjAwUYH3J3 yMq7VZzTNyIhh7VygNC7oHnjujo+d+g00fJnbkzmgPgPFjD/3bz8IJMurAh6c4n9 mLVZOGDnuppbPONeofWqMstRq5RgKbONNuo0exfPdSJhM=; Received: (qmail 22591 invoked by alias); 17 Jan 2013 18:22:55 -0000 Received: (qmail 22577 invoked by uid 22791); 17 Jan 2013 18:22:52 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 17 Jan 2013 18:22:41 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0HIMeR7005064 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 17 Jan 2013 13:22:40 -0500 Received: from zalov.redhat.com (vpn1-5-204.ams2.redhat.com [10.36.5.204]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0HIMc46014404 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 17 Jan 2013 13:22:40 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id r0HIMb2E027509 for ; Thu, 17 Jan 2013 19:22:37 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r0HIMbis027508 for gcc-patches@gcc.gnu.org; Thu, 17 Jan 2013 19:22:37 +0100 Date: Thu, 17 Jan 2013 19:22:36 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix COMPLEX_EXPR expansion (PR middle-end/56015) Message-ID: <20130117182236.GV7269@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! If target (the real part thereof) overlap op1 (i.e. the imag part of COMPLEX_EXPR to be stored), we end up with first overwriting the real part and then using wrong value in op1. Fixed by testing for overlap, and either, if possible, doing the writes in different order if overlap is detected (first write imag part, then real part), or, if not possible, forcing op1 into a register. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-01-17 Jakub Jelinek PR middle-end/56015 * expr.c (expand_expr_real_2) : Handle the case where writing real complex part of target modifies op1. * gfortran.dg/pr56015.f90: New test. Jakub --- gcc/expr.c.jj 2013-01-11 09:02:48.000000000 +0100 +++ gcc/expr.c 2013-01-17 11:21:34.326854116 +0100 @@ -8860,6 +8860,54 @@ expand_expr_real_2 (sepops ops, rtx targ if (!target) target = gen_reg_rtx (TYPE_MODE (type)); + else + /* If target overlaps with op1, then either we need to force + op1 into a pseudo (if target also overlaps with op0), + or write the complex parts in reverse order. */ + switch (GET_CODE (target)) + { + case CONCAT: + if (reg_overlap_mentioned_p (XEXP (target, 0), op1)) + { + if (reg_overlap_mentioned_p (XEXP (target, 1), op0)) + { + complex_expr_force_op1: + temp = gen_reg_rtx (GET_MODE_INNER (GET_MODE (target))); + emit_move_insn (temp, op1); + op1 = temp; + break; + } + complex_expr_swap_order: + /* Move the imaginary (op1) and real (op0) parts to their + location. */ + write_complex_part (target, op1, true); + write_complex_part (target, op0, false); + + return target; + } + break; + case MEM: + temp = adjust_address_nv (target, + GET_MODE_INNER (GET_MODE (target)), 0); + if (reg_overlap_mentioned_p (temp, op1)) + { + enum machine_mode imode = GET_MODE_INNER (GET_MODE (target)); + temp = adjust_address_nv (target, imode, + GET_MODE_SIZE (imode)); + if (reg_overlap_mentioned_p (temp, op0)) + goto complex_expr_force_op1; + goto complex_expr_swap_order; + } + break; + default: + if (reg_overlap_mentioned_p (target, op1)) + { + if (reg_overlap_mentioned_p (target, op0)) + goto complex_expr_force_op1; + goto complex_expr_swap_order; + } + break; + } /* Move the real (op0) and imaginary (op1) parts to their location. */ write_complex_part (target, op0, false); --- gcc/testsuite/gfortran.dg/pr56015.f90.jj 2013-01-17 11:16:27.793639775 +0100 +++ gcc/testsuite/gfortran.dg/pr56015.f90 2013-01-17 11:15:59.000000000 +0100 @@ -0,0 +1,16 @@ +! PR middle-end/56015 +! { dg-do run } +! { dg-options "-Ofast -fno-inline" } + +program pr56015 + implicit none + complex*16 p(10) + p(:) = (0.1d0, 0.2d0) + p(:) = (0.0d0, 1.0d0) * p(:) + call foo (p) +contains + subroutine foo (p) + complex*16 p(10) + if (any (p .ne. (-0.2d0, 0.1d0))) call abort + end subroutine +end program pr56015