From patchwork Mon Oct 21 22:01:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yufeng Zhang X-Patchwork-Id: 285291 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 did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D2FDE2C016A for ; Tue, 22 Oct 2013 09:01:48 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=IxNyqmmy5g3OpqFhAUxm7WgVOjE7d06I+csAyXLby8N e4ZB/yefRXH9LA9QHNRPHBx8zrxV2acfLhRjifrHosYy2dzm3QZ+QAHr9/KybBZl FOKP12dKR/h+kTVPL8/fGrl+UWKNeLwZrdkE/ysvdgTTul61tepR8uEYdlKvjwcU = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=BxUlWMvGIgA4c0PhPLG68c5DcOU=; b=IsKxwv1/KXnolI05O pYVvuuOLOdZhnH2kNB6lH1TJnXteTgRBOyN2ScrovkvWkI7Fpww48isPI7Ali9Kk HS3YyX0tXD7rwOvPsZKiAhgkZBxKJDzSVUiy026CeohSMtggXre1+hBukRLiCYPB dS6H4VlgniGBC4C2CUVrATMS4s= Received: (qmail 13494 invoked by alias); 21 Oct 2013 22:01:41 -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 13480 invoked by uid 89); 21 Oct 2013 22:01:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, 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; Mon, 21 Oct 2013 22:01:39 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Mon, 21 Oct 2013 23:01:35 +0100 Received: from [10.1.201.52] ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.0); Mon, 21 Oct 2013 23:00:00 +0100 Message-ID: <5265A43E.7060507@arm.com> Date: Mon, 21 Oct 2013 23:01:34 +0100 From: Yufeng Zhang User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: ams@codesourcery.com Subject: [PATCH] Generate fused widening multiply-and-accumulate operations only when the widening multiply has single use X-MC-Unique: 113102123013500301 X-IsSubscribed: yes Hi, This patch changes the widening_mul pass to fuse the widening multiply with accumulate only when the multiply has single use. The widening_mul pass currently does the conversion regardless of the number of the uses, which can cause poor code-gen in cases like the following: typedef int ArrT [10][10]; void foo (ArrT Arr, int Idx) { Arr[Idx][Idx] = 1; Arr[Idx + 10][Idx] = 2; } On AArch64, after widening_mul, the IR is like _2 = (long unsigned int) Idx_1(D); _3 = Idx_1(D) w* 40; <---- _5 = Arr_4(D) + _3; *_5[Idx_1(D)] = 1; _8 = WIDEN_MULT_PLUS_EXPR ; <---- _9 = Arr_4(D) + _8; *_9[Idx_1(D)] = 2; Where the arrows point, there are redundant widening multiplies. Bootstrap successfully on x86_64. The patch passes the regtest on aarch64, arm and x86_64. OK for the trunk? Thanks, Yufeng p.s. Note that x86_64 doesn't suffer from this issue as the corresponding widening multiply accumulate op is not available on the target. gcc/ * tree-ssa-math-opts.c (convert_plusminus_to_widen): Call has_single_use () and not do the conversion if has_single_use () returns false for the multiplication result. diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index f7f8ec9..d316990 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -2425,12 +2425,16 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt, It might also appear that it would be sufficient to use the existing operands of the widening multiply, but that would limit the choice of - multiply-and-accumulate instructions. */ + multiply-and-accumulate instructions. + + If the widened-multiplication result has more than one uses, it is + probably wiser not to do the conversion. */ if (code == PLUS_EXPR && (rhs1_code == MULT_EXPR || rhs1_code == WIDEN_MULT_EXPR)) { if (!is_widening_mult_p (rhs1_stmt, &type1, &mult_rhs1, - &type2, &mult_rhs2)) + &type2, &mult_rhs2) + || !has_single_use (rhs1)) return false; add_rhs = rhs2; conv_stmt = conv1_stmt; @@ -2438,7 +2442,8 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt, else if (rhs2_code == MULT_EXPR || rhs2_code == WIDEN_MULT_EXPR) { if (!is_widening_mult_p (rhs2_stmt, &type1, &mult_rhs1, - &type2, &mult_rhs2)) + &type2, &mult_rhs2) + || !has_single_use (rhs2)) return false; add_rhs = rhs1; conv_stmt = conv2_stmt;