public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/104420] New: [12 Regression] Inconsistent checks for X * 0.0 optimization
@ 2022-02-07 13:11 glisse at gcc dot gnu.org
  2022-02-08  8:58 ` [Bug tree-optimization/104420] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2022-02-07 13:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104420
           Summary: [12 Regression] Inconsistent checks for X * 0.0
                    optimization
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---

(from a comment in PR 104389)

/* Maybe fold x * 0 to 0.  The expressions aren't the same
   when x is NaN, since x * 0 is also NaN.  Nor are they the
   same in modes with signed zeros, since multiplying a
   negative value by 0 gives -0, not +0.  Nor when x is +-Inf,
   since x * 0 is NaN.  */
(simplify
 (mult @0 real_zerop@1)
 (if (!tree_expr_maybe_nan_p (@0)
      && (!HONOR_NANS (type) || !tree_expr_maybe_infinite_p (@0))
      && !tree_expr_maybe_real_minus_zero_p (@0)
      && !tree_expr_maybe_real_minus_zero_p (@1))
  @1))

Notice how the comment talks about @0 being a "negative value" while the code
says "!tree_expr_maybe_real_minus_zero_p (@0)", which is not at all the same
thing.

Because tree_expr_maybe_real_minus_zero_p is rather weak, it does not trigger
so often, but still:

double f(int a){
  return a*0.;
}

is optimized to "return 0.;" whereas f(-42) should return -0.

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

* [Bug tree-optimization/104420] [12 Regression] Inconsistent checks for X * 0.0 optimization
  2022-02-07 13:11 [Bug tree-optimization/104420] New: [12 Regression] Inconsistent checks for X * 0.0 optimization glisse at gcc dot gnu.org
@ 2022-02-08  8:58 ` rguenth at gcc dot gnu.org
  2022-02-08 23:23 ` roger at nextmovesoftware dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-02-08  8:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-02-08
           Priority|P3                          |P1
   Target Milestone|---                         |12.0
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

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

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

* [Bug tree-optimization/104420] [12 Regression] Inconsistent checks for X * 0.0 optimization
  2022-02-07 13:11 [Bug tree-optimization/104420] New: [12 Regression] Inconsistent checks for X * 0.0 optimization glisse at gcc dot gnu.org
  2022-02-08  8:58 ` [Bug tree-optimization/104420] " rguenth at gcc dot gnu.org
@ 2022-02-08 23:23 ` roger at nextmovesoftware dot com
  2022-02-09 14:24 ` cvs-commit at gcc dot gnu.org
  2022-02-10 22:18 ` roger at nextmovesoftware dot com
  3 siblings, 0 replies; 5+ messages in thread
From: roger at nextmovesoftware dot com @ 2022-02-08 23:23 UTC (permalink / raw)
  To: gcc-bugs

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

Roger Sayle <roger at nextmovesoftware dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |roger at nextmovesoftware dot com
                 CC|                            |roger at nextmovesoftware dot com

--- Comment #2 from Roger Sayle <roger at nextmovesoftware dot com> ---
Patch proposed
https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590049.html

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

* [Bug tree-optimization/104420] [12 Regression] Inconsistent checks for X * 0.0 optimization
  2022-02-07 13:11 [Bug tree-optimization/104420] New: [12 Regression] Inconsistent checks for X * 0.0 optimization glisse at gcc dot gnu.org
  2022-02-08  8:58 ` [Bug tree-optimization/104420] " rguenth at gcc dot gnu.org
  2022-02-08 23:23 ` roger at nextmovesoftware dot com
@ 2022-02-09 14:24 ` cvs-commit at gcc dot gnu.org
  2022-02-10 22:18 ` roger at nextmovesoftware dot com
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-09 14:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:2d3c477599b02b06e338acd5f5098ee7a3fe6176

commit r12-7130-g2d3c477599b02b06e338acd5f5098ee7a3fe6176
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Wed Feb 9 14:21:08 2022 +0000

    [PATCH] PR tree-optimization/104420: Fix checks for constant folding X*0.0

    This patch resolves PR tree-optimization/104420, which is a P1 regression
    where, as observed by Jakub Jelinek, the conditions for constant folding
    x*0.0 are incorrect (following my patch for PR tree-optimization/96392).
    The multiplication x*0.0 may yield a negative zero result, -0.0, if X is
    negative (not just if x may be negative zero).  Hence (without -ffast-math)
    (int)x*0.0 can't be optimized to 0.0, but (unsigned)x*0.0 can be constant
    folded.  This adds a bunch of test cases to confirm the desired behaviour,
    and removes an incorrect test from gcc.dg/pr96392.c which checked for the
    wrong behaviour.

    2022-02-09  Roger Sayle  <roger@nextmovesoftware.com>

    gcc/ChangeLog
            PR tree-optimization/104420
            * match.pd (mult @0 real_zerop): Tweak conditions for constant
            folding X*0.0 (or X*-0.0) to HONOR_SIGNED_ZEROS when appropriate.

    gcc/testsuite/ChangeLog
            PR tree-optimization/104420
            * gcc.dg/pr104420-1.c: New test case.
            * gcc.dg/pr104420-2.c: New test case.
            * gcc.dg/pr104420-3.c: New test case.
            * gcc.dg/pr104420-4.c: New test case.
            * gcc.dg/pr96392.c: Remove incorrect test.

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

* [Bug tree-optimization/104420] [12 Regression] Inconsistent checks for X * 0.0 optimization
  2022-02-07 13:11 [Bug tree-optimization/104420] New: [12 Regression] Inconsistent checks for X * 0.0 optimization glisse at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-02-09 14:24 ` cvs-commit at gcc dot gnu.org
@ 2022-02-10 22:18 ` roger at nextmovesoftware dot com
  3 siblings, 0 replies; 5+ messages in thread
From: roger at nextmovesoftware dot com @ 2022-02-10 22:18 UTC (permalink / raw)
  To: gcc-bugs

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

Roger Sayle <roger at nextmovesoftware dot com> changed:

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

--- Comment #4 from Roger Sayle <roger at nextmovesoftware dot com> ---
This should now be fixed on mainline.  Sorry again for the inconvenience.

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

end of thread, other threads:[~2022-02-10 22:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-07 13:11 [Bug tree-optimization/104420] New: [12 Regression] Inconsistent checks for X * 0.0 optimization glisse at gcc dot gnu.org
2022-02-08  8:58 ` [Bug tree-optimization/104420] " rguenth at gcc dot gnu.org
2022-02-08 23:23 ` roger at nextmovesoftware dot com
2022-02-09 14:24 ` cvs-commit at gcc dot gnu.org
2022-02-10 22:18 ` roger at nextmovesoftware dot com

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