Created attachment 22691 [details] example case See the attached example case. Also reported here: https://bugs.launchpad.net/gcc-linaro/+bug/687406 When a piece of code containing a multiline macro construct with embedded asm code is first preprocessed then compiled into an object or asm file, the results are different than directly compiling them into an object file or asm code. The preprocessor step could take place when using -save-temps. It also happens when using ccache or distcc. Linux kernel arm parts have this kind of code at least in local_irq_restore() [include/linux/irqflags.h] -> raw_local_irq_restore() [arch/arm/include/asm/irqflags.h] ---- Result of example case without -save-temps: .file "test.c" .text .globl optimized .type optimized, @function optimized: .LFB0: .cfi_startproc #APP # 15 "/tmp/test.c" 1 nop # 0 "" 2 #NO_APP ret .cfi_endproc .LFE0: .size optimized, .-optimized .ident "GCC: (GNU) 4.5.1" .section .note.GNU-stack,"",@progbits ---- Result of example case with -save-temps: .file "test.c" .text .globl optimized .type optimized, @function optimized: .LFB0: .cfi_startproc testb $1, flags(%rip) je .L2 #APP # 15 "/tmp/test.c" 1 nop # 0 "" 2 #NO_APP ret .L2: #APP # 15 "/tmp/test.c" 1 nop # 0 "" 2 #NO_APP ret .cfi_endproc .LFE0: .size optimized, .-optimized .ident "GCC: (GNU) 4.5.1" .section .note.GNU-stack,"",@progbits
Cross jumping doesn't see instructions with different location as equivalent it seems. Comparing the 195r.csa dumps: --- test(3).c.195r.csa 2010-12-09 15:41:13.000000000 +0100 +++ tmp/test(3).c.195r.csa 2010-12-09 15:39:56.000000000 +0100 @@ -11,19 +11,50 @@ changing bb of uid 28 from 5 to 4 Merged 4 and 5 without moving. +Cross jumping from bb 3 to bb 4; 1 common insns +changing bb of uid 29 + unscanned insn +changing bb of uid 10 + from 3 to 6 +changing bb of uid 26 + from 3 to 6 +scanning new insn with uid = 30. +deleting insn with uid = 29. +deleting insn with uid = 10. +deleting insn with uid = 26. +deleting insn with uid = 22. +deleting block 6 Thus, confirmed.
Works ok with 4.1.
Created attachment 22698 [details] gcc46-pr46865.patch The problem is that we do not guarantee the rtl locators are unique, locator_eq needs to be called to check equality. Perhaps for 4.7 a better way would be to use a different fmt string letter for these locations and adjust all routines that look at rtl format strings.
Author: jakub Date: Fri Dec 10 12:43:45 2010 New Revision: 167686 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167686 Log: PR rtl-optimization/46865 * rtl.c (rtx_equal_p_cb, rtx_equal_p): For last operand of ASM_OPERANDS and ASM_INPUT if integers are different, call locator_eq. * jump.c (rtx_renumbered_equal_p): Likewise. * gcc.target/i386/pr46865-1.c: New test. * gcc.target/i386/pr46865-2.c: New test. Added: trunk/gcc/testsuite/gcc.target/i386/pr46865-1.c trunk/gcc/testsuite/gcc.target/i386/pr46865-2.c Modified: trunk/gcc/ChangeLog trunk/gcc/jump.c trunk/gcc/rtl.c trunk/gcc/testsuite/ChangeLog
Fixed on the trunk so far.
Thanks for the quick work! How does this get backported to 4.3 or 4.4 then? I can see the patch directly applies to 4.5.1, but not to 4.4.5 (rtl.c: rtx_equal_p is too different in it). If this backporting stuff is something I should just know then don't waste your time explaining it in lenght, I can dig around :)
Author: jakub Date: Sun Jan 16 20:14:37 2011 New Revision: 168862 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168862 Log: Backport from mainline 2010-12-10 Jakub Jelinek <jakub@redhat.com> PR rtl-optimization/46865 * rtl.c (rtx_equal_p_cb, rtx_equal_p): For last operand of ASM_OPERANDS and ASM_INPUT if integers are different, call locator_eq. * jump.c (rtx_renumbered_equal_p): Likewise. * gcc.target/i386/pr46865-1.c: New test. * gcc.target/i386/pr46865-2.c: New test. Added: branches/gcc-4_5-branch/gcc/testsuite/gcc.target/i386/pr46865-1.c branches/gcc-4_5-branch/gcc/testsuite/gcc.target/i386/pr46865-2.c Modified: branches/gcc-4_5-branch/gcc/ChangeLog branches/gcc-4_5-branch/gcc/jump.c branches/gcc-4_5-branch/gcc/rtl.c branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
Author: jakub Date: Sun Jan 16 22:53:09 2011 New Revision: 168877 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168877 Log: Backport from mainline 2010-12-10 Jakub Jelinek <jakub@redhat.com> PR rtl-optimization/46865 * rtl.c (rtx_equal_p_cb): For last operand of ASM_OPERANDS and ASM_INPUT if integers are different, call locator_eq. * jump.c (rtx_renumbered_equal_p): Likewise. * gcc.target/i386/pr46865-1.c: New test. * gcc.target/i386/pr46865-2.c: New test. Added: branches/gcc-4_4-branch/gcc/testsuite/gcc.target/i386/pr46865-1.c branches/gcc-4_4-branch/gcc/testsuite/gcc.target/i386/pr46865-2.c Modified: branches/gcc-4_4-branch/gcc/ChangeLog branches/gcc-4_4-branch/gcc/jump.c branches/gcc-4_4-branch/gcc/rtl.c branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
Fixed for 4.4+.
Christian Reis added the following comment to Launchpad bug report 687406: Is this bug now resolved, or is it pending any other backports? -- http://launchpad.net/bugs/687406
Fixed for 4.4.6.