diff mbox series

RISC-V: Handle non-legitimate address in riscv_legitimize_move

Message ID 20171102160319.3834-1-palmer@dabbelt.com
State New
Headers show
Series RISC-V: Handle non-legitimate address in riscv_legitimize_move | expand

Commit Message

Palmer Dabbelt Nov. 2, 2017, 4:03 p.m. UTC
From: Kito Cheng <kito.cheng@gmail.com>

GCC may generate non-legitimate address due to we allow some
load/store with non-legitimate address in pic.md.

gcc/ChangeLog

2017-11-02  Kito Cheng  <kito.cheng@gmail.com>

        * config/riscv/riscv.c (riscv_legitimize_move): Handle
        non-legitimate address.
---
 gcc/config/riscv/riscv.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Palmer Dabbelt Nov. 3, 2017, 2:59 p.m. UTC | #1
Committed.

On Thu, 02 Nov 2017 09:03:19 PDT (-0700), Palmer Dabbelt wrote:
> From: Kito Cheng <kito.cheng@gmail.com>
>
> GCC may generate non-legitimate address due to we allow some
> load/store with non-legitimate address in pic.md.
>
> gcc/ChangeLog
>
> 2017-11-02  Kito Cheng  <kito.cheng@gmail.com>
>
>         * config/riscv/riscv.c (riscv_legitimize_move): Handle
>         non-legitimate address.
> ---
>  gcc/config/riscv/riscv.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
> index c34468e018d6..b81a2d29fbfd 100644
> --- a/gcc/config/riscv/riscv.c
> +++ b/gcc/config/riscv/riscv.c
> @@ -1332,6 +1332,22 @@ riscv_legitimize_move (machine_mode mode, rtx dest, rtx src)
>        return true;
>      }
>
> +  /* RISC-V GCC may generate non-legitimate address due to we provide some
> +     pattern for optimize access PIC local symbol and it's make GCC generate
> +     unrecognizable instruction during optmizing.  */
> +
> +  if (MEM_P (dest) && !riscv_legitimate_address_p (mode, XEXP (dest, 0),
> +						   reload_completed))
> +    {
> +      XEXP (dest, 0) = riscv_force_address (XEXP (dest, 0), mode);
> +    }
> +
> +  if (MEM_P (src) && !riscv_legitimate_address_p (mode, XEXP (src, 0),
> +						  reload_completed))
> +    {
> +      XEXP (src, 0) = riscv_force_address (XEXP (src, 0), mode);
> +    }
> +
>    return false;
>  }
diff mbox series

Patch

diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index c34468e018d6..b81a2d29fbfd 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -1332,6 +1332,22 @@  riscv_legitimize_move (machine_mode mode, rtx dest, rtx src)
       return true;
     }
 
+  /* RISC-V GCC may generate non-legitimate address due to we provide some
+     pattern for optimize access PIC local symbol and it's make GCC generate
+     unrecognizable instruction during optmizing.  */
+
+  if (MEM_P (dest) && !riscv_legitimate_address_p (mode, XEXP (dest, 0),
+						   reload_completed))
+    {
+      XEXP (dest, 0) = riscv_force_address (XEXP (dest, 0), mode);
+    }
+
+  if (MEM_P (src) && !riscv_legitimate_address_p (mode, XEXP (src, 0),
+						  reload_completed))
+    {
+      XEXP (src, 0) = riscv_force_address (XEXP (src, 0), mode);
+    }
+
   return false;
 }