[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #23 from Jakub Jelinek --- Author: jakub Date: Wed Aug 6 08:50:12 2014 New Revision: 213654 URL: https://gcc.gnu.org/viewcvs?rev=213654&root=gcc&view=rev Log: PR rtl-optimization/61801 * gcc.target/i386/pr61801.c: Rewritten. Modified: branches/gcc-4_8-branch/gcc/testsuite/ChangeLog branches/gcc-4_8-branch/gcc/testsuite/gcc.target/i386/pr61801.c
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #22 from Jakub Jelinek --- Author: jakub Date: Wed Aug 6 08:44:05 2014 New Revision: 213653 URL: https://gcc.gnu.org/viewcvs?rev=213653&root=gcc&view=rev Log: PR rtl-optimization/61801 * gcc.target/i386/pr61801.c: Rewritten. Modified: branches/gcc-4_9-branch/gcc/testsuite/ChangeLog branches/gcc-4_9-branch/gcc/testsuite/gcc.target/i386/pr61801.c
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #21 from Jakub Jelinek --- Author: jakub Date: Wed Aug 6 08:40:19 2014 New Revision: 213652 URL: https://gcc.gnu.org/viewcvs?rev=213652&root=gcc&view=rev Log: PR rtl-optimization/61801 * gcc.target/i386/pr61801.c: Rewritten. Modified: trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.target/i386/pr61801.c
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #20 from Richard Biener --- Author: rguenth Date: Mon Jul 28 09:02:39 2014 New Revision: 213121 URL: https://gcc.gnu.org/viewcvs?rev=213121&root=gcc&view=rev Log: 2014-07-28 Richard Biener PR rtl-optimization/61801 * gcc.target/i386/pr61801.c: Fix testcase. Modified: trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.target/i386/pr61801.c
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #19 from Richard Biener --- Author: rguenth Date: Mon Jul 28 09:02:23 2014 New Revision: 213120 URL: https://gcc.gnu.org/viewcvs?rev=213120&root=gcc&view=rev Log: 2014-07-28 Richard Biener PR rtl-optimization/61801 * gcc.target/i386/pr61801.c: Fix testcase. Modified: branches/gcc-4_8-branch/gcc/testsuite/ChangeLog branches/gcc-4_8-branch/gcc/testsuite/gcc.target/i386/pr61801.c
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #18 from Richard Biener --- Author: rguenth Date: Mon Jul 28 09:01:54 2014 New Revision: 213119 URL: https://gcc.gnu.org/viewcvs?rev=213119&root=gcc&view=rev Log: 2014-07-28 Richard Biener PR rtl-optimization/61801 * gcc.target/i386/pr61801.c: Fix testcase. Modified: branches/gcc-4_9-branch/gcc/testsuite/ChangeLog branches/gcc-4_9-branch/gcc/testsuite/gcc.target/i386/pr61801.c
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #17 from Richard Biener --- Author: rguenth Date: Mon Jul 28 07:59:22 2014 New Revision: 213113 URL: https://gcc.gnu.org/viewcvs?rev=213113&root=gcc&view=rev Log: 2014-07-28 Richard Biener PR rtl-optimization/61801 * gcc.target/i386/pr61801.c: New testcase. Added: branches/gcc-4_8-branch/gcc/testsuite/gcc.target/i386/pr61801.c Modified: branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #16 from Richard Biener --- Author: rguenth Date: Mon Jul 28 07:54:57 2014 New Revision: 213112 URL: https://gcc.gnu.org/viewcvs?rev=213112&root=gcc&view=rev Log: 2014-07-28 Richard Biener PR rtl-optimization/61801 * gcc.target/i386/pr61801.c: New testcase. Added: branches/gcc-4_9-branch/gcc/testsuite/gcc.target/i386/pr61801.c Modified: branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #15 from Richard Biener --- Author: rguenth Date: Mon Jul 28 07:54:08 2014 New Revision: 213111 URL: https://gcc.gnu.org/viewcvs?rev=213111&root=gcc&view=rev Log: 2014-07-28 Richard Biener PR rtl-optimization/61801 * gcc.target/i386/pr61801.c: New testcase. Added: trunk/gcc/testsuite/gcc.target/i386/pr61801.c Modified: trunk/gcc/testsuite/ChangeLog
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 Markus Trippelsdorf changed: What|Removed |Added CC||trippels at gcc dot gnu.org --- Comment #14 from Markus Trippelsdorf --- Here's a simple testcase for this issue (triggers for 4.8.3 and 4.9.1): markus@x4 linux % cat exit.i int a, b, c; void fn1 () { int d; if (fn2 () && !0) { b = ( { int e; fn3 (); switch (0) default: asm volatile("" : "=a"(e) : "0"(a), ""(0)); e; }); d = b; } c = d; } markus@x4 linux % gcc -fcompare-debug -O2 -c exit.i gcc: error: exit.i: -fcompare-debug failure (length) markus@x4 linux % gcc -fcompare-debug -Os -c exit.i gcc: error: exit.i: -fcompare-debug failure (length) markus@x4 linux %
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 Richard Biener changed: What|Removed |Added CC||torvalds@linux-foundation.o ||rg --- Comment #13 from Richard Biener --- *** Bug 61904 has been marked as a duplicate of this bug. ***
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #11 from Richard Biener --- Author: rguenth Date: Thu Jul 17 07:49:44 2014 New Revision: 212740 URL: https://gcc.gnu.org/viewcvs?rev=212740&root=gcc&view=rev Log: 2014-07-17 Richard Biener PR rtl-optimization/61801 * sched-deps.c (sched_analyze_2): For ASM_OPERANDS and ASM_INPUT don't set reg_pending_barrier if it appears in a debug-insn. Modified: branches/gcc-4_8-branch/gcc/ChangeLog branches/gcc-4_8-branch/gcc/sched-deps.c
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 Richard Biener changed: What|Removed |Added Status|ASSIGNED|RESOLVED Known to work||4.10.0, 4.8.4, 4.9.2 Resolution|--- |FIXED Target Milestone|--- |4.8.4 Known to fail|4.10.0 | --- Comment #12 from Richard Biener --- Fixed.
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #10 from Richard Biener --- Author: rguenth Date: Thu Jul 17 07:48:49 2014 New Revision: 212739 URL: https://gcc.gnu.org/viewcvs?rev=212739&root=gcc&view=rev Log: 2014-07-17 Richard Biener PR rtl-optimization/61801 * sched-deps.c (sched_analyze_2): For ASM_OPERANDS and ASM_INPUT don't set reg_pending_barrier if it appears in a debug-insn. Modified: branches/gcc-4_9-branch/gcc/ChangeLog branches/gcc-4_9-branch/gcc/sched-deps.c
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #9 from Richard Biener --- Author: rguenth Date: Thu Jul 17 07:47:19 2014 New Revision: 212738 URL: https://gcc.gnu.org/viewcvs?rev=212738&root=gcc&view=rev Log: 2014-07-17 Richard Biener PR rtl-optimization/61801 * sched-deps.c (sched_analyze_2): For ASM_OPERANDS and ASM_INPUT don't set reg_pending_barrier if it appears in a debug-insn. Modified: trunk/gcc/ChangeLog trunk/gcc/sched-deps.c
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 Richard Biener changed: What|Removed |Added Status|UNCONFIRMED |ASSIGNED Last reconfirmed||2014-07-16 Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #8 from Richard Biener --- The following fixes it as well, in the scheduler. Index: gcc/sched-deps.c === --- gcc/sched-deps.c(revision 212580) +++ gcc/sched-deps.c(working copy) @@ -2713,7 +2713,8 @@ sched_analyze_2 (struct deps_desc *deps, break; case PREFETCH: - if (PREFETCH_SCHEDULE_BARRIER_P (x)) + if (PREFETCH_SCHEDULE_BARRIER_P (x) + && !DEBUG_INSN_P (insn)) reg_pending_barrier = TRUE_BARRIER; /* Prefetch insn contains addresses only. So if the prefetch address has no registers, there will be no dependencies on @@ -2750,7 +2751,8 @@ sched_analyze_2 (struct deps_desc *deps, Consider for instance a volatile asm that changes the fpu rounding mode. An insn should not be moved across this even if it only uses pseudo-regs because it might give an incorrectly rounded result. */ - if (code != ASM_OPERANDS || MEM_VOLATILE_P (x)) + if ((code != ASM_OPERANDS || MEM_VOLATILE_P (x)) + && !DEBUG_INSN_P (insn)) reg_pending_barrier = TRUE_BARRIER; /* For all ASM_OPERANDS, we must traverse the vector of input operands. we then have ;; --- Region Dependences --- b 12 bb 0 ;; insn codebb dep prio cost reservation ;; -- --- --- ;; 2399012 1 5 1 athlon-direct,athlon-agu,athlon-store : 127 123nm 216n 240 ... ;; 122-112 3 0 0 nothing : 124 123nm ;; 2169012 1 5 3 athlon-direct,athlon-load : 127 123nm 243 so the false forward dependence of the store to the debug-insn is gone and instead a proper dependence on the load is there. Testing the fix.
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #7 from Richard Biener --- It's combine combining 120 into 123 and on the way via propagate_for_debug replacing reg:SI 126 with the asm in the debug_insn. (insn 120 119 122 15 (parallel [ (set (reg:SI 126 [ resultvar ]) (asm_operands/v:SI ("xchgl %%ebx, %%edi int $0x80 xchgl %%edi, %%ebx ... (debug_insn 122 120 123 15 (var_location:SI resultvar (reg:SI 126 [ resultvar ])) bug-887141_pthread_create.1.min.i:77 -1 (nil)) (insn 123 122 124 15 (set (reg/v:SI 84 [ result ]) (reg:SI 126 [ resultvar ])) bug-887141_pthread_create.1.min.i:77 90 {*movsi_internal} (expr_list:REG_DEAD (reg:SI 126 [ resultvar ]) (nil))) So to avoid generating debug-insns with asm_operands loc maybe do Index: valtrack.c === --- valtrack.c (revision 212580) +++ valtrack.c (working copy) @@ -197,6 +197,12 @@ propagate_for_debug (rtx insn, rtx last, next = NEXT_INSN (insn); if (DEBUG_INSN_P (insn)) { + if (GET_CODE (src) == ASM_OPERANDS) + { + INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC (); + df_insn_rescan (insn); + continue; + } loc = simplify_replace_fn_rtx (INSN_VAR_LOCATION_LOC (insn), dest, propagate_for_debug_subst, &p); if (loc == INSN_VAR_LOCATION_LOC (insn)) which "fixes" the bug.
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #6 from Jakub Jelinek --- It wouldn't be that much of a band-aid, as we can't do anything reasonable with asm in debug_insn anyway, there is no way to emit it into DWARF4 nor upcoming DWARF version.
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #5 from Richard Biener --- ;; --- Region Dependences --- b 12 bb 0 ;; insn codebb dep prio cost reservation ;; -- --- --- ... ;; 2399012 1 5 1 athlon-direct,athlon-agu,athlon-store : 127 123n 122nm 240 ... ;; 122-112 7 0 0 nothing : 124 123nm 243 216m ;; 2169012 0 5 3 athlon-direct,athlon-load : 127 123nm 243 ... which maps to: (insn 239 116 240 12 (set (mem/c:SI (reg/f:SI 7 sp) [11 %sfp+-16 S4 A32]) (reg:SI 0 ax [orig:127 cmdp_14(D)->syscall_no ] [127])) bug-887141_pthread_create.1.min.i:77 90 {*movsi_internal} (expr_list:REG_DEAD (reg:SI 0 ax [orig:127 cmdp_14(D)->syscall_no ] [127]) (nil))) ... (debug_insn 122 120 216 12 (var_location:SI resultvar (asm_operands/v:SI ("xchgl %%ebx, %%edi int $0x80 xchgl %%edi, %%ebx ") ("=a") 0 [ (mem/c:SI (reg/f:SI 7 sp) [11 %sfp+-16 S4 A32]) (reg:SI 5 di [orig:128 cmdp_14(D)->id ] [128]) (reg:SI 2 cx [orig:129 cmdp_14(D)->id+4 ] [129]) (reg:SI 1 dx [orig:130 cmdp_14(D)->id+8 ] [130]) ] [ (asm_input:SI ("0") bug-887141_pthread_create.1.min.i:77) (asm_input:SI ("D") bug-887141_pthread_create.1.min.i:77) (asm_input:SI ("c") bug-887141_pthread_create.1.min.i:77) (asm_input:SI ("d") bug-887141_pthread_create.1.min.i:77) ] [] bug-887141_pthread_create.1.min.i:77)) bug-887141_pthread_create.1.min.i:77 -1 (nil)) (insn 216 122 243 12 (set (reg/v:SI 4 si [orig:84 result ] [84]) (mem/c:SI (reg/f:SI 7 sp) [11 %sfp+-16 S4 A32])) bug-887141_pthread_create.1.min.i:77 90 {*movsi_internal} (nil)) insn 123 is the real asm. Not sure if the dependence of 239 via 122 to 216 is supposed to prevent scheduling 216 before 239. If so, then dependence information is correct. The only forward dependence to 216 is really from the debug insn. But then: ;; dependencies resolved: insn 238 ;; tick updated: insn 238 into ready ;; dependencies resolved: insn 216 ;; tick updated: insn 216 into ready ;; Advanced a state. ;; Ready list after queue_to_ready: 216:67:prio=5 238:59:prio=11 what? 216 is already ready? ;; Ready list (t = 0):216:67:prio=5 238:59:prio=11 ;;0--> b 0: i 238 ax=[sp+0x30] :athlon-direct,athlon-load ;; dependencies resolved: insn 116 ;; Ready-->Q: insn 116: queued for 3 cycles (change queue index). ;; tick updated: insn 116 into queue with cost=3 ;; Ready list after ready_sort: 216:67:prio=5 ;; Ready list (t = 0):216:67:prio=5 ;;0--> b 0: i 216 si=[sp] :athlon-direct,athlon-load ;; resetting: debug insn 122 yeah, so we reset the debug insn. But ignored the indirect dependence from 239. Now, of course I'm lost in the scheduler code, not knowing how it is intended to work with debug-insns. As a band-aid fix I'd simply never generate debug_insns with asms ...
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #4 from Richard Biener --- Created attachment 33123 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33123&action=edit more reduced On trunk reproduces with the following slightly more manual reduced testcase and -O2 -m32 -g (so even without -fPIC).
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 Richard Biener changed: What|Removed |Added Keywords||missed-optimization, ra CC||aoliva at gcc dot gnu.org, ||vmakarov at gcc dot gnu.org Known to fail||4.10.0, 4.8.3, 4.9.1 --- Comment #3 from Richard Biener --- Reduced testcase also reproduces the bug with 4.9 and trunk (but not 4.7): movl64(%esp), %eax # cmdp, tmp206 movl4(%esp), %esi # %sfp, result .LVL36: movl(%eax), %eax# cmdp_30(D)->syscall_no, cmdp_30(D)->syscall_no movl%eax, 4(%esp) # cmdp_30(D)->syscall_no, %sfp .LVL37: movl64(%esp), %eax # cmdp, tmp208 movl4(%eax), %edi # cmdp_30(D)->id, cmdp_30(D)->id movl8(%eax), %ecx # cmdp_30(D)->id, cmdp_30(D)->id movl12(%eax), %edx # cmdp_30(D)->id, cmdp_30(D)->id movl%esi, %eax # result, result #APP # 75 "bug-887141_pthread_create.1.min.i" 1 xchgl %ebx, %edi int $0x80 xchgl %edi, %ebx Note that 4.7 doesn't spill %eax but generates movl0(%ebp), %esi # cmdp_18(D)->syscall_no, result .LVL45: movl4(%ebp), %edi # cmdp_18(D)->id, cmdp_18(D)->id movl8(%ebp), %ecx # cmdp_18(D)->id, cmdp_18(D)->id movl12(%ebp), %edx # cmdp_18(D)->id, cmdp_18(D)->id movl%esi, %eax # result, #APP # 75 "bug-887141_pthread_create.1.min.i" 1 xchgl %ebx, %edi int $0x80 xchgl %edi, %ebx which would be an IRA issue?
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #2 from Richard Biener --- Created attachment 33122 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33122&action=edit autoreduced testcase Autoreduced testcase.
[Bug rtl-optimization/61801] sched2 miscompiles syscall sequence with -g
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801 --- Comment #1 from Richard Biener --- Auto-reduring (matching the bogus assembler pattern).