I was asked to split V4 patch #4.2 into smaller chuncks. This patch is one of 8 patches that were broken out from 4.2. Another patch from 4.2 to use SIGNED_16BIT_OFFSET_EXTRA_P has already been committed.
This patch updates the functions that adjust a vector address to access a scalar element to support prefixed addresses. Compared to patch #4.2, this patch eliminates adding a second constraint for non PC-relative addresses. Instead I just added a pattern to be able to add a PC-relative address to a register, and used that in the problematical case of doing a vector extract with a variable element number where the vector is a static (i.e. uses a PC-relative address). Using all of the patches in this series, I have bootstrapped the compiler on a little endian power8 system and ran the regression tests. In addition, I have built the Spec 2006 and 2017 benchmark suites, for -mcpu=power8, -mcpu=power9, and -mcpu=future, and all of the benchmarks build. Can I check this into the trunk? 2019-10-03 Michael Meissner <meiss...@linux.ibm.com> * config/rs6000/rs6000.c (rs6000_adjust_vec_address): Add support for extracting the element of vector with a PC-relative address. * config/rs6000/rs6000.md (pcrel_add_local_addr): New insn to add an address to a register. Index: gcc/config/rs6000/rs6000.c =================================================================== --- gcc/config/rs6000/rs6000.c (revision 276540) +++ gcc/config/rs6000/rs6000.c (working copy) @@ -6701,6 +6701,7 @@ rs6000_adjust_vec_address (rtx scalar_re rtx element_offset; rtx new_addr; bool valid_addr_p; + bool pcrel_p = pcrel_local_address (addr, Pmode); /* Vector addresses should not have PRE_INC, PRE_DEC, or PRE_MODIFY. */ gcc_assert (GET_RTX_CLASS (GET_CODE (addr)) != RTX_AUTOINC); @@ -6738,6 +6739,40 @@ rs6000_adjust_vec_address (rtx scalar_re else if (REG_P (addr) || SUBREG_P (addr)) new_addr = gen_rtx_PLUS (Pmode, addr, element_offset); + /* Optimize PC-relative addresses with a constant offset. */ + else if (pcrel_p && CONST_INT_P (element_offset)) + { + rtx addr2 = addr; + HOST_WIDE_INT offset = INTVAL (element_offset); + + if (GET_CODE (addr2) == CONST) + addr2 = XEXP (addr2, 0); + + if (GET_CODE (addr2) == PLUS) + { + offset += INTVAL (XEXP (addr2, 1)); + addr2 = XEXP (addr2, 0); + } + + gcc_assert (SIGNED_34BIT_OFFSET_P (offset)); + if (offset) + { + addr2 = gen_rtx_PLUS (Pmode, addr2, GEN_INT (offset)); + new_addr = gen_rtx_CONST (Pmode, addr2); + } + else + new_addr = addr2; + } + + /* Optimize PC-relative addresses with a variable offset to add the + PC-relative address to the offset. */ + else if (pcrel_p) + { + emit_insn (gen_pcrel_add_local_addr (base_tmp, element_offset, addr)); + new_addr = base_tmp; + pcrel_p = false; + } + /* Optimize D-FORM addresses with constant offset with a constant element, to include the element offset in the address directly. */ else if (GET_CODE (addr) == PLUS) @@ -6752,8 +6787,11 @@ rs6000_adjust_vec_address (rtx scalar_re HOST_WIDE_INT offset = INTVAL (op1) + INTVAL (element_offset); rtx offset_rtx = GEN_INT (offset); - if (IN_RANGE (offset, -32768, 32767) - && (scalar_size < 8 || (offset & 0x3) == 0)) + if (TARGET_PREFIXED_ADDR && SIGNED_34BIT_OFFSET_P (offset)) + new_addr = gen_rtx_PLUS (Pmode, op0, offset_rtx); + + else if (SIGNED_16BIT_OFFSET_P (offset) + && (scalar_size < 8 || (offset & 0x3) == 0)) new_addr = gen_rtx_PLUS (Pmode, op0, offset_rtx); else { @@ -6801,11 +6839,11 @@ rs6000_adjust_vec_address (rtx scalar_re new_addr = gen_rtx_PLUS (Pmode, base_tmp, element_offset); } - /* If we have a PLUS, we need to see whether the particular register class - allows for D-FORM or X-FORM addressing. */ - if (GET_CODE (new_addr) == PLUS) + /* If we have a PLUS or a PC-relative address without the PLUS, we need to + see whether the particular register class allows for D-FORM or X-FORM + addressing. */ + if (GET_CODE (new_addr) == PLUS || pcrel_p) { - rtx op1 = XEXP (new_addr, 1); addr_mask_type addr_mask; unsigned int scalar_regno = reg_or_subregno (scalar_reg); @@ -6822,10 +6860,16 @@ rs6000_adjust_vec_address (rtx scalar_re else gcc_unreachable (); - if (REG_P (op1) || SUBREG_P (op1)) - valid_addr_p = (addr_mask & RELOAD_REG_INDEXED) != 0; - else + if (pcrel_p) valid_addr_p = (addr_mask & RELOAD_REG_OFFSET) != 0; + else + { + rtx op1 = XEXP (new_addr, 1); + if (REG_P (op1) || SUBREG_P (op1)) + valid_addr_p = (addr_mask & RELOAD_REG_INDEXED) != 0; + else + valid_addr_p = (addr_mask & RELOAD_REG_OFFSET) != 0; + } } else if (REG_P (new_addr) || SUBREG_P (new_addr)) Index: gcc/config/rs6000/rs6000.md =================================================================== --- gcc/config/rs6000/rs6000.md (revision 276540) +++ gcc/config/rs6000/rs6000.md (working copy) @@ -9962,6 +9962,15 @@ (define_insn "*pcrel_local_addr" "la %0,%a1" [(set_attr "prefixed" "yes")]) +;; Add a local PC-relative address to a register. +(define_insn "pcrel_add_local_addr" + [(set (match_operand:DI 0 "gpc_reg_operand" "=r") + (plus:DI (match_operand:DI 1 "gpc_reg_operand" "r") + (match_operand:DI 2 "pcrel_local_address")))] + "TARGET_PCREL" + "addi %0,%1,%a2" + [(set_attr "prefixed" "yes")]) + ;; Load up a PC-relative address to an external symbol. If the symbol and the ;; program are both defined in the main program, the linker will optimize this ;; to a PADDI. Otherwise, it will create a GOT address that is relocated by -- Michael Meissner, IBM IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA email: meiss...@linux.ibm.com, phone: +1 (978) 899-4797