public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/101039] New: Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified
@ 2021-06-12 10:27 pinskia at gcc dot gnu.org
  2021-07-03  5:30 ` [Bug tree-optimization/101039] Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified if expanded pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-12 10:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101039
           Summary: Some simple fold_cond_expr_with_comparison with CMP 0
                    is not simplified
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take at -O2:
int f0(int A)
{
//     A == 0? A : -A    same as -A
  if (A == 0)  return A;
  return -A;
}

int f1(int A)
{
//     A != 0? A : -A    same as A
  if (A != 0)  return A;
  return -A;
}
int f2(int A)
{
//     A >= 0? A : -A    same as abs (A)
  if (A >= 0)  return A;
  return -A;
}
int f3(int A)
{
//     A > 0?  A : -A    same as abs (A)
  if (A > 0)  return A;
  return -A;
}
int f4(int A)
{
//     A <= 0? A : -A    same as -abs (A)
  if (A <= 0)  return A;
  return -A;
}
int f5(int A)
{
//     A < 0?  A : -A    same as -abs (A)
  if (A < 0)  return A;
  return -A;
}

------ CUT -------
Only f1-f3 are optimized at the gimple level.  f0, f4, f5 are not.
With -Dint=float -Ofast, only f0 is not optimized but note f1 takes until
*.phiopt3 be optimized; and unlike int, f4 and f5 are optimized in phiopt2.

Note phiopt1 is still confused by predictor but I think there might be another
bug for that.

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

* [Bug tree-optimization/101039] Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified if expanded
  2021-06-12 10:27 [Bug tree-optimization/101039] New: Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified pinskia at gcc dot gnu.org
@ 2021-07-03  5:30 ` pinskia at gcc dot gnu.org
  2021-07-04 18:47 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-03  5:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2021-07-03

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mine, I had forgot I filed this bug when I submitted the patches for this.
Patch submitted here:
https://gcc.gnu.org/pipermail/gcc-patches/2021-June/573785.html


I guess I should add a few testcases to the patch.

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

* [Bug tree-optimization/101039] Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified if expanded
  2021-06-12 10:27 [Bug tree-optimization/101039] New: Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified pinskia at gcc dot gnu.org
  2021-07-03  5:30 ` [Bug tree-optimization/101039] Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified if expanded pinskia at gcc dot gnu.org
@ 2021-07-04 18:47 ` pinskia at gcc dot gnu.org
  2021-07-05 20:42 ` cvs-commit at gcc dot gnu.org
  2021-07-05 20:43 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-04 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                URL|                            |https://gcc.gnu.org/piperma
                   |                            |il/gcc-patches/2021-July/57
                   |                            |4414.html

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Submitted latest patch, note it depends on previous ones though:
https://gcc.gnu.org/pipermail/gcc-patches/2021-July/574414.html

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

* [Bug tree-optimization/101039] Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified if expanded
  2021-06-12 10:27 [Bug tree-optimization/101039] New: Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified pinskia at gcc dot gnu.org
  2021-07-03  5:30 ` [Bug tree-optimization/101039] Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified if expanded pinskia at gcc dot gnu.org
  2021-07-04 18:47 ` pinskia at gcc dot gnu.org
@ 2021-07-05 20:42 ` cvs-commit at gcc dot gnu.org
  2021-07-05 20:43 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-05 20:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:7d6979197274a662da7bdc564314afe8415865c1

commit r12-2041-g7d6979197274a662da7bdc564314afe8415865c1
Author: Andrew Pinski <apinski@marvell.com>
Date:   Sat Jun 12 19:45:20 2021 -0700

    Port most of the A CMP 0 ? A : -A to match

    To improve phiopt and be able to remove abs_replacement, this ports
    most of "A CMP 0 ? A : -A" from fold_cond_expr_with_comparison to
    match.pd.  There is a few extra changes that are needed to remove
    the "A CMP 0 ? A : -A" part from fold_cond_expr_with_comparison:
       * Need to handle (A - B) case
       * Need to handle UN* comparisons.

    I will handle those in a different patch.

    Note phi-opt-15.c test needed to be updated as we get ABSU now
    instead of not getting ABS.  When ABSU was added phiopt was not
    updated even to use ABSU instead of not creating ABS.

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

    gcc/ChangeLog:

            PR tree-optimization/101039
            * match.pd (A CMP 0 ? A : -A): New patterns.
            * tree-ssa-phiopt.c (abs_replacement): Delete function.
            (tree_ssa_phiopt_worker): Don't call abs_replacement.
            Update comment about abs_replacement.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/101039
            * gcc.dg/tree-ssa/phi-opt-15.c: Update test to expect
            ABSU and still not expect ABS_EXPR.
            * gcc.dg/tree-ssa/phi-opt-23.c: New test.
            * gcc.dg/tree-ssa/phi-opt-24.c: New test.

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

* [Bug tree-optimization/101039] Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified if expanded
  2021-06-12 10:27 [Bug tree-optimization/101039] New: Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-07-05 20:42 ` cvs-commit at gcc dot gnu.org
@ 2021-07-05 20:43 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-05 20:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

end of thread, other threads:[~2021-07-05 20:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-12 10:27 [Bug tree-optimization/101039] New: Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified pinskia at gcc dot gnu.org
2021-07-03  5:30 ` [Bug tree-optimization/101039] Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified if expanded pinskia at gcc dot gnu.org
2021-07-04 18:47 ` pinskia at gcc dot gnu.org
2021-07-05 20:42 ` cvs-commit at gcc dot gnu.org
2021-07-05 20:43 ` 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).