From patchwork Mon Apr 8 19:23:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 234870 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id C8EDB2C00A5 for ; Tue, 9 Apr 2013 05:24:16 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=wnNKwtUOTfNAMpWtEKapOieggjoph d4ycWoevAa8qioHJWuMRWtSv6TlYatqToQFWBHzpB+FOoebaPnpEdiSVZke7QUjG Su/41xmafS0UZQhs0ZgKECnpSJY4fuNENZaeCcy7LDZIpS/36puYecTBajWPrsh0 Z+O8lK5eyKhdPo= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=ryY7LMcWeVIg1XoVYuZ8CPVbNGk=; b=vPB O12LtI0l8gWop/zgR7Ce7LllsnkzTNaaCaO76Izj8g4fYRl27894mBgP9R19ra+H KU+GgT5ClDXXlNQJmK+Vu0I8GZRV3BRVAi93C0COAk9EwocnboX+4SP+ewKdYJPC lSmPo7Ek332d7g/8uPn/FF8P8iNDvwuPOJgEzvKw= Received: (qmail 19182 invoked by alias); 8 Apr 2013 19:24:07 -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 19171 invoked by uid 89); 8 Apr 2013 19:24:07 -0000 X-Spam-SWARE-Status: No, score=-7.5 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 08 Apr 2013 19:24:07 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r38JO5BW011909 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 8 Apr 2013 15:24:06 -0400 Received: from zalov.cz (vpn1-6-248.ams2.redhat.com [10.36.6.248]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r38JO3mJ009248 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 8 Apr 2013 15:24:05 -0400 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.cz (8.14.5/8.14.5) with ESMTP id r38JNuTY006518; Mon, 8 Apr 2013 21:24:01 +0200 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r38JNrN7006517; Mon, 8 Apr 2013 21:23:53 +0200 Date: Mon, 8 Apr 2013 21:23:47 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Don't forwprop into clobbers in some cases (PR tree-optimization/56854) Message-ID: <20130408192347.GR20334@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi! lhs ={v} {CLOBBER}; stmts right now allow only VAR_DECL or MEM_REF lhs, but the forwprop code below on the attached testcase attempts to propagate an ARRAY_REF (of MEM_REF) into it. Fixed by not propagating in that case, allowing arbitrary memory lhs is IMHO unnecessary and such lhs's wouldn't be very useful for DSE anyway. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-04-08 Jakub Jelinek PR tree-optimization/56854 * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Don't forward into clobber stmts if it would change MEM_REF lhs into non-MEM_REF. * g++.dg/torture/pr56854.C: New test. Jakub --- gcc/tree-ssa-forwprop.c.jj 2013-02-25 23:51:21.000000000 +0100 +++ gcc/tree-ssa-forwprop.c 2013-04-08 16:12:37.000000000 +0200 @@ -826,7 +826,11 @@ forward_propagate_addr_expr_1 (tree name && integer_zerop (TREE_OPERAND (lhs, 1)) && useless_type_conversion_p (TREE_TYPE (TREE_OPERAND (def_rhs, 0)), - TREE_TYPE (gimple_assign_rhs1 (use_stmt)))) + TREE_TYPE (gimple_assign_rhs1 (use_stmt))) + /* Don't forward anything into clobber stmts if it would result + in the lhs no longer being a MEM_REF. */ + && (!gimple_clobber_p (use_stmt) + || TREE_CODE (TREE_OPERAND (def_rhs, 0)) == MEM_REF)) { tree *def_rhs_basep = &TREE_OPERAND (def_rhs, 0); tree new_offset, new_base, saved, new_lhs; --- gcc/testsuite/g++.dg/torture/pr56854.C.jj 2013-04-08 18:03:37.978009666 +0200 +++ gcc/testsuite/g++.dg/torture/pr56854.C 2013-04-08 18:03:09.000000000 +0200 @@ -0,0 +1,24 @@ +// PR tree-optimization/56854 +// { dg-do compile } + +inline void * +operator new (__SIZE_TYPE__, void *p) throw () +{ + return p; +} + +struct A +{ + int a; + A () : a (0) {} + ~A () {} + A &operator= (const A &v) { this->~A (); new (this) A (v); return *this; } +}; +A b[4], c[4]; + +void +foo () +{ + for (int i = 0; i < 4; ++i) + c[i] = b[i]; +}