public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111910] New: `a - b < 0` is not transformed into `a < b` for signed types
@ 2023-10-21 21:13 pinskia at gcc dot gnu.org
  2023-10-21 21:24 ` [Bug tree-optimization/111910] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-21 21:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111910
           Summary: `a - b < 0` is not transformed into `a < b` for signed
                    types
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: FIXME, missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

From match.pd:

/* Transform comparisons of the form X - Y CMP 0 to X CMP Y.
   ??? The transformation is valid for the other operators if overflow
   is undefined for the type, but performing it here badly interacts
   with the transformation in fold_cond_expr_with_comparison which
   attempts to synthetize ABS_EXPR.  */

I am looking into that fix that for either GCC 14 or 15.

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

* [Bug tree-optimization/111910] `a - b < 0` is not transformed into `a < b` for signed types
  2023-10-21 21:13 [Bug tree-optimization/111910] New: `a - b < 0` is not transformed into `a < b` for signed types pinskia at gcc dot gnu.org
@ 2023-10-21 21:24 ` pinskia at gcc dot gnu.org
  2023-10-21 21:34 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-21 21:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2023-10-21

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
.

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

* [Bug tree-optimization/111910] `a - b < 0` is not transformed into `a < b` for signed types
  2023-10-21 21:13 [Bug tree-optimization/111910] New: `a - b < 0` is not transformed into `a < b` for signed types pinskia at gcc dot gnu.org
  2023-10-21 21:24 ` [Bug tree-optimization/111910] " pinskia at gcc dot gnu.org
@ 2023-10-21 21:34 ` pinskia at gcc dot gnu.org
  2023-10-21 21:59 ` pinskia at gcc dot gnu.org
  2023-10-22  4:12 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-21 21:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
That is:
```
int f(int a, int b)
{
        if (a > b) return a - b; else return b - a;
}
int fa(int a, int b)
{
        return (a > b) ? (a - b) : (b - a);
}

int f1(int a, int b)
{
        int t = a - b;
        if (a > b) return t; else return -t;
}


int f2(int a, int b)
{
        int t = a - b;
        if (t > 0) return t; else return -t;
}

int f3a(int a, int b)
{
        return ((a - b) > 0) ? (a - b) : (b - a);
}

int f3(int a, int b)
{
        int t = a - b;
        return t > 0 ? t : -t;
}
```

All are detected as ABS<(a-b)> .

Right now only f3a and f3 are detected as such.

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

* [Bug tree-optimization/111910] `a - b < 0` is not transformed into `a < b` for signed types
  2023-10-21 21:13 [Bug tree-optimization/111910] New: `a - b < 0` is not transformed into `a < b` for signed types pinskia at gcc dot gnu.org
  2023-10-21 21:24 ` [Bug tree-optimization/111910] " pinskia at gcc dot gnu.org
  2023-10-21 21:34 ` pinskia at gcc dot gnu.org
@ 2023-10-21 21:59 ` pinskia at gcc dot gnu.org
  2023-10-22  4:12 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-21 21:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also this:
```
int f(int a, int b)
{
        if (a < b) return a - b; else return b - a;
}
int fa(int a, int b)
{
        return (a < b) ? (a - b) : (b - a);
}

int f1(int a, int b)
{
        int t = a - b;
        if (a < b) return t; else return -t;
}


int f2(int a, int b)
{
        int t = a - b;
        if (t < 0) return t; else return -t;
}

int f3a(int a, int b)
{
        return ((a - b) < 0) ? (a - b) : ( b - a);
}

int f3(int a, int b)
{
        int t = a - b;
        return t < 0 ? t : -t;
}
```

(note clang misses on the above for f and fa [f1 on x86_64]).

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

* [Bug tree-optimization/111910] `a - b < 0` is not transformed into `a < b` for signed types
  2023-10-21 21:13 [Bug tree-optimization/111910] New: `a - b < 0` is not transformed into `a < b` for signed types pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-10-21 21:59 ` pinskia at gcc dot gnu.org
@ 2023-10-22  4:12 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-22  4:12 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |50856

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually the `a < b ? (a - b) : (b - a)` is the first example in PR 50856.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50856
[Bug 50856] ARM: suboptimal code for absolute difference calculation

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

end of thread, other threads:[~2023-10-22  4:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-21 21:13 [Bug tree-optimization/111910] New: `a - b < 0` is not transformed into `a < b` for signed types pinskia at gcc dot gnu.org
2023-10-21 21:24 ` [Bug tree-optimization/111910] " pinskia at gcc dot gnu.org
2023-10-21 21:34 ` pinskia at gcc dot gnu.org
2023-10-21 21:59 ` pinskia at gcc dot gnu.org
2023-10-22  4:12 ` pinskia 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).