public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/25985] New: with optimization integer math fails
@ 2006-01-26 23:13 jurka at ejurka dot com
2006-01-26 23:28 ` [Bug middle-end/25985] [4.2 Regression] " pinskia at gcc dot gnu dot org
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: jurka at ejurka dot com @ 2006-01-26 23:13 UTC (permalink / raw)
To: gcc-bugs
gcc version 4.2.0 20060121
With optimzation the following code skips the last loop iteration:
#include <stdio.h>
int main(void)
{
int bits = 25;
while (bits) {
printf("bits=%d\n",bits);
if (bits >= 8) {
bits -= 8;
} else {
bits = 0;
}
}
return 0;
}
jurka@fred:~/pg/test$ ~/gcc/42/bin/gcc ip2.c
jurka@fred:~/pg/test$ ./a.out
bits=25
bits=17
bits=9
bits=1
jurka@fred:~/pg/test$ ~/gcc/42/bin/gcc -O ip2.c
jurka@fred:~/pg/test$ ./a.out
bits=25
bits=17
bits=9
jurka@fred:~/pg/test$
--
Summary: with optimization integer math fails
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jurka at ejurka dot com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug middle-end/25985] [4.2 Regression] with optimization integer math fails
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
@ 2006-01-26 23:28 ` pinskia at gcc dot gnu dot org
2006-02-20 17:50 ` [Bug tree-optimization/25985] " pinskia at gcc dot gnu dot org
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-26 23:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2006-01-26 23:28 -------
Confirmed, quickly looking at this DOM gets it wrong.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu dot
| |org
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |wrong-code
Last reconfirmed|0000-00-00 00:00:00 |2006-01-26 23:28:04
date| |
Summary|with optimization integer |[4.2 Regression] with
|math fails |optimization integer math
| |fails
Target Milestone|--- |4.2.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/25985] [4.2 Regression] with optimization integer math fails
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
2006-01-26 23:28 ` [Bug middle-end/25985] [4.2 Regression] " pinskia at gcc dot gnu dot org
@ 2006-02-20 17:50 ` pinskia at gcc dot gnu dot org
2006-03-15 18:27 ` pinskia at gcc dot gnu dot org
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-20 17:50 UTC (permalink / raw)
To: gcc-bugs
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|critical |blocker
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/25985] [4.2 Regression] with optimization integer math fails
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
2006-01-26 23:28 ` [Bug middle-end/25985] [4.2 Regression] " pinskia at gcc dot gnu dot org
2006-02-20 17:50 ` [Bug tree-optimization/25985] " pinskia at gcc dot gnu dot org
@ 2006-03-15 18:27 ` pinskia at gcc dot gnu dot org
2006-03-15 18:40 ` pinskia at gcc dot gnu dot org
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-15 18:27 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2006-03-15 18:27 -------
Loop 1 iterates 2 times.
Added canonical iv to loop 1, 2 iterations.
That is wrong, it iterates 3 times at this point (an interation has already
been peeled before the loop).
This is from .ivcanon.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/25985] [4.2 Regression] with optimization integer math fails
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
` (2 preceding siblings ...)
2006-03-15 18:27 ` pinskia at gcc dot gnu dot org
@ 2006-03-15 18:40 ` pinskia at gcc dot gnu dot org
2006-03-15 20:15 ` rguenth at gcc dot gnu dot org
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-15 18:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2006-03-15 18:40 -------
Hmm, if I change the function to be:
#include <stdio.h>
int main(void)
{
int bits = 25;
while (bits) {
printf("bits=%d\n",bits);
if (bits >= 8) {
bits -= 8;
} else {
break;
}
}
return 0;
}
And then compare 4.1 vs 4.2, I get the following observation:
in 4.1, it changed bits > 7 to use the iv, while in 4.2, it changed the bits !=
0 to use the iv
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/25985] [4.2 Regression] with optimization integer math fails
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
` (3 preceding siblings ...)
2006-03-15 18:40 ` pinskia at gcc dot gnu dot org
@ 2006-03-15 20:15 ` rguenth at gcc dot gnu dot org
2006-03-15 20:22 ` rakdver at gcc dot gnu dot org
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-03-15 20:15 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from rguenth at gcc dot gnu dot org 2006-03-15 20:15 -------
I'm sure Zdenek has an idea...
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rakdver at gcc dot gnu dot
| |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/25985] [4.2 Regression] with optimization integer math fails
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
` (4 preceding siblings ...)
2006-03-15 20:15 ` rguenth at gcc dot gnu dot org
@ 2006-03-15 20:22 ` rakdver at gcc dot gnu dot org
2006-03-16 2:49 ` rakdver at gcc dot gnu dot org
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rakdver at gcc dot gnu dot org @ 2006-03-15 20:22 UTC (permalink / raw)
To: gcc-bugs
--
rakdver at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |rakdver at gcc dot gnu dot
|dot org |org
Status|NEW |ASSIGNED
Last reconfirmed|2006-01-26 23:28:04 |2006-03-15 20:22:08
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/25985] [4.2 Regression] with optimization integer math fails
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
` (5 preceding siblings ...)
2006-03-15 20:22 ` rakdver at gcc dot gnu dot org
@ 2006-03-16 2:49 ` rakdver at gcc dot gnu dot org
2006-03-16 3:15 ` rakdver at gcc dot gnu dot org
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rakdver at gcc dot gnu dot org @ 2006-03-16 2:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from rakdver at gcc dot gnu dot org 2006-03-16 02:49 -------
"Added canonical iv..." seems correct to me (at least, -fno-tree-loop-ivcanon
does not fix the problem). However, -fno-tree-loop-ivcanon -fno-ivopts fixes
it, so it is mine anyway.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/25985] [4.2 Regression] with optimization integer math fails
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
` (6 preceding siblings ...)
2006-03-16 2:49 ` rakdver at gcc dot gnu dot org
@ 2006-03-16 3:15 ` rakdver at gcc dot gnu dot org
2006-03-16 14:29 ` rakdver at gcc dot gnu dot org
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rakdver at gcc dot gnu dot org @ 2006-03-16 3:15 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from rakdver at gcc dot gnu dot org 2006-03-16 03:15 -------
Actually, my previous comment is wrong, it is ivcanon (more precisely, # of
iterations analysis). Consider this testcase:
#include <stdio.h>
void bla(int x)
{
if (x < -100)
exit (0);
}
int main(void)
{
int bits = 25;
while (bits) {
printf ("%d\n", bits);
bla(bits);
bits -= 8;
}
return 0;
}
We note that bits is signed, therefore it cannot overflow, and conclude the
loop must be finite. Using this assumption, we conclude it iterates two times.
However, this would only be correct if the loop were exited through this
particular exit, as these examples demonstrate.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/25985] [4.2 Regression] with optimization integer math fails
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
` (7 preceding siblings ...)
2006-03-16 3:15 ` rakdver at gcc dot gnu dot org
@ 2006-03-16 14:29 ` rakdver at gcc dot gnu dot org
2006-03-29 1:41 ` rakdver at gcc dot gnu dot org
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rakdver at gcc dot gnu dot org @ 2006-03-16 14:29 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from rakdver at gcc dot gnu dot org 2006-03-16 14:29 -------
Patch:
http://gcc.gnu.org/ml/gcc-patches/2006-03/msg01019.html
--
rakdver at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |http://gcc.gnu.org/ml/gcc-
| |patches/2006-
| |03/msg01019.html
Keywords| |patch
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/25985] [4.2 Regression] with optimization integer math fails
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
` (8 preceding siblings ...)
2006-03-16 14:29 ` rakdver at gcc dot gnu dot org
@ 2006-03-29 1:41 ` rakdver at gcc dot gnu dot org
2006-04-11 23:13 ` pinskia at gcc dot gnu dot org
2006-05-04 6:40 ` jakub at gcc dot gnu dot org
11 siblings, 0 replies; 13+ messages in thread
From: rakdver at gcc dot gnu dot org @ 2006-03-29 1:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from rakdver at gcc dot gnu dot org 2006-03-29 01:41 -------
Subject: Bug 25985
Author: rakdver
Date: Wed Mar 29 01:41:27 2006
New Revision: 112484
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=112484
Log:
PR tree-optimization/25985
* tree-ssa-loop-niter.c (number_of_iterations_le,
number_of_iterations_ne): Make comments more precise.
(number_of_iterations_cond): Add only_exit argument. Use the
fact that signed variables do not overflow only when only_exit
is true.
(loop_only_exit_p): New.
(number_of_iterations_exit): Pass result of loop_only_exit_p to
number_of_iterations_cond.
Modified:
trunk/gcc/ChangeLog
trunk/gcc/tree-ssa-loop-niter.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/25985] [4.2 Regression] with optimization integer math fails
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
` (9 preceding siblings ...)
2006-03-29 1:41 ` rakdver at gcc dot gnu dot org
@ 2006-04-11 23:13 ` pinskia at gcc dot gnu dot org
2006-05-04 6:40 ` jakub at gcc dot gnu dot org
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-11 23:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from pinskia at gcc dot gnu dot org 2006-04-11 23:13 -------
Fixed.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/25985] [4.2 Regression] with optimization integer math fails
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
` (10 preceding siblings ...)
2006-04-11 23:13 ` pinskia at gcc dot gnu dot org
@ 2006-05-04 6:40 ` jakub at gcc dot gnu dot org
11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu dot org @ 2006-05-04 6:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from jakub at gcc dot gnu dot org 2006-05-04 06:40 -------
Subject: Bug 25985
Author: jakub
Date: Thu May 4 06:40:15 2006
New Revision: 113515
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113515
Log:
PR tree-optimization/27285
Backport from mainline:
2006-03-28 Zdenek Dvorak <dvorakz@suse.cz>
PR tree-optimization/25985
* tree-ssa-loop-niter.c (number_of_iterations_le,
number_of_iterations_ne): Make comments more precise.
(number_of_iterations_cond): Add only_exit argument. Use the
fact that signed variables do not overflow only when only_exit
is true.
(loop_only_exit_p): New.
(number_of_iterations_exit): Pass result of loop_only_exit_p to
number_of_iterations_cond.
* gcc.c-torture/execute/pr27285.c: New test.
Added:
branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/execute/pr27285.c
Modified:
branches/gcc-4_1-branch/gcc/ChangeLog
branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
branches/gcc-4_1-branch/gcc/tree-ssa-loop-niter.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25985
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2006-05-04 6:40 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-26 23:13 [Bug c/25985] New: with optimization integer math fails jurka at ejurka dot com
2006-01-26 23:28 ` [Bug middle-end/25985] [4.2 Regression] " pinskia at gcc dot gnu dot org
2006-02-20 17:50 ` [Bug tree-optimization/25985] " pinskia at gcc dot gnu dot org
2006-03-15 18:27 ` pinskia at gcc dot gnu dot org
2006-03-15 18:40 ` pinskia at gcc dot gnu dot org
2006-03-15 20:15 ` rguenth at gcc dot gnu dot org
2006-03-15 20:22 ` rakdver at gcc dot gnu dot org
2006-03-16 2:49 ` rakdver at gcc dot gnu dot org
2006-03-16 3:15 ` rakdver at gcc dot gnu dot org
2006-03-16 14:29 ` rakdver at gcc dot gnu dot org
2006-03-29 1:41 ` rakdver at gcc dot gnu dot org
2006-04-11 23:13 ` pinskia at gcc dot gnu dot org
2006-05-04 6:40 ` jakub 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).