From patchwork Sat Apr 14 17:05:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 152529 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 666BEB7004 for ; Sun, 15 Apr 2012 03:05:19 +1000 (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=1335027920; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:Received:Message-ID:Subject:From:To: Date:Content-Type:Content-Transfer-Encoding:Mime-Version: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=hgkwf8J/MwFDBPLeYCj/ hpgUrpI=; b=W0T+BjhWVmXS10aH3yEIjgMPm7T9lucQzX1AqMijqTXS5Z67dO7j BWL4nB+o2nIpmJUtYZc+8cKm/Vt5NH6jJ0qWmX6eJWaVAmhqj7SHozHXHTIyCA6L wAp2RspgAquQp9v83MwaaguX5IWBJgzMQiJ7WEtpUDR4ijVycrQ/1Uk= 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:Received:Received:Message-ID:Subject:From:To:Date:Content-Type:Content-Transfer-Encoding:Mime-Version:X-Content-Scanned:x-cbid:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=bqXCXP8RoIeYxumF5vjgiIrm9+JEtwRW9pWiIpCdDtV0FTRSrCJ1jmPVPTA7ET 18sVgmnOoEXr35l1B4/PTclWAcTRINXqxafIWoZ2dx7oI+iUOeKbOOe5q6oTnWWs rqPTJiDXmqhBkxvAOZb1PiUz4rZT5UCIwFi1fhWFdCP8w=; Received: (qmail 32402 invoked by alias); 14 Apr 2012 17:05:16 -0000 Received: (qmail 32391 invoked by uid 22791); 14 Apr 2012 17:05:15 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from e3.ny.us.ibm.com (HELO e3.ny.us.ibm.com) (32.97.182.143) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 14 Apr 2012 17:04:58 +0000 Received: from /spool/local by e3.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 14 Apr 2012 13:04:57 -0400 Received: from d01dlp01.pok.ibm.com (9.56.224.56) by e3.ny.us.ibm.com (192.168.1.103) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 14 Apr 2012 13:04:55 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 2F2CE38C805A for ; Sat, 14 Apr 2012 13:04:54 -0400 (EDT) Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q3EH4s8F234900 for ; Sat, 14 Apr 2012 13:04:54 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q3EH4rFG007843 for ; Sat, 14 Apr 2012 13:04:54 -0400 Received: from [9.49.138.10] (sig-9-49-138-10.mts.ibm.com [9.49.138.10]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q3EH4qQ0007816 for ; Sat, 14 Apr 2012 13:04:53 -0400 Message-ID: <1334423102.19102.59.camel@gnopaine> Subject: [PATCH] Fix PR52976 From: "William J. Schmidt" To: gcc-patches@gcc.gnu.org Date: Sat, 14 Apr 2012 12:05:02 -0500 Mime-Version: 1.0 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12041417-8974-0000-0000-0000082A193C 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 This patch corrects two errors in reassociating expressions with repeated factors. First, undistribution needs to recognize repeated factors. For now, repeated factors will be ineligible for this optimization. In the future, this can be improved. Second, when a __builtin_powi call is introduced, its target SSA name must be given a rank higher than other operands in the operand list. Otherwise, uses of the call result may be introduced prior to the call. Bootstrapped and regression tested on powerpc64-linux. Confirmed that cpu2000 and cpu2006 SPEC tests build cleanly. OK for trunk? Thanks, Bill 2012-04-14 Bill Schmidt PR tree-optimization/52976 * tree-ssa-reassoc.c (add_to_ops_vec_max_rank): New function. (undistribute_ops_list): Ops with repeat counts aren't eligible for undistribution. (attempt_builtin_powi): Call add_to_ops_vec_max_rank. Index: gcc/tree-ssa-reassoc.c =================================================================== --- gcc/tree-ssa-reassoc.c (revision 186393) +++ gcc/tree-ssa-reassoc.c (working copy) @@ -544,6 +544,28 @@ add_repeat_to_ops_vec (VEC(operand_entry_t, heap) reassociate_stats.pows_encountered++; } +/* Add an operand entry to *OPS for the tree operand OP, giving the + new entry a larger rank than any other operand already in *OPS. */ + +static void +add_to_ops_vec_max_rank (VEC(operand_entry_t, heap) **ops, tree op) +{ + operand_entry_t oe = (operand_entry_t) pool_alloc (operand_entry_pool); + operand_entry_t oe1; + unsigned i; + unsigned max_rank = 0; + + FOR_EACH_VEC_ELT (operand_entry_t, *ops, i, oe1) + if (oe1->rank > max_rank) + max_rank = oe1->rank; + + oe->op = op; + oe->rank = max_rank + 1; + oe->id = next_operand_entry_id++; + oe->count = 1; + VEC_safe_push (operand_entry_t, heap, *ops, oe); +} + /* Return true if STMT is reassociable operation containing a binary operation with tree code CODE, and is inside LOOP. */ @@ -1200,6 +1222,7 @@ undistribute_ops_list (enum tree_code opcode, dcode = gimple_assign_rhs_code (oe1def); if ((dcode != MULT_EXPR && dcode != RDIV_EXPR) + || oe1->count != 1 || !is_reassociable_op (oe1def, dcode, loop)) continue; @@ -1243,6 +1266,8 @@ undistribute_ops_list (enum tree_code opcode, oecount c; void **slot; size_t idx; + if (oe1->count != 1) + continue; c.oecode = oecode; c.cnt = 1; c.id = next_oecount_id++; @@ -1311,7 +1336,7 @@ undistribute_ops_list (enum tree_code opcode, FOR_EACH_VEC_ELT (operand_entry_t, subops[i], j, oe1) { - if (oe1->op == c->op) + if (oe1->op == c->op && oe1->count == 1) { SET_BIT (candidates2, i); ++nr_candidates2; @@ -3275,8 +3300,10 @@ attempt_builtin_powi (gimple stmt, VEC(operand_ent gsi_insert_before (&gsi, pow_stmt, GSI_SAME_STMT); } - /* Append the result of this iteration to the ops vector. */ - add_to_ops_vec (ops, iter_result); + /* Append the result of this iteration to the ops vector. + Give it a rank higher than all other ranks in the ops vector + so that all uses of it will be forced to come after it. */ + add_to_ops_vec_max_rank (ops, iter_result); /* Decrement the occurrence count of each element in the product by the count found above, and remove this many copies of each