From patchwork Thu Sep 4 08:59:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Cheng X-Patchwork-Id: 385785 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 B3A3214012E for ; Thu, 4 Sep 2014 19:00:20 +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:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=DuCoFkQYMbdhjRi4wn+Muw2z5TvjytHj2Dbs5gud5WuxdoGVBY IwlwtTRPHDcXLBRtahnpfuWxKaCcYa5f3jyYE6rZWzrJlbBlZ2tLNh6PWxfOH8BY 8upP8DixYbU6JYZd5o65YE+Zgs4XmupdoHvGIuBIBNqh1jLRmEaNvJXy4= 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:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=K2BpwIpGFqWCMDqOd9lvHtlBXyE=; b=pBIoeT+QGwBdVM99PU9D yWFyxo6WbZdh2y5Mvkvg+E4E5yLe3AdHGMQMCUkKyD1Qt3bs73WIY/rGBzBmOPkR Yh8UwKYTPwGRgmEL7nxeb+sHGYAVmfyf78d6jLHBrA7ZB1qVwQB/lCastiBvcPyf fFAhq2F18otRSvnFbPbJq48= Received: (qmail 24771 invoked by alias); 4 Sep 2014 08:59:40 -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 24733 invoked by uid 89); 4 Sep 2014 08:59:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 04 Sep 2014 08:59:37 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Thu, 04 Sep 2014 09:59:34 +0100 Received: from shawin233 ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 4 Sep 2014 09:59:33 +0100 From: "Bin Cheng" To: Cc: Subject: [PATCH PR62631]Return shiftadd cost only when it's smaller than normal one Date: Thu, 4 Sep 2014 16:59:23 +0800 Message-ID: <000c01cfc81e$87780e80$96682b80$@arm.com> MIME-Version: 1.0 X-MC-Unique: 114090409593417901 X-IsSubscribed: yes Hi, As reported by pr62631, case ivopts-lt-2.c is failed on sparc64. The root cause is shiftadd_cost calculated on sparc64 is huge which prevents gcc from choosing the wanted candidate. The problem with IVOPT is it always assumes that shiftadd_cost is smaller than the normal cost, while it's not true in this extreme case. This patch checks if the shiftadd_cost is smaller before returning it. The patch also cleans code indent in context. One question is left here. Why >100 cost is calculated for shiftadd on sparc64? In final assembly code, the computation is implemented by separated shift and add instructions. Probably sparc64 should return cost no larger than cost(shift)+cost(add) in the first place?. Bootstrap and tested on x86_64/cortex-m3, the case is fixed on sparc64 now. Is it OK? Thanks, bin 2014-09-04 Bin Cheng * tree-ssa-loop-ivopts.c (force_expr_to_var_cost): Return cost calculated by get_shiftadd_cost only when it is smaller. Fix code indent. Index: gcc/tree-ssa-loop-ivopts.c =================================================================== --- gcc/tree-ssa-loop-ivopts.c (revision 214674) +++ gcc/tree-ssa-loop-ivopts.c (working copy) @@ -3730,20 +3730,23 @@ force_expr_to_var_cost (tree expr, bool speed) case NEGATE_EXPR: cost = new_cost (add_cost (speed, mode), 0); if (TREE_CODE (expr) != NEGATE_EXPR) - { - tree mult = NULL_TREE; - comp_cost sa_cost; - if (TREE_CODE (op1) == MULT_EXPR) - mult = op1; - else if (TREE_CODE (op0) == MULT_EXPR) - mult = op0; + { + tree mult = NULL_TREE; + comp_cost sa_cost; + if (TREE_CODE (op1) == MULT_EXPR) + mult = op1; + else if (TREE_CODE (op0) == MULT_EXPR) + mult = op0; - if (mult != NULL_TREE - && cst_and_fits_in_hwi (TREE_OPERAND (mult, 1)) - && get_shiftadd_cost (expr, mode, cost0, cost1, mult, - speed, &sa_cost)) - return sa_cost; - } + if (mult != NULL_TREE + && cst_and_fits_in_hwi (TREE_OPERAND (mult, 1)) + && get_shiftadd_cost (expr, mode, cost0, cost1, mult, + speed, &sa_cost) + && compare_costs (sa_cost, + add_costs (cost, + add_costs (cost0, cost1))) < 0) + return sa_cost; + } break; CASE_CONVERT: