public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110335] New: int converted to double should be considered non-nan and non-nan*non-nan is still non-nan
@ 2023-06-21  7:35 pinskia at gcc dot gnu.org
  2023-06-22  7:39 ` [Bug tree-optimization/110335] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-21  7:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110335
           Summary: int converted to double should be considered non-nan
                    and non-nan*non-nan is still non-nan
           Product: gcc
           Version: 14.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:
```
  void
  h (int n, int from, int to)
  {
    double dto = to;
    double damt = n * dto;
    if (damt != damt)
     __builtin_trap();
  }
  void
  h1 (double dto, double n)
  {
    if (dto != dto) __builtin_unreachable();
    if (n != n) __builtin_unreachable();
    double damt = n *  dto;
    if (damt != damt)
     __builtin_trap();
  }
```
I would assume this two functions be optimized to just `return;`

LLVM is able to optimize h but not h1.

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

* [Bug tree-optimization/110335] int converted to double should be considered non-nan and non-nan*non-nan is still non-nan
  2023-06-21  7:35 [Bug tree-optimization/110335] New: int converted to double should be considered non-nan and non-nan*non-nan is still non-nan pinskia at gcc dot gnu.org
@ 2023-06-22  7:39 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-22  7:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Another testcase:
```
  void
  h3(int to)
  {
    double dto = to;
    double damt = dto +2;
    if (damt != damt)
     __builtin_trap();
  }
```


Note we do optimize:
```
  void
  done(int to)
  {
    double dto = to;
    double damt = -dto;
    if (damt != damt)
     __builtin_trap();
  }
```
But via match and simplify.

Note there is tree_expr_maybe_nan_p and tree_expr_finite_p in fold-const.cc
Which can be used as a model for some frange related things too.

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

end of thread, other threads:[~2023-06-22  7:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-21  7:35 [Bug tree-optimization/110335] New: int converted to double should be considered non-nan and non-nan*non-nan is still non-nan pinskia at gcc dot gnu.org
2023-06-22  7:39 ` [Bug tree-optimization/110335] " 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).