1 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58595
4 +++ b/gcc/testsuite/gcc.dg/tls/pr58595.c
8 +/* { dg-options "-O2" } */
9 +/* { dg-additional-options "-fpic" { target fpic } } */
10 +/* { dg-require-effective-target tls } */
11 +/* { dg-require-effective-target sync_int_long } */
13 +struct S { unsigned long a, b; };
15 +void bar (unsigned long *);
17 +__attribute__((noinline)) void
21 + for (i = 0; i < 10; i++)
22 + __sync_fetch_and_add (&s.b, 1L);
34 --- a/gcc/config/arm/arm.c
35 +++ b/gcc/config/arm/arm.c
36 @@ -231,7 +231,6 @@ static tree arm_gimplify_va_arg_expr (tr
37 static void arm_option_override (void);
38 static unsigned HOST_WIDE_INT arm_shift_truncation_mask (enum machine_mode);
39 static bool arm_cannot_copy_insn_p (rtx);
40 -static bool arm_tls_symbol_p (rtx x);
41 static int arm_issue_rate (void);
42 static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
43 static bool arm_output_addr_const_extra (FILE *, rtx);
44 @@ -6665,6 +6664,32 @@ legitimize_tls_address (rtx x, rtx reg)
46 arm_legitimize_address (rtx x, rtx orig_x, enum machine_mode mode)
48 + if (arm_tls_referenced_p (x))
52 + if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS)
54 + addend = XEXP (XEXP (x, 0), 1);
55 + x = XEXP (XEXP (x, 0), 0);
58 + if (GET_CODE (x) != SYMBOL_REF)
61 + gcc_assert (SYMBOL_REF_TLS_MODEL (x) != 0);
63 + x = legitimize_tls_address (x, NULL_RTX);
67 + x = gen_rtx_PLUS (SImode, x, addend);
76 /* TODO: legitimize_address for Thumb2. */
77 @@ -6673,9 +6698,6 @@ arm_legitimize_address (rtx x, rtx orig_
78 return thumb_legitimize_address (x, orig_x, mode);
81 - if (arm_tls_symbol_p (x))
82 - return legitimize_tls_address (x, NULL_RTX);
84 if (GET_CODE (x) == PLUS)
86 rtx xop0 = XEXP (x, 0);
87 @@ -6787,9 +6809,6 @@ arm_legitimize_address (rtx x, rtx orig_
89 thumb_legitimize_address (rtx x, rtx orig_x, enum machine_mode mode)
91 - if (arm_tls_symbol_p (x))
92 - return legitimize_tls_address (x, NULL_RTX);
94 if (GET_CODE (x) == PLUS
95 && CONST_INT_P (XEXP (x, 1))
96 && (INTVAL (XEXP (x, 1)) >= 32 * GET_MODE_SIZE (mode)
97 @@ -7080,20 +7099,6 @@ thumb_legitimize_reload_address (rtx *x_
99 /* Test for various thread-local symbols. */
101 -/* Return TRUE if X is a thread-local symbol. */
104 -arm_tls_symbol_p (rtx x)
106 - if (! TARGET_HAVE_TLS)
109 - if (GET_CODE (x) != SYMBOL_REF)
112 - return SYMBOL_REF_TLS_MODEL (x) != 0;
115 /* Helper for arm_tls_referenced_p. */