===================================================================
@@ -1978,8 +1978,15 @@ process_alt_operands (int only_alternati
(op, this_alternative) == NO_REGS))))
reject += LRA_MAX_REJECT;
- if (! ((const_to_mem && constmemok)
- || (MEM_P (op) && offmemok)))
+ if (MEM_P (op) && offmemok)
+ {
+ /* If we know offset and this non-offsetable memory,
+ something wrong with this memory and it is better
+ to try other memory possibilities. */
+ if (MEM_OFFSET_KNOWN_P (op))
+ reject += LRA_MAX_REJECT;
+ }
+ else if (! (const_to_mem && constmemok))
{
/* We prefer to reload pseudos over reloading other
things, since such reloads may be able to be
===================================================================
@@ -0,0 +1,12 @@
+/* PR rtl-optimization/56847 */
+/* { dg-do compile { target pie } } */
+/* { dg-options "-O2 -fpie" } */
+
+struct S { long int a, b; } e;
+__thread struct S s;
+
+void
+foo (void)
+{
+ s = e;
+}