From patchwork Sat Nov 20 13:14:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1557612 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=XLhD39DC; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HxDXL376sz9t0k for ; Sun, 21 Nov 2021 00:14:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 379D8385783B for ; Sat, 20 Nov 2021 13:14:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 7BEF8385840D for ; Sat, 20 Nov 2021 13:14:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7BEF8385840D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=cGnCCU2EsdfgJqF0dzT/A99ySrFPkWV7Gx5InxQKjC4=; b=XLhD39DC1gxXAOHu0DFmUSYmh4 cFKx7zEdjbrmURwQOIBGoptflL4YF1asN+c0Vv29TQs6hJx88oSgMEG+7IOY9tVEzll6SB8J4x3u4 PYrmOhpTiqUdH8IrIA4EFlkTA65t6ahIhlyTy5tsZLMo8brOVxqnpoIwL1PNKayPz5rr6m+jTWEqW dg/UzvOq8MNKZg/4MDAgw334C7AZFBUK/iLBA/Nw/I3qbHqz5sMTdTfiXgleI7V0nUbe6ehzK7zMe GQ8Ix2SFxG1DdUyiCcY+k6uF0VrScOjnG6R27vAcZtRmebZKgHiTes/2TFfjZPNJd0CW5C0cRgXFN K+4Ti0YQ==; Received: from host81-157-90-156.range81-157.btcentralplus.com ([81.157.90.156]:58663 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1moQCL-000724-Gr; Sat, 20 Nov 2021 08:14:11 -0500 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] Tweak tree-ssa-math-opts.c to solve PR target/102117 Date: Sat, 20 Nov 2021 13:14:09 -0000 Message-ID: <027401d7de10$8245e260$86d1a720$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdfeEAfmK9/srBLEQvSYVSeiLOpi7A== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch resolves PR target/102117 on s390. The problem is that some of the functionality of GCC's RTL expanders is no longer triggered following the transition to tree SSA form. On s390, unsigned widening multiplications are converted into WIDEN_MULT_EXPR (aka w* in tree dumps), but signed widening multiplies are left in their original form, which alas doesn't benefit from the clever logic in expand_widening_mult. The fix is to teach convert_mult_to_widen, that RTL expansion can synthesize a signed widening multiplication if the target provides a suitable umul_widen_optab. On s390-linux-gnu with -O2 -m64, the code in the bugzilla PR currently generates: imul128: stmg %r12,%r13,96(%r15) srag %r0,%r4,63 srag %r1,%r3,63 lgr %r13,%r3 mlgr %r12,%r4 msgr %r1,%r4 msgr %r0,%r3 lgr %r4,%r12 agr %r1,%r0 lgr %r5,%r13 agr %r4,%r1 stmg %r4,%r5,0(%r2) lmg %r12,%r13,96(%r15) br %r14 but with this patch should now generate the more efficient: imul128: lgr %r1,%r3 mlgr %r0,%r4 srag %r5,%r3,63 ngr %r5,%r4 srag %r4,%r4,63 sgr %r0,%r5 ngr %r4,%r3 sgr %r0,%r4 stmg %r0,%r1,0(%r2) br %r14 This patch has been tested s390/z13 with a bootstrap and a regression test (thanks to Robin Dapp), and on x86_64-pc-linux-gnu with a bootstrap and regression test just to confirm that there are no unanticipated side-effects. Ok for mainline? 2021-11-20 Roger Sayle Robin Dapp gcc/ChangeLog PR target/102117 * tree-ssa-math-opts.c (convert_mult_to_widen): Recognize signed WIDEN_MULT_EXPR if the target supports umul_widen_optab. gcc/testsuite/ChangeLog PR target/102117 * gcc.target/s390/mul-wide.c: New test case. * gcc.target/s390/umul-wide.c: New test case. Thanks in advance, Roger diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index c4a6492..a944903 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -2723,7 +2723,16 @@ convert_mult_to_widen (gimple *stmt, gimple_stmt_iterator *gsi) from_unsigned1 = from_unsigned2 = false; } else - return false; + { + /* Expand can synthesize smul_widen_optab if the target + supports umul_widen_optab. */ + op = umul_widen_optab; + handler = find_widening_optab_handler_and_mode (op, to_mode, + from_mode, + &actual_mode); + if (handler == CODE_FOR_nothing) + return false; + } } /* Ensure that the inputs to the handler are in the correct precison diff --git a/gcc/testsuite/gcc.target/s390/mul-wide.c b/gcc/testsuite/gcc.target/s390/mul-wide.c new file mode 100644 index 0000000..8a2092e --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/mul-wide.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -m64 -fdump-tree-optimized" } */ + +__int128 foo(long long a, long long b) +{ + return (__int128)a * (__int128)b; +} + +/* { dg-final { scan-tree-dump " w\\* " "optimized" } } */ diff --git a/gcc/testsuite/gcc.target/s390/umul-wide.c b/gcc/testsuite/gcc.target/s390/umul-wide.c new file mode 100644 index 0000000..33a74e5 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/umul-wide.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -m64 -fdump-tree-optimized" } */ + +unsigned __int128 foo(unsigned long long a, unsigned long long b) +{ + return (unsigned __int128)a * (unsigned __int128)b; +} + +/* { dg-final { scan-tree-dump " w\\* " "optimized" } } */