From patchwork Wed Oct 10 06:42:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 190567 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 9D5C22C0088 for ; Wed, 10 Oct 2012 17:42:34 +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=1350456154; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc: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=RRpnljMjIdTgh3zoMHYw khXm+q8=; b=mB70vpWaQU4LbbLgoqDiEb1dH+Flw1A/7JnDERrCnzfYA/ADllpo VelyBtX5IE0n5cb9EtIJQe5M/hY+ry2l3Clb58FPLjfVF3qC7GVILqSg3HAB3dLf 1hZwXg5ZjvJE+6dDXrikRFYqKPWa0efkf8qINQo/QVmKD5RdoEZZOwA= 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:Cc: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=sF1oeHKd4Qbg7Cswpco4XLVL9cV5mZtpuLWeJ9u+eVLCSUsaABXzJxLH9hKcWH qRIEMtqHn2VIco5iSWaAWHFzXZo9+B31BveWROEUWecag3Fc0t/fI0EfYn0cJKI0 vIhuEBj7x6nbtH2rzug0cI0/NeMFAXXVJ5E81r4byFSH4=; Received: (qmail 1109 invoked by alias); 10 Oct 2012 06:42:29 -0000 Received: (qmail 1008 invoked by uid 22791); 10 Oct 2012 06:42:27 -0000 X-SWARE-Spam-Status: No, hits=-7.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM 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; Wed, 10 Oct 2012 06:42:21 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9A6gLGo009614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 10 Oct 2012 02:42:21 -0400 Received: from zalov.redhat.com (vpn1-7-201.ams2.redhat.com [10.36.7.201]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9A6gJMj011843 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 10 Oct 2012 02:42:21 -0400 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id q9A6gJJh018525; Wed, 10 Oct 2012 08:42:19 +0200 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id q9A6gIIm018524; Wed, 10 Oct 2012 08:42:18 +0200 Date: Wed, 10 Oct 2012 08:42:18 +0200 From: Jakub Jelinek To: Richard Guenther Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix MINUS_EXPR vect reduction handling (PR tree-optimization/54877) Message-ID: <20121010064218.GL26735@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! As the testcase shows, a REAL_CST can appear in MINUS_EXPR as second operand (that is not canonicalized to PLUS_EXPR of negated value, unlike integer constants (with exception of minimum value)). The following patch handles constants there and punts if it isn't SSA_NAME or a constant that can be negated. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2012-10-10 Jakub Jelinek PR tree-optimization/54877 * tree-vect-loop.c (vect_is_simple_reduction_1): For MINUS_EXPR, check if rhs2 is SSA_NAME, if not and is constant, try to negate it, otherwise bail out. * gcc.dg/torture/pr54877.c: New test. Jakub --- gcc/tree-vect-loop.c.jj 2012-10-05 13:21:22.000000000 +0200 +++ gcc/tree-vect-loop.c 2012-10-09 20:45:18.559048120 +0200 @@ -2382,16 +2382,41 @@ vect_is_simple_reduction_1 (loop_vec_inf if (orig_code == MINUS_EXPR) { tree rhs = gimple_assign_rhs2 (def_stmt); - tree negrhs = copy_ssa_name (rhs, NULL); - gimple negate_stmt = gimple_build_assign_with_ops (NEGATE_EXPR, negrhs, - rhs, NULL); - gimple_stmt_iterator gsi = gsi_for_stmt (def_stmt); - set_vinfo_for_stmt (negate_stmt, new_stmt_vec_info (negate_stmt, - loop_info, NULL)); - gsi_insert_before (&gsi, negate_stmt, GSI_NEW_STMT); - gimple_assign_set_rhs2 (def_stmt, negrhs); - gimple_assign_set_rhs_code (def_stmt, PLUS_EXPR); - update_stmt (def_stmt); + + if (TREE_CODE (rhs) == SSA_NAME) + { + tree negrhs = copy_ssa_name (rhs, NULL); + gimple negate_stmt + = gimple_build_assign_with_ops (NEGATE_EXPR, negrhs, rhs, NULL); + gimple_stmt_iterator gsi = gsi_for_stmt (def_stmt); + set_vinfo_for_stmt (negate_stmt, + new_stmt_vec_info (negate_stmt, + loop_info, NULL)); + gsi_insert_before (&gsi, negate_stmt, GSI_NEW_STMT); + gimple_assign_set_rhs2 (def_stmt, negrhs); + gimple_assign_set_rhs_code (def_stmt, PLUS_EXPR); + update_stmt (def_stmt); + orig_code = PLUS_EXPR; + } + else if (is_gimple_constant (rhs) + && !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (rhs)))) + { + tree negrhs = fold_unary (NEGATE_EXPR, TREE_TYPE (rhs), rhs); + if (negrhs && is_gimple_val (negrhs)) + { + gimple_assign_set_rhs2 (def_stmt, negrhs); + gimple_assign_set_rhs_code (def_stmt, PLUS_EXPR); + update_stmt (def_stmt); + orig_code = PLUS_EXPR; + } + } + if (orig_code == MINUS_EXPR) + { + if (dump_kind_p (MSG_NOTE)) + report_vect_op (MSG_NOTE, def_stmt, + "reduction: unhandled minus expr: "); + return NULL; + } } /* Reduction is safe. We're dealing with one of the following: --- gcc/testsuite/gcc.dg/torture/pr54877.c.jj 2012-10-09 20:50:43.083259039 +0200 +++ gcc/testsuite/gcc.dg/torture/pr54877.c 2012-10-09 20:51:40.463941703 +0200 @@ -0,0 +1,23 @@ +/* PR tree-optimization/54877 */ +/* { dg-do run } */ +/* { dg-options "-ffast-math" } */ + +extern void abort (void); + +int +foo (void) +{ + double d; + int i; + for (i = 0, d = 0; i < 64; i++) + d--; + return (int) d; +} + +int +main () +{ + if (foo () != -64) + abort (); + return 0; +}