public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/41244] New: "&data[i] - data" isn't converted to "i"
@ 2009-09-03 13:49 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
0 siblings, 2 replies; 10+ messages in thread
From: zsojka at seznam dot cz @ 2009-09-03 13:49 UTC (permalink / raw)
To: gcc-bugs
In attached code:
in find(), generated code computes offset using multiplication/division.
in set(), generated code computes &data[10] and compares &data[i] with that (to
verify find() fails to be optimised because of overflow rules)
tested gcc: 4.3.4, 4.4.1, 4.5.0-alpha20090827
command line:
gcc main.c -o main.o -c -O3
-f(no-)strict-overflow or -m32 doesn't have any effect on that behaviour
---------------------------------
static struct {
int a, b, c;
char pad[200]; /* padding so offset computation has to use expensive
div/mul */
} data[1000]; /* 1000 so loop isn't unrolled */
int find(int val)
{
int i;
for (i = 0; i < 1000; i++) {
if (data[i].a == val) return &data[i] - data; /* does *212,
/212 */
}
return -1;
}
void set(int val)
{
int i;
for (i = 0; i < 1000; i++) {
data[i].b = &data[i] - data < 10 || data[i].a == val; /*
compares with &data[10] */
}
}
---------------------------------
Relevant generated ASM:
(eax is "i", sar+imul is converted division by 212)
---------------------------------
cdqe
imul rax, rax, 212
sar rax, 2
imul eax, eax, -1944890851
ret
---------------------------------
--
Summary: "&data[i] - data" isn't converted to "i"
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: zsojka at seznam dot cz
GCC host triplet: x86_64-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41244
^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <bug-41244-4@http.gcc.gnu.org/bugzilla/>]
* [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; 10+ 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] 10+ 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 ` 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; 10+ 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] 10+ 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 ` 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ messages in thread
end of thread, other threads:[~2023-06-12 2:12 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-03 13:49 [Bug tree-optimization/41244] New: "&data[i] - data" isn't converted to "i" 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
[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
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
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).