Hi, The patch fixes an ICE when the compiler tries to split an instruction. Test attached.
No regression. Ok to apply? Regards, Robert gcc/ 2016-05-20 Andrew Bennett <andrew.benn...@imgtec.com> * config/mips/mips.c (mips_constant_pool_symbol_in_sdata_p): New function. (mips_output_move): Copy GP instead of splitting HIGH when accessing constant pool data. gcc/testsuite/ 2016-05-20 Robert Suchanek <robert.sucha...@imgtec.com> * gcc.target/mips/mips16-gp-bug-1.c: New test. --- gcc/config/mips/mips.c | 20 +++++++++++++++++++- gcc/testsuite/gcc.target/mips/mips16-gp-bug-1.c | 12 ++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/mips/mips16-gp-bug-1.c diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c index cbe1007..e6d8f76 100644 --- a/gcc/config/mips/mips.c +++ b/gcc/config/mips/mips.c @@ -5053,6 +5053,18 @@ mips_split_move_insn (rtx dest, rtx src, rtx insn) mips_split_move (dest, src, mips_insn_split_type (insn)); } +/* Return true if X is a GP-relative symbol in the constant pool. + CONTEXT is the context in which X appears. */ + +bool +mips_constant_pool_symbol_in_sdata_p (rtx x, enum mips_symbol_context context) +{ + enum mips_symbol_type symbol_type; + return (mips_symbolic_constant_p (x, context, &symbol_type) + && symbol_type == SYMBOL_GP_RELATIVE + && CONSTANT_POOL_ADDRESS_P (x)); +} + /* Return the appropriate instructions to move SRC into DEST. Assume that SRC is operand 1 and DEST is operand 0. */ @@ -5202,7 +5214,13 @@ mips_output_move (rtx dest, rtx src) } if (src_code == HIGH) - return TARGET_MIPS16 ? "#" : "lui\t%0,%h1"; + { + if (mips_constant_pool_symbol_in_sdata_p (XEXP (src, 0), + SYMBOL_CONTEXT_MEM)) + return "move\t%0,$28"; + + return TARGET_MIPS16 ? "#" : "lui\t%0,%h1"; + } if (CONST_GP_P (src)) return "move\t%0,%1"; diff --git a/gcc/testsuite/gcc.target/mips/mips16-gp-bug-1.c b/gcc/testsuite/gcc.target/mips/mips16-gp-bug-1.c new file mode 100644 index 0000000..85a6d83 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/mips16-gp-bug-1.c @@ -0,0 +1,12 @@ +/* { dg-options "(-mips16) -G4 -mno-abicalls -mcode-readable=no" } */ +typedef struct { int a, b, c, d; } A[5000]; +int a, b; +extern void bar (int, int, A); + +void +foo (int p1) +{ + A c; + while (p1) + bar (a, b, c); +} -- 2.8.2.396.g5fe494c