This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix asm impossible reload


PowerPC64 linux people have been using a work-around in the following
kernel macro, using "=r" instead of "=g", in order to compile the
kernel.

/* This macro obfuscates arithmetic on a variable address so that gcc
   shouldn't recognize the original var, and make assumptions about it */
#define RELOC_HIDE(ptr, off)					\
  ({ unsigned long __ptr;					\
    __asm__ ("" : "=g"(__ptr) : "0"(ptr));		\
    (typeof(ptr)) (__ptr + (off)); })

The trouble is that Linus won't accept the work-around, claiming
that it must be a compiler bug.  He's correct..

"=g" allows a symbol_ref, like so:

(gdb) p debug_rtx (insn)
(insn:HI 567 568 198 9 (nil) (set (reg/v:DI 24 r24 [185])
        (asm_operands:DI ("") ("=g") 0 [
                (symbol_ref:DI ("kstat__per_cpu"))
            ]
             [
                (asm_input:DI ("0"))
            ] ("arch/ppc64/kernel/irq.c") 362)) -1 (nil)
    (nil))
$1 = void
(gdb) n
(gdb) 
(gdb) 

Which is turned into a toc reference by reload, like so:

(gdb) p debug_rtx (prev->fld[2].rtx)
(insn 592 568 593 9 (nil) (use (symbol_ref:DI ("kstat__per_cpu"))) -1 (nil)
    (nil))
$2 = void
(gdb) p debug_rtx (prev->fld[2].rtx->fld[2].rtx)
(insn 593 592 594 9 (nil) (set (reg:DI 9 r9)
        (mem/u:DI (plus:DI (reg:DI 2 r2)
                (const:DI (minus:DI (symbol_ref/u:DI ("*.LC44"))
                        (symbol_ref:DI ("*.LCTOC1"))))) [0 S8 A8])) -1 (nil)
    (nil))
$3 = void
(gdb) p debug_rtx (prev->fld[2].rtx->fld[2].rtx->fld[2].rtx)
(insn 594 593 567 9 (nil) (set (reg/v:DI 24 r24 [185])
        (reg:DI 9 r9)) -1 (nil)
    (nil))
$4 = void
(gdb) 

And the "use" isn't recognized as valid.

	* reload1.c (reload_as_needed): Allow a USE in asm reloads.

OK mainline, 3.3 and 3.2?

--- gcc-ppc64-33.orig/gcc/reload1.c	2003-03-27 22:11:53.000000000 +1030
+++ gcc-ppc64-33/gcc/reload1.c	2003-03-27 22:12:14.000000000 +1030
@@ -3930,6 +3930,7 @@ reload_as_needed (live_known)
 	      if (asm_noperands (PATTERN (insn)) >= 0)
 		for (p = NEXT_INSN (prev); p != next; p = NEXT_INSN (p))
 		  if (p != insn && INSN_P (p)
+		      && GET_CODE (PATTERN (p)) != USE
 		      && (recog_memoized (p) < 0
 			  || (extract_insn (p), ! constrain_operands (1))))
 		    {

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]