400-mips-delay-slot.patch 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. http://www.linux-mips.org/archives/linux-mips/2004-09/msg00000.html
  2. Atsushi Nemoto <anemo@mba.ocn.ne.jp> writes:
  3. >/ Is this a get_user's problem or gcc's?/
  4. The latter. gcc is putting the empty asm:
  5. __asm__ ("":"=r" (__gu_val));
  6. into the delay slot of the call.
  7. Part of the problem is that gcc estimates the length of an asm to be the
  8. number of instruction separators + 1. This means that it estimates the
  9. asm above to be one instruction long, which is perhaps a little silly
  10. for an empty string.
  11. But the real problem is that gcc should never trust this estimate anyway,
  12. since each "instruction" could obviously be a multi-instruction macro.
  13. gcc should certainly never put asms into delay slots.
  14. FWIW, I don't think the bug is specific to 3.3 or 3.4. It could
  15. probably trigger for other gcc versions too. It is highly dependent
  16. on scheduling though.
  17. The attached 3.4.x patch fixes the problem there, but if you want to work
  18. around it for old versions, just avoid using empty asms if you can,
  19. or make them volatile if you can't.
  20. Of course, the problem isn't confined to empty asms. If you have an asm
  21. with a single, multi-instruction macro, gcc might try putting that in a
  22. delay slot too. You should at least get an assembler warning in that case.
  23. Richard
  24. --- gcc-3.4.1/gcc/config/mips/mips.md-orig 2004-09-02 10:38:36.000000000 -0500
  25. +++ gcc-3.4.1/gcc/config/mips/mips.md 2004-09-02 10:38:42.000000000 -0500
  26. @@ -251,7 +251,7 @@
  27. ;; Can the instruction be put into a delay slot?
  28. (define_attr "can_delay" "no,yes"
  29. - (if_then_else (and (eq_attr "type" "!branch,call,jump")
  30. + (if_then_else (and (eq_attr "type" "!branch,call,jump,multi")
  31. (and (eq_attr "hazard" "none")
  32. (eq_attr "single_insn" "yes")))
  33. (const_string "yes")