951-arm_bug_58595.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58595
  2. --- /dev/null
  3. +++ b/gcc/testsuite/gcc.dg/tls/pr58595.c
  4. @@ -0,0 +1,28 @@
  5. +/* PR target/58595 */
  6. +/* { dg-do run } */
  7. +/* { dg-options "-O2" } */
  8. +/* { dg-additional-options "-fpic" { target fpic } } */
  9. +/* { dg-require-effective-target tls } */
  10. +/* { dg-require-effective-target sync_int_long } */
  11. +
  12. +struct S { unsigned long a, b; };
  13. +__thread struct S s;
  14. +void bar (unsigned long *);
  15. +
  16. +__attribute__((noinline)) void
  17. +foo (void)
  18. +{
  19. + int i;
  20. + for (i = 0; i < 10; i++)
  21. + __sync_fetch_and_add (&s.b, 1L);
  22. +}
  23. +
  24. +int
  25. +main ()
  26. +{
  27. + s.b = 12;
  28. + foo ();
  29. + if (s.b != 22)
  30. + __builtin_abort ();
  31. + return 0;
  32. +}
  33. --- a/gcc/config/arm/arm.c
  34. +++ b/gcc/config/arm/arm.c
  35. @@ -231,7 +231,6 @@ static tree arm_gimplify_va_arg_expr (tr
  36. static void arm_option_override (void);
  37. static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode);
  38. static bool arm_cannot_copy_insn_p (rtx);
  39. -static bool arm_tls_symbol_p (rtx x);
  40. static int arm_issue_rate (void);
  41. static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
  42. static bool arm_output_addr_const_extra (FILE *, rtx);
  43. @@ -6665,6 +6664,32 @@ legitimize_tls_address (rtx x, rtx reg)
  44. rtx
  45. arm_legitimize_address (rtx x, rtx orig_x, enum machine_mode mode)
  46. {
  47. + if (arm_tls_referenced_p (x))
  48. + {
  49. + rtx addend = NULL;
  50. +
  51. + if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS)
  52. + {
  53. + addend = XEXP (XEXP (x, 0), 1);
  54. + x = XEXP (XEXP (x, 0), 0);
  55. + }
  56. +
  57. + if (GET_CODE (x) != SYMBOL_REF)
  58. + return x;
  59. +
  60. + gcc_assert (SYMBOL_REF_TLS_MODEL (x) != 0);
  61. +
  62. + x = legitimize_tls_address (x, NULL_RTX);
  63. +
  64. + if (addend)
  65. + {
  66. + x = gen_rtx_PLUS (SImode, x, addend);
  67. + orig_x = x;
  68. + }
  69. + else
  70. + return x;
  71. + }
  72. +
  73. if (!TARGET_ARM)
  74. {
  75. /* TODO: legitimize_address for Thumb2. */
  76. @@ -6673,9 +6698,6 @@ arm_legitimize_address (rtx x, rtx orig_
  77. return thumb_legitimize_address (x, orig_x, mode);
  78. }
  79. - if (arm_tls_symbol_p (x))
  80. - return legitimize_tls_address (x, NULL_RTX);
  81. -
  82. if (GET_CODE (x) == PLUS)
  83. {
  84. rtx xop0 = XEXP (x, 0);
  85. @@ -6787,9 +6809,6 @@ arm_legitimize_address (rtx x, rtx orig_
  86. rtx
  87. thumb_legitimize_address (rtx x, rtx orig_x, enum machine_mode mode)
  88. {
  89. - if (arm_tls_symbol_p (x))
  90. - return legitimize_tls_address (x, NULL_RTX);
  91. -
  92. if (GET_CODE (x) == PLUS
  93. && CONST_INT_P (XEXP (x, 1))
  94. && (INTVAL (XEXP (x, 1)) >= 32 * GET_MODE_SIZE (mode)
  95. @@ -7080,20 +7099,6 @@ thumb_legitimize_reload_address (rtx *x_
  96. /* Test for various thread-local symbols. */
  97. -/* Return TRUE if X is a thread-local symbol. */
  98. -
  99. -static bool
  100. -arm_tls_symbol_p (rtx x)
  101. -{
  102. - if (! TARGET_HAVE_TLS)
  103. - return false;
  104. -
  105. - if (GET_CODE (x) != SYMBOL_REF)
  106. - return false;
  107. -
  108. - return SYMBOL_REF_TLS_MODEL (x) != 0;
  109. -}
  110. -
  111. /* Helper for arm_tls_referenced_p. */
  112. static int