summaryrefslogtreecommitdiffstats
path: root/toolchain/gcc/3.4.2/400-mips-pr17565.patch
blob: 7ae6aa56f6f33d2b7da34dfe5209ddc023b9d0b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
[committed] Fix target/17565: asms in delay slots

    * From: Richard Sandiford <rsandifo at redhat dot com>
    * To: gcc-patches at gcc dot gnu dot org
    * Date: Mon, 20 Sep 2004 07:55:58 +0100
    * Subject: [committed] Fix target/17565: asms in delay slots

The MIPS port was allowing asms to be put into delay slots if the
compiler guesses they are only one instruction long.  This is wrong
because of the possibility of it containing macros.

The problem can be reproduced as an assembler warning
in the following testcase:

int foo (int n)
{
  register int k asm ("$16") = n;
  if (k > 0)
    {
      bar ();
      asm ("li %0,0x12345678" : "=r" (k));
    }
  return k;
}

because the multi-instruction asm statement goes into the delay
slot of the call to bar().

This is reduced from a much more serious linux problem.  Linux is fond
of using empty asm statements, and since gcc estimates empty asms to be
one instruction long, they too might be put into delay slots.  This
actually has the effect of putting the following instruction into the
delay slot instead.  Since there's no assembler warning, the problem was
only detected as a run-time failure.

The fix is simple: set the asm value of "can_delay" to "no".
Tested on mipsisa64-elf, applied to mainline.

This problem goes back to at least 2.95, so it isn't technically a
regression.  On the other hand, it's the kind of bug that could trigger
for different types of code in different releases, so I'm sure there's
a testcase that fails (say) in 3.4 and not in 2.95.  Will probably ask
Mark for permission to backport to 3.4.

Richard


	PR target/17565
	* config/mips/mips.md (define_asm_attributes): Set can_delay to no.

testsuite/
	* gcc.target/mips/asm-1.c: New test.

Index: config/mips/mips.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mips/mips.md,v
retrieving revision 1.306
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.306 mips.md
*** gcc/gcc/config/mips/mips.md	13 Sep 2004 19:32:05 -0000	1.306
--- gcc/gcc/config/mips/mips.md	20 Sep 2004 06:52:31 -0000
*************** (define_attr "may_clobber_hilo" "no,yes"
*** 266,272 ****
  
  ;; Describe a user's asm statement.
  (define_asm_attributes
!   [(set_attr "type" "multi")])
  
  ;; .........................
  ;;
--- 266,273 ----
  
  ;; Describe a user's asm statement.
  (define_asm_attributes
!   [(set_attr "type" "multi")
!    (set_attr "can_delay" "no")])
  
  ;; .........................
  ;;
Index: testsuite/gcc.target/mips/asm-1.c
===================================================================
RCS file: testsuite/gcc.target/mips/asm-1.c
diff -N testsuite/gcc.target/mips/asm-1.c
*** gcc/gcc/testsuite/gcc.target/mips/asm-1.c	1 Jan 1970 00:00:00 -0000
--- gcc/gcc/testsuite/gcc.target/mips/asm-1.c	20 Sep 2004 06:52:31 -0000
***************
*** 0 ****
--- 1,14 ----
+ /* PR target/17565.  GCC used to put the asm into the delay slot
+    of the call.  */
+ /* { dg-do assemble } */
+ /* { dg-options "-O" } */
+ int foo (int n)
+ {
+   register int k asm ("$16") = n;
+   if (k > 0)
+     {
+       bar ();
+       asm ("li %0,0x12345678" : "=r" (k));
+     }
+   return k;
+ }