public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/27109] Simplify "a - 10 > 150" into "a > 160" when range of a is known (in VRP or somewhere else)
       [not found] <bug-27109-4@http.gcc.gnu.org/bugzilla/>
@ 2012-12-04 18:48 ` glisse at gcc dot gnu.org
  2021-06-03  3:27 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: glisse at gcc dot gnu.org @ 2012-12-04 18:48 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27109

--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> 2012-12-04 18:48:27 UTC ---
This seems to be well handled in reassoc1 now:

Optimizing range tests a_2(D) -[0, 99] and +[0, 200] and -[10, 160]
 into a_2(D) + 4294967135 <= 39


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

* [Bug tree-optimization/27109] Simplify "a - 10 > 150" into "a > 160" when range of a is known (in VRP or somewhere else)
       [not found] <bug-27109-4@http.gcc.gnu.org/bugzilla/>
  2012-12-04 18:48 ` [Bug tree-optimization/27109] Simplify "a - 10 > 150" into "a > 160" when range of a is known (in VRP or somewhere else) glisse at gcc dot gnu.org
@ 2021-06-03  3:27 ` pinskia at gcc dot gnu.org
  2021-06-03 13:25 ` amacleod at redhat dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-03  3:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2007-07-01 00:53:44         |2021-6-2

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a better testcase:
void bar(void);
void goo(void);
void
foo (unsigned a)
{
  if (a < 100)
    return;
  goo();
  if (200 < a)
    return;

  if (a - 10 > 150)
    bar ();
}


Note the original testcase is optimized correctly in reassoc1 but that was not
the point of it.
Anyways we have:
  # RANGE [90, 190] NONZERO 255
  _1 = a_3(D) + 4294967286;
  if (_1 > 150)

4294967286 is -10

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

* [Bug tree-optimization/27109] Simplify "a - 10 > 150" into "a > 160" when range of a is known (in VRP or somewhere else)
       [not found] <bug-27109-4@http.gcc.gnu.org/bugzilla/>
  2012-12-04 18:48 ` [Bug tree-optimization/27109] Simplify "a - 10 > 150" into "a > 160" when range of a is known (in VRP or somewhere else) glisse at gcc dot gnu.org
  2021-06-03  3:27 ` pinskia at gcc dot gnu.org
@ 2021-06-03 13:25 ` amacleod at redhat dot com
  2021-08-07 22:38 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: amacleod at redhat dot com @ 2021-06-03 13:25 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Macleod <amacleod at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amacleod at redhat dot com

--- Comment #4 from Andrew Macleod <amacleod at redhat dot com> ---
well, in evrp we now produce:
=========== BB 6 ============
Imports: a_3(D)
Exports: _1  a_3(D)
         _1 : a_3(D)(I)
a_3(D)  unsigned int [100, 200]
    <bb 6> :
    _1 = a_3(D) + 4294967286;
    if (_1 > 150)
      goto <bb 7>; [INV]
    else
      goto <bb 8>; [INV]

_1 : unsigned int [90, 190]
6->7  (T) _1 :  unsigned int [151, 190]
6->7  (T) a_3(D) :      unsigned int [161, 200]
6->8  (F) _1 :  unsigned int [90, 150]
6->8  (F) a_3(D) :      unsigned int [100, 160]

we know its not going to overflow.  who or what should make the decision? looks
like some sort of simplification or peephole.  

Also note that you can now find this out from any pass with the range_query
infrastructure that Aldy added:

at the start of the pass call enable_ranger() for context sensitive info, and
then anywhere you can 

get_range_query()->range_of_expr (r, stmt, name)  will get a range.
so for the initial stmt
1 = a_3(D) + 4294967286;
asking for the range of a_3 on this stmt would give you [100,200] or asking for
the range of the stmt (or i_1 in the next statetment) will give you [90,190]

Aldy has also implemented an overflow checker for expressions.. not sure it
applies to stmts.. yet.  If any of this interests you, send him a note.
We're still working out user case functionality, so if there is anything else
we need to present this kind of info, let us know.

I think he's planning to write a guide for this next week.

Another option is to work it backwards. given the stmt:
  # RANGE [90, 190] NONZERO 255
  _1 = a_3(D) + 4294967286;
range-ops can tell you that if _1 is [90,190] then it can evaluate the
expression and solve that a_3 is [100,200]..   if that helps.  internally it
knows if there was a potential overflow, but that isnt exported in any useful
way way at the moment.

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

* [Bug tree-optimization/27109] Simplify "a - 10 > 150" into "a > 160" when range of a is known (in VRP or somewhere else)
       [not found] <bug-27109-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2021-06-03 13:25 ` amacleod at redhat dot com
@ 2021-08-07 22:38 ` pinskia at gcc dot gnu.org
  2021-08-07 22:39 ` pinskia at gcc dot gnu.org
  2023-08-09 21:51 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-07 22:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 101815 has been marked as a duplicate of this bug. ***

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

* [Bug tree-optimization/27109] Simplify "a - 10 > 150" into "a > 160" when range of a is known (in VRP or somewhere else)
       [not found] <bug-27109-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2021-08-07 22:38 ` pinskia at gcc dot gnu.org
@ 2021-08-07 22:39 ` pinskia at gcc dot gnu.org
  2023-08-09 21:51 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-07 22:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Another testcase which shows up via the autovectorizer aliasing checks

int g(unsigned int a)
{
  if (a == 0) __builtin_unreachable();
  unsigned int t = a;
  a += -1;
  return a > 3u;
}

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

* [Bug tree-optimization/27109] Simplify "a - 10 > 150" into "a > 160" when range of a is known (in VRP or somewhere else)
       [not found] <bug-27109-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2021-08-07 22:39 ` pinskia at gcc dot gnu.org
@ 2023-08-09 21:51 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-09 21:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I suspect we could add it to simplify_compare_using_ranges_1 very easy.
Let me look into that.

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

* [Bug tree-optimization/27109] Simplify "a - 10 > 150" into "a > 160" when range of a is known (in VRP or somewhere else)
  2006-04-11  2:04 [Bug tree-optimization/27109] New: " pinskia at gcc dot gnu dot org
  2006-04-11  2:04 ` [Bug tree-optimization/27109] " pinskia at gcc dot gnu dot org
@ 2006-12-28 12:03 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-12-28 12:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2006-12-28 12:03 -------
Confirmed.  compare_values needs to be teached to look at value ranges for
operands and decide on overflow there - but only for substitute and fold as
earlier we can have invalid intermediate value ranges.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-12-28 12:03:15
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27109


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

* [Bug tree-optimization/27109] Simplify "a - 10 > 150" into "a > 160" when range of a is known (in VRP or somewhere else)
  2006-04-11  2:04 [Bug tree-optimization/27109] New: " pinskia at gcc dot gnu dot org
@ 2006-04-11  2:04 ` pinskia at gcc dot gnu dot org
  2006-12-28 12:03 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-11  2:04 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27109


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

end of thread, other threads:[~2023-08-09 21:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-27109-4@http.gcc.gnu.org/bugzilla/>
2012-12-04 18:48 ` [Bug tree-optimization/27109] Simplify "a - 10 > 150" into "a > 160" when range of a is known (in VRP or somewhere else) glisse at gcc dot gnu.org
2021-06-03  3:27 ` pinskia at gcc dot gnu.org
2021-06-03 13:25 ` amacleod at redhat dot com
2021-08-07 22:38 ` pinskia at gcc dot gnu.org
2021-08-07 22:39 ` pinskia at gcc dot gnu.org
2023-08-09 21:51 ` pinskia at gcc dot gnu.org
2006-04-11  2:04 [Bug tree-optimization/27109] New: " pinskia at gcc dot gnu dot org
2006-04-11  2:04 ` [Bug tree-optimization/27109] " pinskia at gcc dot gnu dot org
2006-12-28 12:03 ` rguenth at gcc dot gnu dot 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).