diff options
author | Richard Sandiford <richard.sandiford@linaro.org> | 2017-09-05 19:57:28 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@gcc.gnu.org> | 2017-09-05 19:57:28 +0000 |
commit | ddc203a7b15306287792a3eed6abfe306e3d26ad (patch) | |
tree | 70d42d6bad62e909cc47a2cbfc83768e6d71f952 | |
parent | 61b2290a5c248efd43dd45b1b256e7f792f21f02 (diff) | |
download | gcc-ddc203a7b15306287792a3eed6abfe306e3d26ad.zip gcc-ddc203a7b15306287792a3eed6abfe306e3d26ad.tar.gz gcc-ddc203a7b15306287792a3eed6abfe306e3d26ad.tar.bz2 |
Add mode_for_int_vector helper functions
There are at least a few places that want to create an integer vector
with a specified element size and element count, or to create the
integer equivalent of an existing mode. This patch adds helpers
for doing that.
The require ()s are all used in functions that go on to emit
instructions that use the result as a vector mode.
2017-09-05 Richard Sandiford <richard.sandiford@linaro.org>
gcc/
* machmode.h (mode_for_int_vector): New function.
* stor-layout.c (mode_for_int_vector): Likewise.
* config/aarch64/aarch64.c (aarch64_emit_approx_sqrt): Use it.
* config/powerpcspe/powerpcspe.c (rs6000_do_expand_vec_perm): Likewise.
* config/rs6000/rs6000.c (rs6000_do_expand_vec_perm): Likewise.
* config/s390/s390.c (s390_expand_vec_compare_cc): Likewise.
(s390_expand_vcond): Likewise.
From-SVN: r251729
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/config/aarch64/aarch64.c | 5 | ||||
-rw-r--r-- | gcc/config/powerpcspe/powerpcspe.c | 3 | ||||
-rw-r--r-- | gcc/config/rs6000/rs6000.c | 3 | ||||
-rw-r--r-- | gcc/config/s390/s390.c | 9 | ||||
-rw-r--r-- | gcc/machmode.h | 15 | ||||
-rw-r--r-- | gcc/stor-layout.c | 17 |
7 files changed, 47 insertions, 15 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4a7f676..03f690f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,15 @@ 2017-09-05 Richard Sandiford <richard.sandiford@linaro.org> + * machmode.h (mode_for_int_vector): New function. + * stor-layout.c (mode_for_int_vector): Likewise. + * config/aarch64/aarch64.c (aarch64_emit_approx_sqrt): Use it. + * config/powerpcspe/powerpcspe.c (rs6000_do_expand_vec_perm): Likewise. + * config/rs6000/rs6000.c (rs6000_do_expand_vec_perm): Likewise. + * config/s390/s390.c (s390_expand_vec_compare_cc): Likewise. + (s390_expand_vcond): Likewise. + +2017-09-05 Richard Sandiford <richard.sandiford@linaro.org> + * machmode.h (opt_machine_mode): New type. (opt_mode<T>): Allow construction from anything that can be converted to a T. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index d766307..2a5a075 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -8282,9 +8282,6 @@ aarch64_emit_approx_sqrt (rtx dst, rtx src, bool recp) return false; } - machine_mode mmsk - = mode_for_vector (int_mode_for_mode (GET_MODE_INNER (mode)).require (), - GET_MODE_NUNITS (mode)); if (!recp) { if (!(flag_mlow_precision_sqrt @@ -8302,7 +8299,7 @@ aarch64_emit_approx_sqrt (rtx dst, rtx src, bool recp) /* Caller assumes we cannot fail. */ gcc_assert (use_rsqrt_p (mode)); - + machine_mode mmsk = mode_for_int_vector (mode).require (); rtx xmsk = gen_reg_rtx (mmsk); if (!recp) /* When calculating the approximate square root, compare the diff --git a/gcc/config/powerpcspe/powerpcspe.c b/gcc/config/powerpcspe/powerpcspe.c index 9fd2d86..82c36de 100644 --- a/gcc/config/powerpcspe/powerpcspe.c +++ b/gcc/config/powerpcspe/powerpcspe.c @@ -38739,8 +38739,7 @@ rs6000_do_expand_vec_perm (rtx target, rtx op0, rtx op1, imode = vmode; if (GET_MODE_CLASS (vmode) != MODE_VECTOR_INT) - imode = mode_for_vector - (int_mode_for_mode (GET_MODE_INNER (vmode)).require (), nelt); + imode = mode_for_int_vector (vmode).require (); x = gen_rtx_CONST_VECTOR (imode, gen_rtvec_v (nelt, perm)); x = expand_vec_perm (vmode, op0, op1, x, target); diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 1a934ec..5f3d361 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -35584,8 +35584,7 @@ rs6000_do_expand_vec_perm (rtx target, rtx op0, rtx op1, imode = vmode; if (GET_MODE_CLASS (vmode) != MODE_VECTOR_INT) - imode = mode_for_vector - (int_mode_for_mode (GET_MODE_INNER (vmode)).require (), nelt); + imode = mode_for_int_vector (vmode).require (); x = gen_rtx_CONST_VECTOR (imode, gen_rtvec_v (nelt, perm)); x = expand_vec_perm (vmode, op0, op1, x, target); diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c index 3fd1ff6..36bc67d 100644 --- a/gcc/config/s390/s390.c +++ b/gcc/config/s390/s390.c @@ -6472,10 +6472,7 @@ s390_expand_vec_compare_cc (rtx target, enum rtx_code code, case LE: cc_producer_mode = CCVFHEmode; code = GE; swap_p = true; break; default: gcc_unreachable (); } - scratch_mode = mode_for_vector - (int_mode_for_mode (GET_MODE_INNER (GET_MODE (cmp1))).require (), - GET_MODE_NUNITS (GET_MODE (cmp1))); - gcc_assert (scratch_mode != BLKmode); + scratch_mode = mode_for_int_vector (GET_MODE (cmp1)).require (); if (inv_p) all_p = !all_p; @@ -6581,9 +6578,7 @@ s390_expand_vcond (rtx target, rtx then, rtx els, /* We always use an integral type vector to hold the comparison result. */ - result_mode = mode_for_vector - (int_mode_for_mode (GET_MODE_INNER (cmp_mode)).require (), - GET_MODE_NUNITS (cmp_mode)); + result_mode = mode_for_int_vector (cmp_mode).require (); result_target = gen_reg_rtx (result_mode); /* We allow vector immediates as comparison operands that diff --git a/gcc/machmode.h b/gcc/machmode.h index 956e2c0..7dd71e9 100644 --- a/gcc/machmode.h +++ b/gcc/machmode.h @@ -706,6 +706,21 @@ extern machine_mode bitwise_mode_for_mode (machine_mode); extern machine_mode mode_for_vector (scalar_mode, unsigned); +extern opt_machine_mode mode_for_int_vector (unsigned int, unsigned int); + +/* Return the integer vector equivalent of MODE, if one exists. In other + words, return the mode for an integer vector that has the same number + of bits as MODE and the same number of elements as MODE, with the + latter being 1 if MODE is scalar. The returned mode can be either + an integer mode or a vector mode. */ + +inline opt_machine_mode +mode_for_int_vector (machine_mode mode) +{ + return mode_for_int_vector (GET_MODE_UNIT_BITSIZE (mode), + GET_MODE_NUNITS (mode)); +} + /* A class for iterating through possible bitfield modes. */ class bit_field_mode_iterator { diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index f9a28e7..6bb7b24 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -517,6 +517,23 @@ mode_for_vector (scalar_mode innermode, unsigned nunits) return mode; } +/* Return the mode for a vector that has NUNITS integer elements of + INT_BITS bits each, if such a mode exists. The mode can be either + an integer mode or a vector mode. */ + +opt_machine_mode +mode_for_int_vector (unsigned int int_bits, unsigned int nunits) +{ + scalar_int_mode int_mode; + if (int_mode_for_size (int_bits, 0).exists (&int_mode)) + { + machine_mode vec_mode = mode_for_vector (int_mode, nunits); + if (vec_mode != BLKmode) + return vec_mode; + } + return opt_machine_mode (); +} + /* Return the alignment of MODE. This will be bounded by 1 and BIGGEST_ALIGNMENT. */ |