public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/41244] "&data[i] - data" isn't converted to "i"
[not found] <bug-41244-4@http.gcc.gnu.org/bugzilla/>
@ 2021-09-14 22:03 ` pinskia at gcc dot gnu.org
2021-10-09 21:19 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-14 22:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41244
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here are some better testcases as the power of 2 case can be handled on the rtl
level as it is just a shift.
extern struct s{
int a, b, c, d, e, f, g, h;
} data[];
int find(int i, int j)
{
struct s *a = &data[i];
struct s *b = &data[j];
return a - b;
}
extern struct {
int a, b, c;
} data1[];
int find1(int i, int j)
{
return &data1[i] - data1;
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/41244] "&data[i] - data" isn't converted to "i"
[not found] <bug-41244-4@http.gcc.gnu.org/bugzilla/>
2021-09-14 22:03 ` [Bug tree-optimization/41244] "&data[i] - data" isn't converted to "i" pinskia at gcc dot gnu.org
@ 2021-10-09 21:19 ` pinskia at gcc dot gnu.org
2023-06-11 19:44 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-09 21:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41244
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> ---
Mine.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/41244] "&data[i] - data" isn't converted to "i"
[not found] <bug-41244-4@http.gcc.gnu.org/bugzilla/>
2021-09-14 22:03 ` [Bug tree-optimization/41244] "&data[i] - data" isn't converted to "i" pinskia at gcc dot gnu.org
2021-10-09 21:19 ` pinskia at gcc dot gnu.org
@ 2023-06-11 19:44 ` pinskia at gcc dot gnu.org
2023-06-11 23:54 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-11 19:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41244
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
_14 = _13 * 32;
_15 = (long int) _14;
_2 = _15 /[ex] 32;
I think this will work ....
(simplify
(exact_div (nop_convert (mult @0 INTEGER_CST@1)) INTEGER_CST@2)
(if (!TYPE_UNSIGNED (@0)
&& wi::to_wide (@1) == wi::to_wide (@2))
(convert @0)))
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/41244] "&data[i] - data" isn't converted to "i"
[not found] <bug-41244-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2023-06-11 19:44 ` pinskia at gcc dot gnu.org
@ 2023-06-11 23:54 ` pinskia at gcc dot gnu.org
2023-06-12 0:30 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-11 23:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41244
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55302
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55302&action=edit
Patch which I will be testing
This extends the pattern that already handles `(t * 2) / 2) -> t`.
The one thing which I need to double check and understand if :c can/should be
used here, or should use another with here.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/41244] "&data[i] - data" isn't converted to "i"
[not found] <bug-41244-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2023-06-11 23:54 ` pinskia at gcc dot gnu.org
@ 2023-06-12 0:30 ` pinskia at gcc dot gnu.org
2023-06-12 1:33 ` pinskia at gcc dot gnu.org
2023-06-12 2:12 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-12 0:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41244
--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55303
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55303&action=edit
Better patch
This is a better patch, operand_equal_p already does the integer cst check too.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/41244] "&data[i] - data" isn't converted to "i"
[not found] <bug-41244-4@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
2023-06-12 0:30 ` pinskia at gcc dot gnu.org
@ 2023-06-12 1:33 ` pinskia at gcc dot gnu.org
2023-06-12 2:12 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-12 1:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41244
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEW
--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
You know what, both patches are wrong with respect to the overflow check.
Anyways Someone else can fix this.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/41244] "&data[i] - data" isn't converted to "i"
[not found] <bug-41244-4@http.gcc.gnu.org/bugzilla/>
` (5 preceding siblings ...)
2023-06-12 1:33 ` pinskia at gcc dot gnu.org
@ 2023-06-12 2:12 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-12 2:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41244
--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So basically the biggest issue is we do the sign extend and then do the
multiply in an unsigned type; this causes all negative values causing a
wrapping which is not correct really but we don't know any better. I tried to
change pass_laddress::execute to do the multiply in a signed type but that
still is not able to optimize find in comment #6 to work and the IR is so much
more complex.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/41244] "&data[i] - data" isn't converted to "i"
2009-09-03 13:49 [Bug tree-optimization/41244] New: " zsojka at seznam dot cz
2009-09-03 13:51 ` [Bug tree-optimization/41244] " zsojka at seznam dot cz
@ 2009-09-03 14:12 ` rguenth at gcc dot gnu dot org
1 sibling, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-09-03 14:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2009-09-03 14:12 -------
Because the index arithmetic is done unsigned.
return (int) ((unsigned int) i * 212) /[ex] 212;
We lost the information that i * 212 cannot overflow.
Simpler testcase:
extern int data[];
int find(int i)
{
return &data[i] - data;
}
from which we enter c_fully_fold_internal with
((int) ((int *) &data + (unsigned int) ((unsigned int) i * 4)) - (int) &data)
/[ex] 4
addressed on the no-undefined-overflow branch.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |missed-optimization
Last reconfirmed|0000-00-00 00:00:00 |2009-09-03 14:12:37
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41244
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/41244] "&data[i] - data" isn't converted to "i"
2009-09-03 13:49 [Bug tree-optimization/41244] New: " zsojka at seznam dot cz
@ 2009-09-03 13:51 ` zsojka at seznam dot cz
2009-09-03 14:12 ` rguenth at gcc dot gnu dot org
1 sibling, 0 replies; 9+ messages in thread
From: zsojka at seznam dot cz @ 2009-09-03 13:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from zsojka at seznam dot cz 2009-09-03 13:50 -------
Created an attachment (id=18475)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18475&action=view)
preprocessed source
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41244
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-06-12 2:12 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-41244-4@http.gcc.gnu.org/bugzilla/>
2021-09-14 22:03 ` [Bug tree-optimization/41244] "&data[i] - data" isn't converted to "i" pinskia at gcc dot gnu.org
2021-10-09 21:19 ` pinskia at gcc dot gnu.org
2023-06-11 19:44 ` pinskia at gcc dot gnu.org
2023-06-11 23:54 ` pinskia at gcc dot gnu.org
2023-06-12 0:30 ` pinskia at gcc dot gnu.org
2023-06-12 1:33 ` pinskia at gcc dot gnu.org
2023-06-12 2:12 ` pinskia at gcc dot gnu.org
2009-09-03 13:49 [Bug tree-optimization/41244] New: " zsojka at seznam dot cz
2009-09-03 13:51 ` [Bug tree-optimization/41244] " zsojka at seznam dot cz
2009-09-03 14:12 ` 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).