[Bug tree-optimization/108017] ptr+v >= ptr + d should converted into (long)v >= CST(/sizeof(*ptr))

2022-12-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108017

Andrew Pinski  changed:

   What|Removed |Added

   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=94356

--- Comment #2 from Andrew Pinski  ---
I think this is the more generialized form of bug 94356.

[Bug tree-optimization/108017] ptr+v >= ptr + d should converted into (long)v >= CST(/sizeof(*ptr))

2022-12-07 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108017

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1
   Last reconfirmed||2022-12-08

--- Comment #1 from Richard Biener  ---
We do this for  + C {!=,==} ' + C' - I think we're afraid of relational
compares here though, even with TYPE_OVERFLOW_UNDEFINED.

/* (+b) !=/== ([1] + c) ->  sizeof(a[0]) + b !=/== c */
(for neeq (ne eq)
 (simplify 
  (neeq (pointer_plus ADDR_EXPR@0 @1) (pointer_plus ADDR_EXPR@2 @3))
   (with { poly_int64 diff; tree inner_type = TREE_TYPE (@1);}
(if (ptr_difference_const (@0, @2, ))
 (neeq (plus { build_int_cst_type (inner_type, diff); } @1) @3)

that could be relaxed to general @0/@2 (at some cost) and to
relational compares with TYPE_OVERFLOW_UNDEFINED.