public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/112324] New: phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max)
@ 2023-11-01  1:26 crazylht at gmail dot com
  2023-11-01  1:32 ` [Bug tree-optimization/112324] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: crazylht at gmail dot com @ 2023-11-01  1:26 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112324
           Summary: phiopt fail to recog if (b < 0) max = MAX(-b, max);
                    else max = MAX (b, max) into max = MAX (ABS(b), max)
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: crazylht at gmail dot com
  Target Milestone: ---

#define MAX(a, b) ((a) > (b) ? (a) : (b)) 
int
foo (int n, int* a)
{
    int max = 0;
    for (int i = 0; i != n; i++)
    {
        int tmp = a[i];
        if (tmp < 0)
          max = MAX (-tmp, max);
        else
          max = MAX (tmp, max);
    }
    return max;
}

int
foo1 (int n, int* a)
{
    int max = 0;
    for (int i = 0; i != n; i++)
    {
        int tmp = a[i];
        max = MAX ((tmp < 0 ? -tmp : tmp), max);
    }
    return max;
}

foo should be same as foo1, but gcc failed to recognize ABS_EXPR in foo.
It's from pr110015(originally from source code in openjpeg).

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

* [Bug tree-optimization/112324] phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max)
  2023-11-01  1:26 [Bug middle-end/112324] New: phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max) crazylht at gmail dot com
@ 2023-11-01  1:32 ` pinskia at gcc dot gnu.org
  2023-11-01  1:33 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-01  1:32 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org
     Ever confirmed|0                           |1
          Component|middle-end                  |tree-optimization
             Status|UNCONFIRMED                 |ASSIGNED
           Severity|normal                      |enhancement
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
   Last reconfirmed|                            |2023-11-01

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

There is another bug which is very much similar to this but:
  max_19 = MAX_EXPR <_4, max_6>;
  goto <bb 6>; [INV]

  <bb 5> :
  _8 = MAX_EXPR <max_6, tmp_15>;

  <bb 6> :
  # max_5 = PHI <max_19(4), _8(5)>

Basically we need to pull MAX_EXPR out of the if and then the ABS will be
recognized and all.

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

* [Bug tree-optimization/112324] phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max)
  2023-11-01  1:26 [Bug middle-end/112324] New: phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max) crazylht at gmail dot com
  2023-11-01  1:32 ` [Bug tree-optimization/112324] " pinskia at gcc dot gnu.org
@ 2023-11-01  1:33 ` pinskia at gcc dot gnu.org
  2023-11-06 17:27 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-01  1:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |64700

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
PR 64700 (and others).


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64700
[Bug 64700] Sink common code through PHI

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

* [Bug tree-optimization/112324] phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max)
  2023-11-01  1:26 [Bug middle-end/112324] New: phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max) crazylht at gmail dot com
  2023-11-01  1:32 ` [Bug tree-optimization/112324] " pinskia at gcc dot gnu.org
  2023-11-01  1:33 ` pinskia at gcc dot gnu.org
@ 2023-11-06 17:27 ` pinskia at gcc dot gnu.org
  2023-11-06 17:56 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-06 17:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note a simple patch to improve phiopt here does not improve the original code
in openjpeg.

The reason why is due to the code in phiopt here is only operates on the case
where the phi would be the only one. In that case we also have a vop phi which
changes which causes the code not to be done.

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

* [Bug tree-optimization/112324] phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max)
  2023-11-01  1:26 [Bug middle-end/112324] New: phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max) crazylht at gmail dot com
                   ` (2 preceding siblings ...)
  2023-11-06 17:27 ` pinskia at gcc dot gnu.org
@ 2023-11-06 17:56 ` pinskia at gcc dot gnu.org
  2023-11-06 20:23 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-06 17:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> Note a simple patch to improve phiopt here does not improve the original
> code in openjpeg.
> 
> The reason why is due to the code in phiopt here is only operates on the
> case where the phi would be the only one. In that case we also have a vop
> phi which changes which causes the code not to be done.

But maybe ifcvt could use the same function to do the transformation before it
does the conversion ...

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

* [Bug tree-optimization/112324] phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max)
  2023-11-01  1:26 [Bug middle-end/112324] New: phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max) crazylht at gmail dot com
                   ` (3 preceding siblings ...)
  2023-11-06 17:56 ` pinskia at gcc dot gnu.org
@ 2023-11-06 20:23 ` pinskia at gcc dot gnu.org
  2023-11-19 16:23 ` sjames at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-06 20:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #4)
> (In reply to Andrew Pinski from comment #3)
> > Note a simple patch to improve phiopt here does not improve the original
> > code in openjpeg.
> > 
> > The reason why is due to the code in phiopt here is only operates on the
> > case where the phi would be the only one. In that case we also have a vop
> > phi which changes which causes the code not to be done.
> 
> But maybe ifcvt could use the same function to do the transformation before
> it does the conversion ...

I will try to figure that out next but I want to get this patch though.

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

* [Bug tree-optimization/112324] phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max)
  2023-11-01  1:26 [Bug middle-end/112324] New: phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max) crazylht at gmail dot com
                   ` (4 preceding siblings ...)
  2023-11-06 20:23 ` pinskia at gcc dot gnu.org
@ 2023-11-19 16:23 ` sjames at gcc dot gnu.org
  2023-11-19 16:43 ` pinskia at gcc dot gnu.org
  2023-11-19 17:13 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-11-19 16:23 UTC (permalink / raw)
  To: gcc-bugs

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

Sam James <sjames at gcc dot gnu.org> changed:

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

--- Comment #6 from Sam James <sjames at gcc dot gnu.org> ---
Someone filed a bug for LLVM for x <= abs(x) being always true
(https://github.com/llvm/llvm-project/issues/72653) and it looks like we're
missing that too. Not sure if that's a dupe though.

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

* [Bug tree-optimization/112324] phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max)
  2023-11-01  1:26 [Bug middle-end/112324] New: phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max) crazylht at gmail dot com
                   ` (5 preceding siblings ...)
  2023-11-19 16:23 ` sjames at gcc dot gnu.org
@ 2023-11-19 16:43 ` pinskia at gcc dot gnu.org
  2023-11-19 17:13 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-19 16:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Sam James from comment #6)
> Someone filed a bug for LLVM for x <= abs(x) being always true
> (https://github.com/llvm/llvm-project/issues/72653) and it looks like we're
> missing that too. Not sure if that's a dupe though.

Yes and there is no dup filed so far. Let me file about them.

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

* [Bug tree-optimization/112324] phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max)
  2023-11-01  1:26 [Bug middle-end/112324] New: phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max) crazylht at gmail dot com
                   ` (6 preceding siblings ...)
  2023-11-19 16:43 ` pinskia at gcc dot gnu.org
@ 2023-11-19 17:13 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-19 17:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Sam James from comment #6)
> Someone filed a bug for LLVM for x <= abs(x) being always true
> (https://github.com/llvm/llvm-project/issues/72653) and it looks like we're
> missing that too. Not sure if that's a dupe though.

Filed as PR 112626.

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

end of thread, other threads:[~2023-11-19 17:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-01  1:26 [Bug middle-end/112324] New: phiopt fail to recog if (b < 0) max = MAX(-b, max); else max = MAX (b, max) into max = MAX (ABS(b), max) crazylht at gmail dot com
2023-11-01  1:32 ` [Bug tree-optimization/112324] " pinskia at gcc dot gnu.org
2023-11-01  1:33 ` pinskia at gcc dot gnu.org
2023-11-06 17:27 ` pinskia at gcc dot gnu.org
2023-11-06 17:56 ` pinskia at gcc dot gnu.org
2023-11-06 20:23 ` pinskia at gcc dot gnu.org
2023-11-19 16:23 ` sjames at gcc dot gnu.org
2023-11-19 16:43 ` pinskia at gcc dot gnu.org
2023-11-19 17:13 ` 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).