public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/108017] New: ptr+v >= ptr + d should converted into (long)v >= CST(/sizeof(*ptr))
@ 2022-12-08  3:52 pinskia at gcc dot gnu.org
  2022-12-08  7:07 ` [Bug tree-optimization/108017] " rguenth at gcc dot gnu.org
  2022-12-12 20:09 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-08  3:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108017
           Summary: ptr+v >= ptr + d should converted into (long)v >=
                    CST(/sizeof(*ptr))
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
_Bool f(int *a, __SIZE_TYPE__ t, __SIZE_TYPE__ t1)
{
    int *b = a + t;
    int *c = a + t1;
    return c >= b;
}

_Bool f1(int *a, __SIZE_TYPE__ t, __SIZE_TYPE__ t1)
{
    long tt = t;
    long tt1 = t1;
    return tt1 >= tt;
}
```
These two should give the same code.

LLVM does this optimization.

I noticed this while looking into the code from the blog at
https://lemire.me/blog/2022/12/06/optimizing-compilers-reload-vector-constants-needlessly/
(but not vector constant issue though).

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

* [Bug tree-optimization/108017] ptr+v >= ptr + d should converted into (long)v >= CST(/sizeof(*ptr))
  2022-12-08  3:52 [Bug tree-optimization/108017] New: ptr+v >= ptr + d should converted into (long)v >= CST(/sizeof(*ptr)) pinskia at gcc dot gnu.org
@ 2022-12-08  7:07 ` rguenth at gcc dot gnu.org
  2022-12-12 20:09 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-08  7:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
We do this for &x + C {!=,==} &x' + C' - I think we're afraid of relational
compares here though, even with TYPE_OVERFLOW_UNDEFINED.

/* (&a+b) !=/== (&a[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, &diff))
     (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.

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

* [Bug tree-optimization/108017] ptr+v >= ptr + d should converted into (long)v >= CST(/sizeof(*ptr))
  2022-12-08  3:52 [Bug tree-optimization/108017] New: ptr+v >= ptr + d should converted into (long)v >= CST(/sizeof(*ptr)) pinskia at gcc dot gnu.org
  2022-12-08  7:07 ` [Bug tree-optimization/108017] " rguenth at gcc dot gnu.org
@ 2022-12-12 20:09 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-12 20:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this is the more generialized form of bug 94356.

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

end of thread, other threads:[~2022-12-12 20:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-08  3:52 [Bug tree-optimization/108017] New: ptr+v >= ptr + d should converted into (long)v >= CST(/sizeof(*ptr)) pinskia at gcc dot gnu.org
2022-12-08  7:07 ` [Bug tree-optimization/108017] " rguenth at gcc dot gnu.org
2022-12-12 20:09 ` 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).