From: Richard Biener Date: Fri, 18 Sep 2020 11:36:24 +0000 (+0200) Subject: tree-optimization/97081 - fix wrong-code with vectorized shift X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9c9b88fdcff3520b2c4fb520c5d3b422eaa9a72f;p=gcc.git tree-optimization/97081 - fix wrong-code with vectorized shift This corrects the mask for creation of x << s | x >> (-x & mask) from a rotate x < PR tree-optimization/97081 * tree-vect-patterns.c (vect_recog_rotate_pattern): Use the precision of the shifted operand to determine the mask. * gcc.dg/vect/pr97081.c: New testcase. --- diff --git a/gcc/testsuite/gcc.dg/vect/pr97081.c b/gcc/testsuite/gcc.dg/vect/pr97081.c new file mode 100644 index 00000000000..bc83c88c019 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr97081.c @@ -0,0 +1,26 @@ +#include "tree-vect.h" + +#define EXEC_ROR2(a, b, sz) (a >> b) | (a << (64 - b)) + +#define TYPE __UINT64_TYPE__ + +void __attribute__((noipa)) +exec_VRORudi_i(TYPE *__restrict__ pvd, + TYPE *__restrict__ const pva, unsigned char IMM) +{ + unsigned char I2 = IMM & 63; + + for (unsigned i = 0; i < 4; i++) + pvd[i] = EXEC_ROR2(pva[i], I2, 8); +} + +int main() +{ + check_vect (); + + TYPE pvd[4], pva[4] = { 0x0102030405060708, 0x0102030405060708, 0x0102030405060708, 0x0102030405060708 }; + exec_VRORudi_i (pvd, pva, 7); + if (pvd[0] != 0x10020406080a0c0e) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c index 478a45a2281..db45740da3c 100644 --- a/gcc/tree-vect-patterns.c +++ b/gcc/tree-vect-patterns.c @@ -2456,7 +2456,6 @@ vect_recog_rotate_pattern (vec_info *vinfo, append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt); } stype = TREE_TYPE (def); - scalar_int_mode smode = SCALAR_INT_TYPE_MODE (stype); if (TREE_CODE (def) == INTEGER_CST) { @@ -2485,7 +2484,7 @@ vect_recog_rotate_pattern (vec_info *vinfo, append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, vecstype); def2 = vect_recog_temp_ssa_var (stype, NULL); - tree mask = build_int_cst (stype, GET_MODE_PRECISION (smode) - 1); + tree mask = build_int_cst (stype, GET_MODE_PRECISION (mode) - 1); def_stmt = gimple_build_assign (def2, BIT_AND_EXPR, gimple_assign_lhs (def_stmt), mask); if (ext_def)