From 021f95d99a68b87643fdc06b3f17da1f206f33b3 Mon Sep 17 00:00:00 2001 From: Max Filippov Date: Thu, 11 Jun 2015 17:56:57 +0300 Subject: [PATCH] WIP: xtensa: add -mforce-l32 Signed-off-by: Max Filippov --- gcc/config/xtensa/constraints.md | 16 ++++++++++ gcc/config/xtensa/xtensa.c | 53 +++++++++++++++++++++++++++++++- gcc/config/xtensa/xtensa.md | 49 ++++++++++++++++------------- gcc/config/xtensa/xtensa.opt | 4 +++ 4 files changed, 99 insertions(+), 23 deletions(-) diff --git a/gcc/config/xtensa/constraints.md b/gcc/config/xtensa/constraints.md index 5a794f28f0fe..41facf849e18 100644 --- a/gcc/config/xtensa/constraints.md +++ b/gcc/config/xtensa/constraints.md @@ -142,3 +142,19 @@ (and (match_code "reg") (match_test "reload_in_progress && REGNO (op) >= FIRST_PSEUDO_REGISTER")))) + +(define_constraint "u" + "Memory that is not in a literal pool, but only in the absence of -mforce-l32, + or pseudoregister." + (ior (and (and (match_code "mem") + (match_test "! constantpool_mem_p (op)")) + (match_test "!TARGET_FORCE_L32")) + (and (match_code "reg") + (match_test "reload_in_progress + && REGNO (op) >= FIRST_PSEUDO_REGISTER")))) + +(define_constraint "Z" + "Memory that is not in a literal pool, but only in the presence of -mforce-l32." + (and (and (match_code "mem") + (match_test "! constantpool_mem_p (op)")) + (match_test "TARGET_FORCE_L32"))) diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c index 64d089bdfb0d..bb0be16b9882 100644 --- a/gcc/config/xtensa/xtensa.c +++ b/gcc/config/xtensa/xtensa.c @@ -1801,7 +1801,8 @@ xtensa_legitimate_address_p (machine_mode mode, rtx addr, bool strict) return true; /* Check for "register + offset" addressing. */ - if (GET_CODE (addr) == PLUS) + if (GET_CODE (addr) == PLUS && + (!TARGET_FORCE_L32 || (mode != HImode && mode != QImode))) { rtx xplus0 = XEXP (addr, 0); rtx xplus1 = XEXP (addr, 1); @@ -2285,6 +2286,8 @@ printx (FILE *file, signed int val) fprintf (file, "0x%x", val); } +static void +output_address_base (FILE *file, rtx addr); void print_operand (FILE *file, rtx x, int letter) @@ -2294,6 +2297,13 @@ print_operand (FILE *file, rtx x, int letter) switch (letter) { + case 'B': + if (GET_CODE (x) == MEM) + output_address_base (file, XEXP (x, 0)); + else + output_operand_lossage ("invalid %%B value"); + break; + case 'D': if (GET_CODE (x) == REG || GET_CODE (x) == SUBREG) fprintf (file, "%s", reg_names[xt_true_regnum (x) + 1]); @@ -2437,6 +2447,47 @@ print_operand (FILE *file, rtx x, int letter) } } +static void +output_address_base (FILE *file, rtx addr) +{ + switch (GET_CODE (addr)) + { + default: + fatal_insn ("invalid address", addr); + break; + + case REG: + fprintf (file, "%s", reg_names [REGNO (addr)]); + break; + + case PLUS: + { + rtx reg = (rtx)0; + rtx offset = (rtx)0; + rtx arg0 = XEXP (addr, 0); + rtx arg1 = XEXP (addr, 1); + + if (GET_CODE (arg0) == REG) + { + reg = arg0; + offset = arg1; + } + else if (GET_CODE (arg1) == REG) + { + reg = arg1; + offset = arg0; + } + else + fatal_insn ("no register in address", addr); + + if (CONSTANT_P (offset)) + fprintf (file, "%s", reg_names [REGNO (reg)]); + else + fatal_insn ("address offset not a constant", addr); + } + break; + } +} /* A C compound statement to output to stdio stream STREAM the assembler syntax for an instruction operand that is a memory diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index db54a12b7bc0..93f010063400 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -532,26 +532,28 @@ ;; Zero-extend instructions. (define_insn "zero_extendhisi2" - [(set (match_operand:SI 0 "register_operand" "=a,a") - (zero_extend:SI (match_operand:HI 1 "nonimmed_operand" "r,U")))] + [(set (match_operand:SI 0 "register_operand" "=a,a,a") + (zero_extend:SI (match_operand:HI 1 "nonimmed_operand" "r,u,Z")))] "" "@ extui\t%0, %1, 0, 16 - l16ui\t%0, %1" - [(set_attr "type" "arith,load") + l16ui\t%0, %1 + ssa8l\t%B1 ; srli\t%0, %B1, 2 ; slli\t%0, %0, 2 ; l32i\t%0, %0, 0 ; srl\t%0, %0 ; extui\t%0, %0, 0, 16" + [(set_attr "type" "arith,load,load") (set_attr "mode" "SI") - (set_attr "length" "3,3")]) + (set_attr "length" "3,3,18")]) (define_insn "zero_extendqisi2" - [(set (match_operand:SI 0 "register_operand" "=a,a") - (zero_extend:SI (match_operand:QI 1 "nonimmed_operand" "r,U")))] + [(set (match_operand:SI 0 "register_operand" "=a,a,a") + (zero_extend:SI (match_operand:QI 1 "nonimmed_operand" "r,u,Z")))] "" "@ extui\t%0, %1, 0, 8 - l8ui\t%0, %1" - [(set_attr "type" "arith,load") + l8ui\t%0, %1 + ssa8l\t%B1 ; srli\t%0, %B1, 2 ; slli\t%0, %0, 2 ; l32i\t%0, %0, 0 ; srl\t%0, %0 ; extui\t%0, %0, 0, 8" + [(set_attr "type" "arith,load,load") (set_attr "mode" "SI") - (set_attr "length" "3,3")]) + (set_attr "length" "3,3,18")]) ;; Sign-extend instructions. @@ -569,15 +571,16 @@ }) (define_insn "extendhisi2_internal" - [(set (match_operand:SI 0 "register_operand" "=B,a") - (sign_extend:SI (match_operand:HI 1 "sext_operand" "r,U")))] + [(set (match_operand:SI 0 "register_operand" "=B,a,a") + (sign_extend:SI (match_operand:HI 1 "sext_operand" "r,r,u")))] "" "@ sext\t%0, %1, 15 + slli\t%0, %1, 16 ; srai\t%0, %0, 16 l16si\t%0, %1" - [(set_attr "type" "arith,load") + [(set_attr "type" "arith,arith,load") (set_attr "mode" "SI") - (set_attr "length" "3,3")]) + (set_attr "length" "3,6,3")]) (define_expand "extendqisi2" [(set (match_operand:SI 0 "register_operand" "") @@ -797,8 +800,8 @@ }) (define_insn "movhi_internal" - [(set (match_operand:HI 0 "nonimmed_operand" "=D,D,a,a,a,a,U,*a,*A") - (match_operand:HI 1 "move_operand" "M,d,r,I,Y,U,r,*A,*r"))] + [(set (match_operand:HI 0 "nonimmed_operand" "=D,D,a,a,a,a,a,U,*a,*A") + (match_operand:HI 1 "move_operand" "M,d,r,I,Y,u,Z,r,*A,*r"))] "xtensa_valid_move (HImode, operands)" "@ movi.n\t%0, %x1 @@ -807,12 +810,13 @@ movi\t%0, %x1 movi\t%0, %1 %v1l16ui\t%0, %1 + ssa8l\t%B1 ; srli\t%0, %B1, 2 ; slli\t%0, %0, 2 ; %v1l32i\t%0, %0, 0 ; srl\t%0, %0 ; extui\t%0, %0, 0, 16 %v0s16i\t%1, %0 rsr\t%0, ACCLO wsr\t%1, ACCLO" - [(set_attr "type" "move,move,move,move,move,load,store,rsr,wsr") + [(set_attr "type" "move,move,move,move,move,load,load,store,rsr,wsr") (set_attr "mode" "HI") - (set_attr "length" "2,2,3,3,3,3,3,3,3")]) + (set_attr "length" "2,2,3,3,3,3,18,3,3,3")]) ;; 8-bit Integer moves @@ -826,8 +830,8 @@ }) (define_insn "movqi_internal" - [(set (match_operand:QI 0 "nonimmed_operand" "=D,D,a,a,a,U,*a,*A") - (match_operand:QI 1 "move_operand" "M,d,r,I,U,r,*A,*r"))] + [(set (match_operand:QI 0 "nonimmed_operand" "=D,D,a,a,a,a,U,*a,*A") + (match_operand:QI 1 "move_operand" "M,d,r,I,u,Z,r,*A,*r"))] "xtensa_valid_move (QImode, operands)" "@ movi.n\t%0, %x1 @@ -835,12 +839,13 @@ mov\t%0, %1 movi\t%0, %x1 %v1l8ui\t%0, %1 + ssa8l\t%B1 ; srli\t%0, %B1, 2 ; slli\t%0, %0, 2 ; %v1l32i\t%0, %0, 0 ; srl\t%0, %0 ; extui\t%0, %0, 0, 8 %v0s8i\t%1, %0 rsr\t%0, ACCLO wsr\t%1, ACCLO" - [(set_attr "type" "move,move,move,move,load,store,rsr,wsr") + [(set_attr "type" "move,move,move,move,load,load,store,rsr,wsr") (set_attr "mode" "QI") - (set_attr "length" "2,2,3,3,3,3,3,3")]) + (set_attr "length" "2,2,3,3,3,18,3,3,3")]) ;; Sub-word reloads from the constant pool. diff --git a/gcc/config/xtensa/xtensa.opt b/gcc/config/xtensa/xtensa.opt index ea5c7d596713..a19ec23088c3 100644 --- a/gcc/config/xtensa/xtensa.opt +++ b/gcc/config/xtensa/xtensa.opt @@ -45,3 +45,7 @@ Relax literals in assembler and place them automatically in the text section. mserialize-volatile Target Report Mask(SERIALIZE_VOLATILE) -mno-serialize-volatile Do not serialize volatile memory references with MEMW instructions. + +mforce-l32 +Target Report Mask(FORCE_L32) +Use l32i to access 1- and 2-byte quantities in memory instead of l8ui/l16ui.