Bug 46865 - [4.3 Regression] Using -save-temps (or ccache, distcc) produces different results with multiline macros containing asm code
Summary: [4.3 Regression] Using -save-temps (or ccache, distcc) produces different res...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.5.1
: P2 normal
Target Milestone: 4.4.6
Assignee: Jakub Jelinek
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2010-12-09 13:52 UTC by Juha Kallioinen
Modified: 2011-06-27 12:01 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.2, 4.2.4, 4.4.6, 4.5.3, 4.6.0
Known to fail: 4.4.1, 4.4.5, 4.5.1
Last reconfirmed: 2010-12-09 14:46:05


Attachments
example case (176 bytes, text/x-csrc)
2010-12-09 13:52 UTC, Juha Kallioinen
Details
gcc46-pr46865.patch (847 bytes, patch)
2010-12-09 19:11 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Juha Kallioinen 2010-12-09 13:52:33 UTC
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
Comment 1 Richard Biener 2010-12-09 14:46:05 UTC
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.
Comment 2 Richard Biener 2010-12-09 14:50:45 UTC
Works ok with 4.1.
Comment 3 Jakub Jelinek 2010-12-09 19:11:08 UTC
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.
Comment 4 Jakub Jelinek 2010-12-10 12:43:49 UTC
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
Comment 5 Jakub Jelinek 2010-12-10 12:46:41 UTC
Fixed on the trunk so far.
Comment 6 Juha Kallioinen 2010-12-10 13:14:14 UTC
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 :)
Comment 7 Jakub Jelinek 2011-01-16 20:14:53 UTC
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
Comment 8 Jakub Jelinek 2011-01-16 22:53:13 UTC
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
Comment 9 Jakub Jelinek 2011-01-17 08:05:03 UTC
Fixed for 4.4+.
Comment 10 Launchpad 2011-05-11 04:22:42 UTC
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
Comment 11 Richard Biener 2011-06-27 12:01:32 UTC
Fixed for 4.4.6.