aarch64: Fix SYMBOL_TINY_GOT handling for ILP32 [PR94201]
authorDuan bo <duanbo3@huawei.com>
Wed, 18 Mar 2020 10:18:39 +0000 (10:18 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Wed, 18 Mar 2020 11:50:04 +0000 (11:50 +0000)
The SYMBOL_TINY_GOT case in aarch64_load_symref_appropriately was
missing support for ILP32.  This caused an ICE on the testcase.

2020-03-18  Duan bo  <duanbo3@huawei.com>

gcc/
PR target/94201
* config/aarch64/aarch64.md (ldr_got_tiny): Delete.
(@ldr_got_tiny_<mode>): New pattern.
(ldr_got_tiny_sidi): Likewise.
* config/aarch64/aarch64.c (aarch64_load_symref_appropriately): Use
them to handle SYMBOL_TINY_GOT for ILP32.

gcc/testsuite/
PR target/94201
* gcc.target/aarch64/pr94201.c:New test.

gcc/ChangeLog
gcc/config/aarch64/aarch64.c
gcc/config/aarch64/aarch64.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/aarch64/pr94201.c [new file with mode: 0644]

index 1fa291100d0a6cfaa1550532929cfea6d8b91f2b..5eb23b5703797e6dce68d16c8e82048ac7e22d90 100644 (file)
@@ -1,3 +1,12 @@
+2020-03-18  Duan bo  <duanbo3@huawei.com>
+
+       PR target/94201
+       * config/aarch64/aarch64.md (ldr_got_tiny): Delete.
+       (@ldr_got_tiny_<mode>): New pattern.
+       (ldr_got_tiny_sidi): Likewise.
+       * config/aarch64/aarch64.c (aarch64_load_symref_appropriately): Use
+       them to handle SYMBOL_TINY_GOT for ILP32.
+
 2020-03-18  Richard Sandiford  <richard.sandiford@arm.com>
 
        * config/aarch64/aarch64.c (aarch64_sve_abi): Treat p12-p15 as
index 26c00969cc1745b663598d480a689ee125d08b13..c90de65de127992cc0bd9603a32684ebb5bd4fdf 100644 (file)
@@ -2739,8 +2739,21 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
       }
 
     case SYMBOL_TINY_GOT:
-      emit_insn (gen_ldr_got_tiny (dest, imm));
-      return;
+      {
+       rtx insn;
+       machine_mode mode = GET_MODE (dest);
+
+       if (mode == ptr_mode)
+         insn = gen_ldr_got_tiny (mode, dest, imm);
+       else
+         {
+           gcc_assert (mode == Pmode);
+           insn = gen_ldr_got_tiny_sidi (dest, imm);
+         }
+
+       emit_insn (insn);
+       return;
+      }
 
     case SYMBOL_TINY_TLSIE:
       {
index 7ad4e918578bae5734647af700c23224261f2504..c7c4d1dd519af6c9df03ba74e7b6ade5f122b4d8 100644 (file)
   [(set_attr "type" "load_4")]
 )
 
-(define_insn "ldr_got_tiny"
-  [(set (match_operand:DI 0 "register_operand" "=r")
-       (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "S")]
-                  UNSPEC_GOTTINYPIC))]
+(define_insn "@ldr_got_tiny_<mode>"
+  [(set (match_operand:PTR 0 "register_operand" "=r")
+       (unspec:PTR [(match_operand:PTR 1 "aarch64_valid_symref" "S")]
+                   UNSPEC_GOTTINYPIC))]
   ""
-  "ldr\\t%0, %L1"
-  [(set_attr "type" "load_8")]
+  "ldr\t%<w>0, %L1"
+  [(set_attr "type" "load_<ldst_sz>")]
+)
+
+(define_insn "ldr_got_tiny_sidi"
+  [(set (match_operand:DI 0 "register_operand" "=r")
+       (zero_extend:DI
+         (unspec:SI [(match_operand:DI 1 "aarch64_valid_symref" "S")]
+                    UNSPEC_GOTTINYPIC)))]
+  "TARGET_ILP32"
+  "ldr\t%w0, %L1"
+  [(set_attr "type" "load_4")]
 )
 
 (define_insn "aarch64_load_tp_hard"
index 3c70254fc6c031d67623b8a28e13db534139a178..e8b78df02def2800befd89e9f758d734a5d873e0 100644 (file)
@@ -1,3 +1,8 @@
+2020-03-18  Duan bo  <duanbo3@huawei.com>
+
+       PR target/94201
+       * gcc.target/aarch64/pr94201.c:New test.
+
 2020-03-18  Richard Sandiford  <richard.sandiford@arm.com>
 
        * gcc.target/aarch64/sve/acle/general/cpy_1.c: Leave gaps for in the
diff --git a/gcc/testsuite/gcc.target/aarch64/pr94201.c b/gcc/testsuite/gcc.target/aarch64/pr94201.c
new file mode 100644 (file)
index 0000000..6917616
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-mcmodel=tiny -mabi=ilp32 -fPIC" } */
+
+extern int bar (void *);
+extern long long a;
+
+int
+foo (void)
+{
+  a = 1;
+  return bar ((void *)bar);
+}
+