0002-Revert-re-PR-target-92095-internal-error-with-O1-mcp.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. From bb9b71752267444b4360442b89129bfc0ae938d3 Mon Sep 17 00:00:00 2001
  2. From: Romain Naour <romain.naour@gmail.com>
  3. Date: Wed, 20 Jan 2021 23:06:07 +0100
  4. Subject: [PATCH] Revert "re PR target/92095 (internal error with -O1
  5. -mcpu=niagara2 -fPIE)"
  6. This reverts commit 3fcce773f0f914c0499b130c6e9efa0e45ee54a0.
  7. Building the Buildroot defconfig qemu_sparc_ss10_defconfig using
  8. gcc 8.4, 9.3 and 10 produce a broken rootfs that trigger illegal
  9. instruction messages.
  10. gcc 8.3, 9.2 are the latest working gcc version.
  11. git bisect between gcc 8.4 and 8.4 allowed to identify
  12. the commit that introcuce the regression.
  13. Reverting this patch allowed to produce a working rootfs.
  14. Signed-off-by: Romain Naour <romain.naour@gmail.com>
  15. Cc: Eric Botcazou <ebotcazou@gcc.gnu.org>
  16. ---
  17. gcc/config/sparc/sparc-protos.h | 1 -
  18. gcc/config/sparc/sparc.c | 121 +++++++-----------
  19. gcc/config/sparc/sparc.md | 5 +-
  20. .../gcc.c-torture/compile/20191108-1.c | 14 --
  21. gcc/testsuite/gcc.target/sparc/overflow-3.c | 2 +-
  22. gcc/testsuite/gcc.target/sparc/overflow-4.c | 2 +-
  23. gcc/testsuite/gcc.target/sparc/overflow-5.c | 2 +-
  24. 7 files changed, 53 insertions(+), 94 deletions(-)
  25. delete mode 100644 gcc/testsuite/gcc.c-torture/compile/20191108-1.c
  26. diff --git a/gcc/config/sparc/sparc-protos.h b/gcc/config/sparc/sparc-protos.h
  27. index b3f73c2f2bf..71a067e871c 100644
  28. --- a/gcc/config/sparc/sparc-protos.h
  29. +++ b/gcc/config/sparc/sparc-protos.h
  30. @@ -69,7 +69,6 @@ extern void sparc_split_reg_mem (rtx, rtx, machine_mode);
  31. extern void sparc_split_mem_reg (rtx, rtx, machine_mode);
  32. extern int sparc_split_reg_reg_legitimate (rtx, rtx);
  33. extern void sparc_split_reg_reg (rtx, rtx, machine_mode);
  34. -extern const char *output_load_pcrel_sym (rtx *);
  35. extern const char *output_ubranch (rtx, rtx_insn *);
  36. extern const char *output_cbranch (rtx, rtx, int, int, int, rtx_insn *);
  37. extern const char *output_return (rtx_insn *);
  38. diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c
  39. index 73032d33596..db1b428db90 100644
  40. --- a/gcc/config/sparc/sparc.c
  41. +++ b/gcc/config/sparc/sparc.c
  42. @@ -4200,6 +4200,13 @@ eligible_for_sibcall_delay (rtx_insn *trial)
  43. static bool
  44. sparc_cannot_force_const_mem (machine_mode mode, rtx x)
  45. {
  46. + /* After IRA has run in PIC mode, it is too late to put anything into the
  47. + constant pool if the PIC register hasn't already been initialized. */
  48. + if ((lra_in_progress || reload_in_progress)
  49. + && flag_pic
  50. + && !crtl->uses_pic_offset_table)
  51. + return true;
  52. +
  53. switch (GET_CODE (x))
  54. {
  55. case CONST_INT:
  56. @@ -4235,11 +4242,9 @@ sparc_cannot_force_const_mem (machine_mode mode, rtx x)
  57. }
  58. /* Global Offset Table support. */
  59. -static GTY(()) rtx got_symbol_rtx = NULL_RTX;
  60. -static GTY(()) rtx got_register_rtx = NULL_RTX;
  61. static GTY(()) rtx got_helper_rtx = NULL_RTX;
  62. -
  63. -static GTY(()) bool got_helper_needed = false;
  64. +static GTY(()) rtx got_register_rtx = NULL_RTX;
  65. +static GTY(()) rtx got_symbol_rtx = NULL_RTX;
  66. /* Return the SYMBOL_REF for the Global Offset Table. */
  67. @@ -4252,6 +4257,27 @@ sparc_got (void)
  68. return got_symbol_rtx;
  69. }
  70. +#ifdef HAVE_GAS_HIDDEN
  71. +# define USE_HIDDEN_LINKONCE 1
  72. +#else
  73. +# define USE_HIDDEN_LINKONCE 0
  74. +#endif
  75. +
  76. +static void
  77. +get_pc_thunk_name (char name[32], unsigned int regno)
  78. +{
  79. + const char *reg_name = reg_names[regno];
  80. +
  81. + /* Skip the leading '%' as that cannot be used in a
  82. + symbol name. */
  83. + reg_name += 1;
  84. +
  85. + if (USE_HIDDEN_LINKONCE)
  86. + sprintf (name, "__sparc_get_pc_thunk.%s", reg_name);
  87. + else
  88. + ASM_GENERATE_INTERNAL_LABEL (name, "LADDPC", regno);
  89. +}
  90. +
  91. /* Wrapper around the load_pcrel_sym{si,di} patterns. */
  92. static rtx
  93. @@ -4271,78 +4297,30 @@ gen_load_pcrel_sym (rtx op0, rtx op1, rtx op2)
  94. return insn;
  95. }
  96. -/* Output the load_pcrel_sym{si,di} patterns. */
  97. -
  98. -const char *
  99. -output_load_pcrel_sym (rtx *operands)
  100. -{
  101. - if (flag_delayed_branch)
  102. - {
  103. - output_asm_insn ("sethi\t%%hi(%a1-4), %0", operands);
  104. - output_asm_insn ("call\t%a2", operands);
  105. - output_asm_insn (" add\t%0, %%lo(%a1+4), %0", operands);
  106. - }
  107. - else
  108. - {
  109. - output_asm_insn ("sethi\t%%hi(%a1-8), %0", operands);
  110. - output_asm_insn ("add\t%0, %%lo(%a1-4), %0", operands);
  111. - output_asm_insn ("call\t%a2", operands);
  112. - output_asm_insn (" nop", NULL);
  113. - }
  114. -
  115. - if (operands[2] == got_helper_rtx)
  116. - got_helper_needed = true;
  117. -
  118. - return "";
  119. -}
  120. -
  121. -#ifdef HAVE_GAS_HIDDEN
  122. -# define USE_HIDDEN_LINKONCE 1
  123. -#else
  124. -# define USE_HIDDEN_LINKONCE 0
  125. -#endif
  126. -
  127. /* Emit code to load the GOT register. */
  128. void
  129. load_got_register (void)
  130. {
  131. - rtx insn;
  132. + if (!got_register_rtx)
  133. + got_register_rtx = gen_rtx_REG (Pmode, GLOBAL_OFFSET_TABLE_REGNUM);
  134. if (TARGET_VXWORKS_RTP)
  135. - {
  136. - if (!got_register_rtx)
  137. - got_register_rtx = pic_offset_table_rtx;
  138. -
  139. - insn = gen_vxworks_load_got ();
  140. - }
  141. + emit_insn (gen_vxworks_load_got ());
  142. else
  143. {
  144. - if (!got_register_rtx)
  145. - got_register_rtx = gen_rtx_REG (Pmode, GLOBAL_OFFSET_TABLE_REGNUM);
  146. -
  147. /* The GOT symbol is subject to a PC-relative relocation so we need a
  148. helper function to add the PC value and thus get the final value. */
  149. if (!got_helper_rtx)
  150. {
  151. char name[32];
  152. -
  153. - /* Skip the leading '%' as that cannot be used in a symbol name. */
  154. - if (USE_HIDDEN_LINKONCE)
  155. - sprintf (name, "__sparc_get_pc_thunk.%s",
  156. - reg_names[REGNO (got_register_rtx)] + 1);
  157. - else
  158. - ASM_GENERATE_INTERNAL_LABEL (name, "LADDPC",
  159. - REGNO (got_register_rtx));
  160. -
  161. + get_pc_thunk_name (name, GLOBAL_OFFSET_TABLE_REGNUM);
  162. got_helper_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
  163. }
  164. - insn
  165. - = gen_load_pcrel_sym (got_register_rtx, sparc_got (), got_helper_rtx);
  166. + emit_insn (gen_load_pcrel_sym (got_register_rtx, sparc_got (),
  167. + got_helper_rtx));
  168. }
  169. -
  170. - emit_insn (insn);
  171. }
  172. /* Ensure that we are not using patterns that are not OK with PIC. */
  173. @@ -5494,7 +5472,7 @@ save_local_or_in_reg_p (unsigned int regno, int leaf_function)
  174. return true;
  175. /* GOT register (%l7) if needed. */
  176. - if (got_register_rtx && regno == REGNO (got_register_rtx))
  177. + if (regno == GLOBAL_OFFSET_TABLE_REGNUM && got_register_rtx)
  178. return true;
  179. /* If the function accesses prior frames, the frame pointer and the return
  180. @@ -12475,9 +12453,10 @@ static void
  181. sparc_file_end (void)
  182. {
  183. /* If we need to emit the special GOT helper function, do so now. */
  184. - if (got_helper_needed)
  185. + if (got_helper_rtx)
  186. {
  187. const char *name = XSTR (got_helper_rtx, 0);
  188. + const char *reg_name = reg_names[GLOBAL_OFFSET_TABLE_REGNUM];
  189. #ifdef DWARF2_UNWIND_INFO
  190. bool do_cfi;
  191. #endif
  192. @@ -12514,22 +12493,17 @@ sparc_file_end (void)
  193. #ifdef DWARF2_UNWIND_INFO
  194. do_cfi = dwarf2out_do_cfi_asm ();
  195. if (do_cfi)
  196. - output_asm_insn (".cfi_startproc", NULL);
  197. + fprintf (asm_out_file, "\t.cfi_startproc\n");
  198. #endif
  199. if (flag_delayed_branch)
  200. - {
  201. - output_asm_insn ("jmp\t%%o7+8", NULL);
  202. - output_asm_insn (" add\t%%o7, %0, %0", &got_register_rtx);
  203. - }
  204. + fprintf (asm_out_file, "\tjmp\t%%o7+8\n\t add\t%%o7, %s, %s\n",
  205. + reg_name, reg_name);
  206. else
  207. - {
  208. - output_asm_insn ("add\t%%o7, %0, %0", &got_register_rtx);
  209. - output_asm_insn ("jmp\t%%o7+8", NULL);
  210. - output_asm_insn (" nop", NULL);
  211. - }
  212. + fprintf (asm_out_file, "\tadd\t%%o7, %s, %s\n\tjmp\t%%o7+8\n\t nop\n",
  213. + reg_name, reg_name);
  214. #ifdef DWARF2_UNWIND_INFO
  215. if (do_cfi)
  216. - output_asm_insn (".cfi_endproc", NULL);
  217. + fprintf (asm_out_file, "\t.cfi_endproc\n");
  218. #endif
  219. }
  220. @@ -13035,10 +13009,7 @@ sparc_init_pic_reg (void)
  221. edge entry_edge;
  222. rtx_insn *seq;
  223. - /* In PIC mode, we need to always initialize the PIC register if optimization
  224. - is enabled, because we are called from IRA and LRA may later force things
  225. - to the constant pool for optimization purposes. */
  226. - if (!flag_pic || (!crtl->uses_pic_offset_table && !optimize))
  227. + if (!crtl->uses_pic_offset_table)
  228. return;
  229. start_sequence ();
  230. diff --git a/gcc/config/sparc/sparc.md b/gcc/config/sparc/sparc.md
  231. index 468e2cc5d3b..25134bd1148 100644
  232. --- a/gcc/config/sparc/sparc.md
  233. +++ b/gcc/config/sparc/sparc.md
  234. @@ -1601,7 +1601,10 @@
  235. (clobber (reg:P O7_REG))]
  236. "REGNO (operands[0]) == INTVAL (operands[3])"
  237. {
  238. - return output_load_pcrel_sym (operands);
  239. + if (flag_delayed_branch)
  240. + return "sethi\t%%hi(%a1-4), %0\n\tcall\t%a2\n\t add\t%0, %%lo(%a1+4), %0";
  241. + else
  242. + return "sethi\t%%hi(%a1-8), %0\n\tadd\t%0, %%lo(%a1-4), %0\n\tcall\t%a2\n\t nop";
  243. }
  244. [(set (attr "type") (const_string "multi"))
  245. (set (attr "length")
  246. diff --git a/gcc/testsuite/gcc.c-torture/compile/20191108-1.c b/gcc/testsuite/gcc.c-torture/compile/20191108-1.c
  247. deleted file mode 100644
  248. index 7929751bb06..00000000000
  249. --- a/gcc/testsuite/gcc.c-torture/compile/20191108-1.c
  250. +++ /dev/null
  251. @@ -1,14 +0,0 @@
  252. -/* PR target/92095 */
  253. -/* Testcase by Sergei Trofimovich <slyfox@inbox.ru> */
  254. -
  255. -typedef union {
  256. - double a;
  257. - int b[2];
  258. -} c;
  259. -
  260. -double d(int e)
  261. -{
  262. - c f;
  263. - (&f)->b[0] = 15728640;
  264. - return e ? -(&f)->a : (&f)->a;
  265. -}
  266. diff --git a/gcc/testsuite/gcc.target/sparc/overflow-3.c b/gcc/testsuite/gcc.target/sparc/overflow-3.c
  267. index 18253bb6e5e..8cb24f52f7b 100644
  268. --- a/gcc/testsuite/gcc.target/sparc/overflow-3.c
  269. +++ b/gcc/testsuite/gcc.target/sparc/overflow-3.c
  270. @@ -1,5 +1,5 @@
  271. /* { dg-do compile } */
  272. -/* { dg-options "-O -fno-pie" } */
  273. +/* { dg-options "-O" } */
  274. /* { dg-require-effective-target lp64 } */
  275. #include <stdbool.h>
  276. diff --git a/gcc/testsuite/gcc.target/sparc/overflow-4.c b/gcc/testsuite/gcc.target/sparc/overflow-4.c
  277. index fb30877efb9..868edea2b9e 100644
  278. --- a/gcc/testsuite/gcc.target/sparc/overflow-4.c
  279. +++ b/gcc/testsuite/gcc.target/sparc/overflow-4.c
  280. @@ -1,5 +1,5 @@
  281. /* { dg-do compile } */
  282. -/* { dg-options "-O -fno-pie -mno-vis3" } */
  283. +/* { dg-options "-O -mno-vis3" } */
  284. /* { dg-require-effective-target lp64 } */
  285. #include <stdbool.h>
  286. diff --git a/gcc/testsuite/gcc.target/sparc/overflow-5.c b/gcc/testsuite/gcc.target/sparc/overflow-5.c
  287. index 509d957715d..501ce04f7a1 100644
  288. --- a/gcc/testsuite/gcc.target/sparc/overflow-5.c
  289. +++ b/gcc/testsuite/gcc.target/sparc/overflow-5.c
  290. @@ -1,5 +1,5 @@
  291. /* { dg-do compile } */
  292. -/* { dg-options "-O -fno-pie -mvis3" } */
  293. +/* { dg-options "-O -mvis3" } */
  294. /* { dg-require-effective-target lp64 } */
  295. #include <stdbool.h>
  296. --
  297. 2.25.4