public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95185] New: Failure to optimize specific kind of sign comparison check
@ 2020-05-18 12:05 gabravier at gmail dot com
  2020-05-18 13:15 ` [Bug tree-optimization/95185] " rguenth at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: gabravier at gmail dot com @ 2020-05-18 12:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95185
           Summary: Failure to optimize specific kind of sign comparison
                    check
           Product: gcc
           Version: 11.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: ---

int f(int x, int y)
{
    return (x >= 0) == (y <= 0);
}

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94718 was resolved and most of the
patterns are now optimized, but this specific one isn't. It's equivalent to `(x
< 0) ^ (y <= 0)`, which can be done with a single compare instead of two. That
transformation is made by LLVM, but not by GCC.

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

* [Bug tree-optimization/95185] Failure to optimize specific kind of sign comparison check
  2020-05-18 12:05 [Bug tree-optimization/95185] New: Failure to optimize specific kind of sign comparison check gabravier at gmail dot com
@ 2020-05-18 13:15 ` rguenth at gcc dot gnu.org
  2020-05-18 13:16 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-18 13:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Keywords|                            |easyhack,
                   |                            |missed-optimization
   Last reconfirmed|                            |2020-05-18
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.

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

* [Bug tree-optimization/95185] Failure to optimize specific kind of sign comparison check
  2020-05-18 12:05 [Bug tree-optimization/95185] New: Failure to optimize specific kind of sign comparison check gabravier at gmail dot com
  2020-05-18 13:15 ` [Bug tree-optimization/95185] " rguenth at gcc dot gnu.org
@ 2020-05-18 13:16 ` rguenth at gcc dot gnu.org
  2021-10-04 23:02 ` arjun.is at lostca dot se
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-18 13:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Btw, thanks for all these bugreports!

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

* [Bug tree-optimization/95185] Failure to optimize specific kind of sign comparison check
  2020-05-18 12:05 [Bug tree-optimization/95185] New: Failure to optimize specific kind of sign comparison check gabravier at gmail dot com
  2020-05-18 13:15 ` [Bug tree-optimization/95185] " rguenth at gcc dot gnu.org
  2020-05-18 13:16 ` rguenth at gcc dot gnu.org
@ 2021-10-04 23:02 ` arjun.is at lostca dot se
  2021-10-04 23:12 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: arjun.is at lostca dot se @ 2021-10-04 23:02 UTC (permalink / raw)
  To: gcc-bugs

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

Arjun Shankar <arjun.is at lostca dot se> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arjun.is at lostca dot se

--- Comment #3 from Arjun Shankar <arjun.is at lostca dot se> ---
If the code is compiled as C, gcc produces essentially the same code as clang
with some differences in the schedule of instructions:
https://godbolt.org/z/8nsq16Pen

It's when the code is compiled as C++ that gcc does worse:
https://godbolt.org/z/dK8hTEhjr

The difference lies in the front-ends. The C front-end already appears to know
that this is a XOR. testcase.c.004t.original looks like:

  return (int) (x < 0 ^ y <= 0);

On the other hand, g++ outputs:

  return <retval> = x >= 0 == y <= 0;

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

* [Bug tree-optimization/95185] Failure to optimize specific kind of sign comparison check
  2020-05-18 12:05 [Bug tree-optimization/95185] New: Failure to optimize specific kind of sign comparison check gabravier at gmail dot com
                   ` (2 preceding siblings ...)
  2021-10-04 23:02 ` arjun.is at lostca dot se
@ 2021-10-04 23:12 ` pinskia at gcc dot gnu.org
  2023-06-18 19:24 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-04 23:12 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=101807

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
related to PR 101807

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

* [Bug tree-optimization/95185] Failure to optimize specific kind of sign comparison check
  2020-05-18 12:05 [Bug tree-optimization/95185] New: Failure to optimize specific kind of sign comparison check gabravier at gmail dot com
                   ` (3 preceding siblings ...)
  2021-10-04 23:12 ` pinskia at gcc dot gnu.org
@ 2023-06-18 19:24 ` pinskia at gcc dot gnu.org
  2023-08-28 20:36 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-18 19:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
  _1 = x_4(D) >= 0;
  _2 = y_5(D) <= 0;
  _3 = _1 == _2;

Something like:
Prefer ^ over ==
```
(for cmp
(for cmpN
(for neeq
 (simplify
  (neeq:c (cmp @0 @1) @3
  (if (cmpN == inverseof(cmp, TREE_TYPE (type))
   (bit_xor (cmpN @0 @1) @3)
  )
 )
)))
```

This is what clang seems to do rather than any magic around == really.

I do wonder if we should try to expand bool == bool as bool^bool^1 .

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

* [Bug tree-optimization/95185] Failure to optimize specific kind of sign comparison check
  2020-05-18 12:05 [Bug tree-optimization/95185] New: Failure to optimize specific kind of sign comparison check gabravier at gmail dot com
                   ` (4 preceding siblings ...)
  2023-06-18 19:24 ` pinskia at gcc dot gnu.org
@ 2023-08-28 20:36 ` pinskia at gcc dot gnu.org
  2023-08-28 21:08 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-28 20:36 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 107881 has been marked as a duplicate of this bug. ***

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

* [Bug tree-optimization/95185] Failure to optimize specific kind of sign comparison check
  2020-05-18 12:05 [Bug tree-optimization/95185] New: Failure to optimize specific kind of sign comparison check gabravier at gmail dot com
                   ` (5 preceding siblings ...)
  2023-08-28 20:36 ` pinskia at gcc dot gnu.org
@ 2023-08-28 21:08 ` pinskia at gcc dot gnu.org
  2023-08-29  4:04 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-28 21:08 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #5)
> 
> Something like:
> Prefer ^ over ==
> ```
> (for cmp
> (for cmpN
> (for neeq
>  (simplify
>   (neeq:c (cmp @0 @1) @3
>   (if (cmpN == inverseof(cmp, TREE_TYPE (type))
>    (bit_xor (cmpN @0 @1) @3)
>   )
>  )
> )))
> ```

Actually we can just do:
```
/* For CMP == b, prefer CMP` ^ b. */
(for neeq (ne eq)
 (for cmp (tcc_comparison)
  (simplify
   (neeq:c (cmp@0 @1 @2) @3)
   (bit_xor (bit_not! @0) @3)
  )
 )
)
```
Since we already have folding of (bit_not cmp) in another place.

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

* [Bug tree-optimization/95185] Failure to optimize specific kind of sign comparison check
  2020-05-18 12:05 [Bug tree-optimization/95185] New: Failure to optimize specific kind of sign comparison check gabravier at gmail dot com
                   ` (6 preceding siblings ...)
  2023-08-28 21:08 ` pinskia at gcc dot gnu.org
@ 2023-08-29  4:04 ` pinskia at gcc dot gnu.org
  2023-09-11 22:14 ` [Bug tree-optimization/95185] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
  2024-03-22 14:09 ` law at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-29  4:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I have a patch which converts this into:
  _1 = x_4(D) < 0;
  _2 = y_5(D) <= 0;
  _3 = _1 ^ _2;

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

* [Bug tree-optimization/95185] [11/12/13/14 Regression] Failure to optimize specific kind of sign comparison check
  2020-05-18 12:05 [Bug tree-optimization/95185] New: Failure to optimize specific kind of sign comparison check gabravier at gmail dot com
                   ` (7 preceding siblings ...)
  2023-08-29  4:04 ` pinskia at gcc dot gnu.org
@ 2023-09-11 22:14 ` pinskia at gcc dot gnu.org
  2024-03-22 14:09 ` law at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-11 22:14 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW
           Assignee|pinskia at gcc dot gnu.org         |unassigned at gcc dot gnu.org
           Keywords|                            |needs-bisection
            Summary|Failure to optimize         |[11/12/13/14 Regression]
                   |specific kind of sign       |Failure to optimize
                   |comparison check            |specific kind of sign
                   |                            |comparison check
      Known to work|                            |8.5.0
   Target Milestone|---                         |11.5
      Known to fail|                            |9.1.0

--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The original testcase is actually a regression.

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

* [Bug tree-optimization/95185] [11/12/13/14 Regression] Failure to optimize specific kind of sign comparison check
  2020-05-18 12:05 [Bug tree-optimization/95185] New: Failure to optimize specific kind of sign comparison check gabravier at gmail dot com
                   ` (8 preceding siblings ...)
  2023-09-11 22:14 ` [Bug tree-optimization/95185] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2024-03-22 14:09 ` law at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-22 14:09 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
                 CC|                            |law at gcc dot gnu.org

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

end of thread, other threads:[~2024-03-22 14:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-18 12:05 [Bug tree-optimization/95185] New: Failure to optimize specific kind of sign comparison check gabravier at gmail dot com
2020-05-18 13:15 ` [Bug tree-optimization/95185] " rguenth at gcc dot gnu.org
2020-05-18 13:16 ` rguenth at gcc dot gnu.org
2021-10-04 23:02 ` arjun.is at lostca dot se
2021-10-04 23:12 ` pinskia at gcc dot gnu.org
2023-06-18 19:24 ` pinskia at gcc dot gnu.org
2023-08-28 20:36 ` pinskia at gcc dot gnu.org
2023-08-28 21:08 ` pinskia at gcc dot gnu.org
2023-08-29  4:04 ` pinskia at gcc dot gnu.org
2023-09-11 22:14 ` [Bug tree-optimization/95185] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-03-22 14:09 ` law 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).