public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Roger Sayle <sayle@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5436] Tweak tree-ssa-math-opts.c to solve PR target/102117. Date: Sun, 21 Nov 2021 11:41:15 +0000 (GMT) [thread overview] Message-ID: <20211121114115.E9D373858C27@sourceware.org> (raw) https://gcc.gnu.org/g:dc915b361bbc99da83fc53db7f7e0e28d0ce12c8 commit r12-5436-gdc915b361bbc99da83fc53db7f7e0e28d0ce12c8 Author: Roger Sayle <roger@nextmovesoftware.com> Date: Sun Nov 21 11:40:08 2021 +0000 Tweak tree-ssa-math-opts.c to solve PR target/102117. 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 2021-11-21 Roger Sayle <roger@nextmovesoftware.com> Robin Dapp <rdapp@linux.ibm.com> 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. Diff: --- gcc/testsuite/gcc.target/s390/mul-wide.c | 9 +++++++++ gcc/testsuite/gcc.target/s390/umul-wide.c | 9 +++++++++ gcc/tree-ssa-math-opts.c | 11 ++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) 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 00000000000..8a2092e01c4 --- /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 00000000000..33a74e52170 --- /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" } } */ diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index cc8496c3c32..6131824191f 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
reply other threads:[~2021-11-21 11:41 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211121114115.E9D373858C27@sourceware.org \ --to=sayle@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).