public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/58662] New: wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode)
@ 2013-10-08 5:27 su at cs dot ucdavis.edu
2013-10-08 7:32 ` [Bug tree-optimization/58662] " mpolacek at gcc dot gnu.org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: su at cs dot ucdavis.edu @ 2013-10-08 5:27 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58662
Bug ID: 58662
Summary: wrong code at -O2 and -O3 on x86_64-linux-gnu (in
64-bit mode)
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: su at cs dot ucdavis.edu
The current gcc trunk miscompiles the attached testcase on x86_64-linux-gnu at
-O2 and -O3 in 64-bit mode.
It is a regression from 4.8.x.
$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure
--enable-languages=c,c++,objc,obj-c++,fortran,lto --disable-werror
--enable-checking=release --with-gmp=/usr/local/gcc-trunk
--with-mpfr=/usr/local/gcc-trunk --with-mpc=/usr/local/gcc-trunk
--with-cloog=/usr/local/gcc-trunk --prefix=/usr/local/gcc-trunk
Thread model: posix
gcc version 4.9.0 20131007 (experimental) [trunk revision 203235] (GCC)
$
$ gcc-trunk -Os small.c; a.out
0
$ gcc-trunk -O2 small.c; a.out
-1008071096
$ gcc-trunk -O3 small.c; a.out
86090104
$
$ gcc-4.8 -O2 small.c; a.out
0
$ gcc-4.8 -O3 small.c; a.out
0
$
-------------------------------------
int printf (const char *, ...);
int a, b, c, d;
int
foo (int p1, short p2)
{
return p1 / p2;
}
int
main ()
{
char e;
d = foo (a == 0, (0, 35536));
e = d % 14;
b = e && c;
printf ("%d\n", b);
return 0;
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/58662] wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode)
2013-10-08 5:27 [Bug tree-optimization/58662] New: wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode) su at cs dot ucdavis.edu
@ 2013-10-08 7:32 ` mpolacek at gcc dot gnu.org
2013-10-08 8:31 ` mpolacek at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2013-10-08 7:32 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58662
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-10-08
CC| |mpolacek at gcc dot gnu.org
Target Milestone|--- |4.9.0
Ever confirmed|0 |1
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed. It seems to be the VRP; adding -fno-tree-vrp makes trunk behave as
4.8.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/58662] wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode)
2013-10-08 5:27 [Bug tree-optimization/58662] New: wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode) su at cs dot ucdavis.edu
2013-10-08 7:32 ` [Bug tree-optimization/58662] " mpolacek at gcc dot gnu.org
@ 2013-10-08 8:31 ` mpolacek at gcc dot gnu.org
2013-10-08 11:24 ` mpolacek at gcc dot gnu.org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2013-10-08 8:31 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58662
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu.org
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with r202944.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/58662] wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode)
2013-10-08 5:27 [Bug tree-optimization/58662] New: wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode) su at cs dot ucdavis.edu
2013-10-08 7:32 ` [Bug tree-optimization/58662] " mpolacek at gcc dot gnu.org
2013-10-08 8:31 ` mpolacek at gcc dot gnu.org
@ 2013-10-08 11:24 ` mpolacek at gcc dot gnu.org
2013-10-10 12:03 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2013-10-08 11:24 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58662
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Actually, I think it's the uncprop:
--- Q.c.139t.crited2 2013-10-08 13:03:04.169955615 +0200
+++ Q.c.141t.uncprop1 2013-10-08 13:03:04.169955615 +0200
@@ -51,7 +51,7 @@
_13 = (int) _8;
<bb 4>:
- # iftmp.3_1 = PHI <0(5), _13(3)>
+ # iftmp.3_1 = PHI <_7(5), _13(3)>
b = iftmp.3_1;
printf ("%d\n", iftmp.3_1);
return 0;
so -fno-tree-dominator-opts makes the bug go away.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/58662] wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode)
2013-10-08 5:27 [Bug tree-optimization/58662] New: wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode) su at cs dot ucdavis.edu
` (2 preceding siblings ...)
2013-10-08 11:24 ` mpolacek at gcc dot gnu.org
@ 2013-10-10 12:03 ` rguenth at gcc dot gnu.org
2013-10-10 13:30 ` rguenth at gcc dot gnu.org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-10-10 12:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58662
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
I will have a looksee.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/58662] wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode)
2013-10-08 5:27 [Bug tree-optimization/58662] New: wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode) su at cs dot ucdavis.edu
` (3 preceding siblings ...)
2013-10-10 12:03 ` rguenth at gcc dot gnu.org
@ 2013-10-10 13:30 ` rguenth at gcc dot gnu.org
2013-10-10 13:48 ` [Bug rtl-optimization/58662] [4.9 Regression] " rguenth at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-10-10 13:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58662
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
It looks like changing the testcase line
d = foo (a == 0, (0, 35536));
to
d = foo (a == 0, -30000);
fixes it. _No_ IL difference in 065t.mergephi2, but then 066t.vrp1 has
main ()
{
char e;
@@ -39,6 +35,7 @@
_Bool _4;
int _5;
int _7;
+ int c.4_9;
int b.5_11;
int _12;
@@ -46,22 +43,37 @@
a.0_3 = a;
_4 = a.0_3 == 0;
_5 = (int) _4;
- _12 = 0;
- d = 0;
- _7 = 0;
- e_8 = 0;
- iftmp.3_1 = 0;
- b ={v} 0;
- b.5_11 ={v} b;
- if (b.5_11 != 0)
+ _12 = _5 / -30000;
+ d = _12;
+ _7 = _12 % 14;
+ e_8 = (char) _7;
+ if (_7 != 0)
goto <bb 3>;
else
goto <bb 4>;
<bb 3>:
- abort ();
+ c.4_9 = c;
+ if (c.4_9 != 0)
+ goto <bb 5>;
+ else
+ goto <bb 4>;
<bb 4>:
+
+ <bb 5>:
+ # iftmp.3_1 = PHI <1(3), 0(4)>
+ b ={v} iftmp.3_1;
+ b.5_11 ={v} b;
+ if (b.5_11 != 0)
+ goto <bb 6>;
+ else
+ goto <bb 7>;
+
+ <bb 6>:
+ abort ();
+
+ <bb 7>:
return 0;
}
what?!
Reduced testcase:
extern void abort (void);
int a, c, d;
volatile int b;
static int
foo (int p1, short p2)
{
return p1 / p2;
}
int
main ()
{
char e;
d = foo (a == 0, (0, 35536));
e = d % 14;
b = e && c;
if (b != 0)
abort ();
return 0;
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug rtl-optimization/58662] [4.9 Regression] wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode)
2013-10-08 5:27 [Bug tree-optimization/58662] New: wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode) su at cs dot ucdavis.edu
` (4 preceding siblings ...)
2013-10-10 13:30 ` rguenth at gcc dot gnu.org
@ 2013-10-10 13:48 ` rguenth at gcc dot gnu.org
2013-10-10 14:00 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-10-10 13:48 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58662
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEW
Component|tree-optimization |rtl-optimization
Assignee|rguenth at gcc dot gnu.org |unassigned at gcc dot gnu.org
Summary|wrong code at -O2 and -O3 |[4.9 Regression] wrong code
|on x86_64-linux-gnu (in |at -O2 and -O3 on
|64-bit mode) |x86_64-linux-gnu (in 64-bit
| |mode)
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Doesn't fail with -O2 -fno-tree-vrp.
The uncprop transform is correct.
_7 = _12 % 14;
if (_7 != 0)
goto <bb 3>;
else
goto <bb 7>;
<bb 7>:
goto <bb 4>;
<bb 3>:
c.4_9 = c;
_8 = c.4_9 != 0;
_13 = (int) _8;
<bb 4>:
iftmp.3_1 = PHI <_7(7), _13(3)>
we know that _7 is zero on the edge from BB 7.
What we now do is coalesce iftmp.3_1 with both _7 and _13 with also seems
correct. The initial RTL generated looks ok as well:
(insn 25 24 26 2 (parallel [
(set (reg:SI 83 [ D.1762 ])
(minus:SI (reg:SI 90 [ D.1762 ])
(reg:SI 106)))
(clobber (reg:CC 17 flags))
]) t.c:17 296 {*subsi_1}
(nil))
(insn 26 25 27 2 (set (reg:CCZ 17 flags)
(compare:CCZ (reg:SI 83 [ D.1762 ])
(const_int 0 [0]))) t.c:18 3 {*cmpsi_ccno_1}
(nil))
(jump_insn 27 26 28 2 (set (pc)
(if_then_else (eq (reg:CCZ 17 flags)
(const_int 0 [0]))
(label_ref 33)
(pc))) t.c:18 616 {*jcc_1}
(int_list:REG_BR_PROB 5000 (nil))
-> 33)
;; succ: 4 [50.0%] (FALLTHRU)
;; 5 [50.0%]
;; basic block 4, loop depth 0, count 0, freq 5000
;; prev block 2, next block 5, flags: (NEW, REACHABLE, RTL)
;; pred: 2 [50.0%] (FALLTHRU)
...
(insn 32 31 33 4 (set (reg:SI 83 [ D.1762 ])
(reg:SI 107 [ D.1763 ])) t.c:18 86 {*movsi_internal}
(nil))
;; succ: 5 [100.0%] (FALLTHRU)
;; basic block 5, loop depth 0, count 0, freq 10000, maybe hot
;; prev block 4, next block 6, flags: (NEW, REACHABLE, RTL)
;; pred: 2 [50.0%]
;; 4 [100.0%] (FALLTHRU)
(code_label 33 32 34 5 2 "" [1 uses])
(note 34 33 35 5 [bb 5] NOTE_INSN_BASIC_BLOCK)
(insn 35 34 36 5 (set (mem/v/c:SI (symbol_ref:DI ("b") <var_decl
0x7fc8088581c8 b>) [2 b+0 S4 A32])
(reg:SI 83 [ D.1762 ])) t.c:18 86 {*movsi_internal}
(nil))
it is combine where mysteriously all defining instructions for reg:SI 83
vanish. Not mine.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug rtl-optimization/58662] [4.9 Regression] wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode)
2013-10-08 5:27 [Bug tree-optimization/58662] New: wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode) su at cs dot ucdavis.edu
` (5 preceding siblings ...)
2013-10-10 13:48 ` [Bug rtl-optimization/58662] [4.9 Regression] " rguenth at gcc dot gnu.org
@ 2013-10-10 14:00 ` rguenth at gcc dot gnu.org
2013-10-11 7:07 ` ebotcazou at gcc dot gnu.org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-10-10 14:00 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58662
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #5)
> It looks like changing the testcase line
>
> d = foo (a == 0, (0, 35536));
>
> to
>
> d = foo (a == 0, -30000);
>
> fixes it. _No_ IL difference in 065t.mergephi2, but then 066t.vrp1 has
>
> main ()
> {
> char e;
> @@ -39,6 +35,7 @@
> _Bool _4;
> int _5;
> int _7;
> + int c.4_9;
> int b.5_11;
> int _12;
>
> @@ -46,22 +43,37 @@
> a.0_3 = a;
> _4 = a.0_3 == 0;
> _5 = (int) _4;
> - _12 = 0;
> - d = 0;
> - _7 = 0;
> - e_8 = 0;
> - iftmp.3_1 = 0;
> - b ={v} 0;
> - b.5_11 ={v} b;
> - if (b.5_11 != 0)
> + _12 = _5 / -30000;
> + d = _12;
> + _7 = _12 % 14;
> + e_8 = (char) _7;
> + if (_7 != 0)
> goto <bb 3>;
> else
> goto <bb 4>;
>
> <bb 3>:
> - abort ();
> + c.4_9 = c;
> + if (c.4_9 != 0)
> + goto <bb 5>;
> + else
> + goto <bb 4>;
>
> <bb 4>:
> +
> + <bb 5>:
> + # iftmp.3_1 = PHI <1(3), 0(4)>
> + b ={v} iftmp.3_1;
> + b.5_11 ={v} b;
> + if (b.5_11 != 0)
> + goto <bb 6>;
> + else
> + goto <bb 7>;
> +
> + <bb 6>:
> + abort ();
> +
> + <bb 7>:
> return 0;
>
> }
>
> what?!
That's because there _is_ a IL difference. With (0, 35536) the
-30000 tree constant has TREE_OVERFLOW set while with literal
-30000 in the source it does not.
Due to VRP relying on some fold-const.c overflow detection with
TREE_OVERFLOW this effect is to be expected.
[but in reality GIMPLE should not have any TREE_OVERFLOW constants
in the IL, though that's hard to avoid]
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug rtl-optimization/58662] [4.9 Regression] wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode)
2013-10-08 5:27 [Bug tree-optimization/58662] New: wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode) su at cs dot ucdavis.edu
` (6 preceding siblings ...)
2013-10-10 14:00 ` rguenth at gcc dot gnu.org
@ 2013-10-11 7:07 ` ebotcazou at gcc dot gnu.org
2013-10-13 13:29 ` [Bug rtl-optimization/58662] [4.9 Regression] wrong code at -O2 for dumb condition ebotcazou at gcc dot gnu.org
2013-10-13 13:30 ` ebotcazou at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-10-11 7:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58662
Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC|ebotcazou at gcc dot gnu.org |
Assignee|unassigned at gcc dot gnu.org |ebotcazou at gcc dot gnu.org
--- Comment #9 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Investigating.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug rtl-optimization/58662] [4.9 Regression] wrong code at -O2 for dumb condition
2013-10-08 5:27 [Bug tree-optimization/58662] New: wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode) su at cs dot ucdavis.edu
` (7 preceding siblings ...)
2013-10-11 7:07 ` ebotcazou at gcc dot gnu.org
@ 2013-10-13 13:29 ` ebotcazou at gcc dot gnu.org
2013-10-13 13:30 ` ebotcazou at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-10-13 13:29 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58662
--- Comment #10 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Author: ebotcazou
Date: Sun Oct 13 13:29:28 2013
New Revision: 203498
URL: http://gcc.gnu.org/viewcvs?rev=203498&root=gcc&view=rev
Log:
PR rtl-optimization/58662
* combine.c (try_combine): Take into account death nodes on I2 when
splitting a PARALLEL of two independent SETs. Fix dump message.
Added:
trunk/gcc/testsuite/gcc.c-torture/execute/pr58662.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/combine.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug rtl-optimization/58662] [4.9 Regression] wrong code at -O2 for dumb condition
2013-10-08 5:27 [Bug tree-optimization/58662] New: wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode) su at cs dot ucdavis.edu
` (8 preceding siblings ...)
2013-10-13 13:29 ` [Bug rtl-optimization/58662] [4.9 Regression] wrong code at -O2 for dumb condition ebotcazou at gcc dot gnu.org
@ 2013-10-13 13:30 ` ebotcazou at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-10-13 13:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58662
Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #11 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Thanks for reporting the problem.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2013-10-13 13:30 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-08 5:27 [Bug tree-optimization/58662] New: wrong code at -O2 and -O3 on x86_64-linux-gnu (in 64-bit mode) su at cs dot ucdavis.edu
2013-10-08 7:32 ` [Bug tree-optimization/58662] " mpolacek at gcc dot gnu.org
2013-10-08 8:31 ` mpolacek at gcc dot gnu.org
2013-10-08 11:24 ` mpolacek at gcc dot gnu.org
2013-10-10 12:03 ` rguenth at gcc dot gnu.org
2013-10-10 13:30 ` rguenth at gcc dot gnu.org
2013-10-10 13:48 ` [Bug rtl-optimization/58662] [4.9 Regression] " rguenth at gcc dot gnu.org
2013-10-10 14:00 ` rguenth at gcc dot gnu.org
2013-10-11 7:07 ` ebotcazou at gcc dot gnu.org
2013-10-13 13:29 ` [Bug rtl-optimization/58662] [4.9 Regression] wrong code at -O2 for dumb condition ebotcazou at gcc dot gnu.org
2013-10-13 13:30 ` ebotcazou 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).