public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94785] New: Failure to detect abs pattern using multiplication
@ 2020-04-27  7:57 gabravier at gmail dot com
  2020-04-27  8:06 ` [Bug middle-end/94785] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gabravier at gmail dot com @ 2020-04-27  7:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94785

            Bug ID: 94785
           Summary: Failure to detect abs pattern using multiplication
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

unsigned r(int v)
{
    return (1 | -(v < 0)) * v;
}

`r` is equivalent to `abs(v)`. GCC does not make the transformation to an
`abs`.

Example of the optimization not being done : https://godbolt.org/z/Rw-hBt

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/94785] Failure to detect abs pattern using multiplication
  2020-04-27  7:57 [Bug tree-optimization/94785] New: Failure to detect abs pattern using multiplication gabravier at gmail dot com
@ 2020-04-27  8:06 ` rguenth at gcc dot gnu.org
  2020-12-30 11:08 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-27  8:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94785

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |middle-end
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Keywords|                            |easyhack
   Last reconfirmed|                            |2020-04-27

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note you likely want 1U | -(... as otherwise you implicitely assert that
v != INT_MIN due to -1 * INT_MIN invoking undefined overflow.  We still
can do the transform to abs, of course.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/94785] Failure to detect abs pattern using multiplication
  2020-04-27  7:57 [Bug tree-optimization/94785] New: Failure to detect abs pattern using multiplication gabravier at gmail dot com
  2020-04-27  8:06 ` [Bug middle-end/94785] " rguenth at gcc dot gnu.org
@ 2020-12-30 11:08 ` jakub at gcc dot gnu.org
  2020-12-31 10:08 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-12-30 11:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94785

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 49859
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49859&action=edit
gcc11-pr94785.patch

Untested fix.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/94785] Failure to detect abs pattern using multiplication
  2020-04-27  7:57 [Bug tree-optimization/94785] New: Failure to detect abs pattern using multiplication gabravier at gmail dot com
  2020-04-27  8:06 ` [Bug middle-end/94785] " rguenth at gcc dot gnu.org
  2020-12-30 11:08 ` jakub at gcc dot gnu.org
@ 2020-12-31 10:08 ` cvs-commit at gcc dot gnu.org
  2020-12-31 10:13 ` jakub at gcc dot gnu.org
  2021-11-16  3:32 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-31 10:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94785

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:8f12ce2ea3be12de4f83d3c419bdb1dc5036b202

commit r11-6377-g8f12ce2ea3be12de4f83d3c419bdb1dc5036b202
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Dec 31 11:08:15 2020 +0100

    match.pd: Add (-(X < 0) | 1) * X -> abs (X) etc. simplifications [PR94785]

    The following patch adds two simplifications to recognize idioms
    for ABS_EXPR resp. ABSU_EXPR.

    2020-12-31  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/94785
            * match.pd ((-(X < 0) | 1) * X -> abs (X)): New simplification.
            ((-(X < 0) | 1U) * X -> absu (X)): Likewise.

            * gcc.dg/tree-ssa/pr94785.c: New test.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/94785] Failure to detect abs pattern using multiplication
  2020-04-27  7:57 [Bug tree-optimization/94785] New: Failure to detect abs pattern using multiplication gabravier at gmail dot com
                   ` (2 preceding siblings ...)
  2020-12-31 10:08 ` cvs-commit at gcc dot gnu.org
@ 2020-12-31 10:13 ` jakub at gcc dot gnu.org
  2021-11-16  3:32 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-12-31 10:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94785

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for GCC 11.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/94785] Failure to detect abs pattern using multiplication
  2020-04-27  7:57 [Bug tree-optimization/94785] New: Failure to detect abs pattern using multiplication gabravier at gmail dot com
                   ` (3 preceding siblings ...)
  2020-12-31 10:13 ` jakub at gcc dot gnu.org
@ 2021-11-16  3:32 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-16  3:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94785

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:3200de91bc70bfd6d4b7b40e769bc82756b9b555

commit r12-5291-g3200de91bc70bfd6d4b7b40e769bc82756b9b555
Author: Andrew Pinski <apinski@marvell.com>
Date:   Mon Nov 15 22:55:09 2021 +0000

    tree-optimization: [PR103245] Improve detection of abs pattern using
multiplication

    So while working on PR 103228 (and a few others), I noticed the testcase
for PR 94785
    was failing. The problem is that the nop_convert moved from being inside
the IOR to be
    outside of it. I also noticed the patch for PR 103228 was not needed to
reproduce the
    issue either.
    This patch combines the two patterns together for the abs match when using
multiplication
    and adds a few places where nop_convert are optional.

    OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

            PR tree-optimization/103245

    gcc/ChangeLog:

            * match.pd: Combine the abs pattern matching using multiplication.
            Adding optional nop_convert too.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/pr103245-1.c: New test.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-11-16  3:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27  7:57 [Bug tree-optimization/94785] New: Failure to detect abs pattern using multiplication gabravier at gmail dot com
2020-04-27  8:06 ` [Bug middle-end/94785] " rguenth at gcc dot gnu.org
2020-12-30 11:08 ` jakub at gcc dot gnu.org
2020-12-31 10:08 ` cvs-commit at gcc dot gnu.org
2020-12-31 10:13 ` jakub at gcc dot gnu.org
2021-11-16  3:32 ` cvs-commit at gcc dot gnu.org

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).