https://gcc.gnu.org/g:deb635249c04efee269e9407c48de6af92361ad9
commit deb635249c04efee269e9407c48de6af92361ad9 Author: Michael Meissner <meiss...@linux.ibm.com> Date: Sat Nov 16 02:14:19 2024 -0500 Add potential p-future XVRLD and XVRLDI instructions. 2024-11-16 Michael Meissner <meiss...@linux.ibm.com> gcc/ * config/rs6000/altivec.md (altivec_vrl<VI_char>): Add support for a possible XVRLD instruction in the future. (altivec_vrl<VI_char>_immediate): New insns. * config/rs6000/predicates.md (vector_shift_immediate): New predicate. * config/rs6000/rs6000.h (TARGET_XVRLW): New macro. * config/rs6000/rs6000.md (isa attribute): Add xvrlw. (enabled attribute): Add support for xvrlw. gcc/testsuite/ * lib/target-supports.exp (check_effective_target_powerpc_future_ok): New target. (check_effective_target_powerpc_dense_math_ok): Likewise. * gcc.target/powerpc/vector-rotate-left.c: New test. Diff: --- gcc/config/rs6000/altivec.md | 35 +++++++++++++++++++++++++++++++---- gcc/config/rs6000/predicates.md | 26 ++++++++++++++++++++++++++ gcc/config/rs6000/rs6000.h | 3 +++ gcc/config/rs6000/rs6000.md | 6 +++++- gcc/testsuite/lib/target-supports.exp | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 5 deletions(-) diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md index 00dad4b91f1c..d4ee50322ca1 100644 --- a/gcc/config/rs6000/altivec.md +++ b/gcc/config/rs6000/altivec.md @@ -1983,12 +1983,39 @@ } [(set_attr "type" "vecperm")]) +;; -mcpu=future adds a vector rotate left word variant. There is no vector +;; byte/half-word/double-word/quad-word rotate left. This insn occurs before +;; altivec_vrl<VI_char> and will match for -mcpu=future, while other cpus will +;; match the generic insn. +;; However for testing, allow other xvrl variants. In particular, XVRLD for +;; the sha3 tests for multibuf/singlebuf. (define_insn "altivec_vrl<VI_char>" - [(set (match_operand:VI2 0 "register_operand" "=v") - (rotate:VI2 (match_operand:VI2 1 "register_operand" "v") - (match_operand:VI2 2 "register_operand" "v")))] + [(set (match_operand:VI2 0 "register_operand" "=v,wa") + (rotate:VI2 (match_operand:VI2 1 "register_operand" "v,wa") + (match_operand:VI2 2 "register_operand" "v,wa")))] "<VI_unit>" - "vrl<VI_char> %0,%1,%2" + "@ + vrl<VI_char> %0,%1,%2 + xvrl<VI_char> %x0,%x1,%x2" + [(set_attr "type" "vecsimple") + (set_attr "isa" "*,xvrlw")]) + +(define_insn "*altivec_vrl<VI_char>_immediate" + [(set (match_operand:VI2 0 "register_operand" "=wa,wa,wa,wa") + (rotate:VI2 (match_operand:VI2 1 "register_operand" "wa,wa,wa,wa") + (match_operand:VI2 2 "vector_shift_immediate" "j,wM,wE,wS")))] + "TARGET_XVRLW && <VI_unit>" +{ + rtx op2 = operands[2]; + int value = 256; + int num_insns = -1; + + if (!xxspltib_constant_p (op2, <MODE>mode, &num_insns, &value)) + gcc_unreachable (); + + operands[3] = GEN_INT (value & 0xff); + return "xvrl<VI_char>i %x0,%x1,%3"; +} [(set_attr "type" "vecsimple")]) (define_insn "altivec_vrlq" diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md index 1d95e34557e5..fccfbd7e4904 100644 --- a/gcc/config/rs6000/predicates.md +++ b/gcc/config/rs6000/predicates.md @@ -728,6 +728,32 @@ return num_insns == 1; }) +;; Return 1 if the operand is a CONST_VECTOR whose elements are all the +;; same and the elements can be an immediate shift or rotate factor +(define_predicate "vector_shift_immediate" + (match_code "const_vector,vec_duplicate,const_int") +{ + int value = 256; + int num_insns = -1; + + if (zero_constant (op, mode) || all_ones_constant (op, mode)) + return true; + + if (!xxspltib_constant_p (op, mode, &num_insns, &value)) + return false; + + switch (mode) + { + case V16QImode: return IN_RANGE (value, 0, 7); + case V8HImode: return IN_RANGE (value, 0, 15); + case V4SImode: return IN_RANGE (value, 0, 31); + case V2DImode: return IN_RANGE (value, 0, 63); + default: break; + } + + return false; +}) + ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a ;; vector register without using memory. (define_predicate "easy_vector_constant" diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h index f95318dd5536..576c7ae66bb4 100644 --- a/gcc/config/rs6000/rs6000.h +++ b/gcc/config/rs6000/rs6000.h @@ -578,6 +578,9 @@ extern int rs6000_vector_align[]; below. */ #define RS6000_FN_TARGET_INFO_HTM 1 +/* Whether we have XVRLW support. */ +#define TARGET_XVRLW TARGET_FUTURE + /* Whether the various reciprocal divide/square root estimate instructions exist, and whether we should automatically generate code for the instruction by default. */ diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index 6a2268f9e044..62b45a6bd613 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -369,7 +369,7 @@ (const (symbol_ref "(enum attr_cpu) rs6000_tune"))) ;; The ISA we implement. -(define_attr "isa" "any,p5,p6,p7,p7v,p8,p8v,p9,p9v,p9kf,p9tf,p10,xxeval" +(define_attr "isa" "any,p5,p6,p7,p7v,p8,p8v,p9,p9v,p9kf,p9tf,p10,xxeval,xvrlw" (const_string "any")) ;; Is this alternative enabled for the current CPU/ISA/etc.? @@ -426,6 +426,10 @@ (match_test "TARGET_PREFIXED && TARGET_XXEVAL")) (const_int 1) + (and (eq_attr "isa" "xvrlw") + (match_test "TARGET_XVRLW")) + (const_int 1) + ] (const_int 0))) ;; If this instruction is microcoded on the CELL processor diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index fd58682cae3b..e2504886d86b 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -7402,6 +7402,41 @@ proc check_effective_target_power10_ok { } { } } +# Return 1 if this is a PowerPC target supporting -mcpu=future which enables +# some potential new instructions. +proc check_effective_target_powerpc_future_ok { } { + return [check_no_compiler_messages powerpc_future_ok object { + #ifndef _ARCH_PWR_FUTURE + #error "-mcpu=future is not supported" + #else + int dummy; + #endif + } "-mcpu=future"] +} + +# Return 1 if this is a PowerPC target supporting -mcpu=future which enables +# the dense math operations. +proc check_effective_target_powerpc_dense_math_ok { } { + if { ([istarget powerpc*-*-*]) } { + return [check_no_compiler_messages powerpc_dense_math_ok object { + __vector_quad vq; + int main (void) { + #ifndef __DENSE_MATH__ + #error "target does not have dense math support." + #else + /* Make sure we have dense math support. */ + __vector_quad dmr; + __asm__ ("dmsetaccz %A0" : "=wD" (dmr)); + vq = dmr; + #endif + return 0; + } + } "-mcpu=future"] + } else { + return 0; + } +} + # Return 1 if this is a PowerPC target supporting -mfloat128 via either # software emulation on power7/power8 systems or hardware support on power9.