public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/107591] New: range-op{,-float}.cc for x * x
@ 2022-11-09 15:37 jakub at gcc dot gnu.org
  2022-11-09 15:49 ` [Bug tree-optimization/107591] " aldyh at gcc dot gnu.org
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-11-09 15:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107591
           Summary: range-op{,-float}.cc for x * x
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

int
foo (int x)
{
  if (x < -13 || x > 26)
    return -1;
  return x * x;
}

results in
x_4(D) :      [irange] int [-13, 26]
_5  : [irange] int [-338, 676]
That is unnecessarily pessimized, because it only computes [-13, 26] * [-13,
26]
range without taking into account that both operands are the same.
For the powi (x, 2) case the range is actually [0, 26 * 26], i.e. we shouldn't
do a cross product for it, just compute the -13 * -13, 0 * 0 (if 0 is in the
range) and 26 * 26 products and form from that the range (I admit I haven't
thought about unsigned or wrapping stuff).

On the PR107569 testcase it is on frange:
  _3 = u_2(D)->x;
  _6 = _3 * _3;
  _7 = u_2(D)->y;
  _8 = _7 * _7;
  _9 = _6 + _8;
  if (_9 u>= 0.0)
If we don't know anything further about u_2(D)->x and u_2(D)->y, VARYING *
VARYING is [0, +Inf] +-NAN, added twice is the same (note, unless
-fno-signed-zeros, it should be really [+0, +Inf] +-NAN, not [-0, +Inf] +-NAN,
but it doesn't matter for the u>= 0.0 comparison).
And then we can fold u>= 0.0 to true.

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

end of thread, other threads:[~2023-04-05  7:14 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09 15:37 [Bug tree-optimization/107591] New: range-op{,-float}.cc for x * x jakub at gcc dot gnu.org
2022-11-09 15:49 ` [Bug tree-optimization/107591] " aldyh at gcc dot gnu.org
2022-11-09 15:55 ` aldyh at gcc dot gnu.org
2022-11-09 15:57 ` jakub at gcc dot gnu.org
2022-11-09 15:59 ` pinskia at gcc dot gnu.org
2022-11-09 16:01 ` pinskia at gcc dot gnu.org
2022-11-09 16:02 ` aldyh at gcc dot gnu.org
2022-11-09 16:04 ` aldyh at gcc dot gnu.org
2022-11-09 16:31 ` jakub at gcc dot gnu.org
2022-11-09 16:40 ` jakub at gcc dot gnu.org
2022-11-09 17:45 ` amacleod at redhat dot com
2022-11-09 17:49 ` jakub at gcc dot gnu.org
2022-11-09 18:22 ` amacleod at redhat dot com
2022-11-09 18:35 ` jakub at gcc dot gnu.org
2022-11-09 19:20 ` amacleod at redhat dot com
2022-11-09 20:24 ` jakub at gcc dot gnu.org
2022-11-09 20:45 ` jakub at gcc dot gnu.org
2022-11-09 22:25 ` amacleod at redhat dot com
2022-11-09 23:27 ` jakub at gcc dot gnu.org
2022-11-12  8:42 ` cvs-commit at gcc dot gnu.org
2023-04-05  7:14 ` pilarlatiesa at gmail 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).