aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vect-patterns.c
diff options
context:
space:
mode:
authorKewen Lin <linkw@linux.ibm.com>2021-07-27 22:04:22 -0500
committerKewen Lin <linkw@linux.ibm.com>2021-07-27 22:04:22 -0500
commit89b3c97eed75c1e7c492bc727e0016003c5809cc (patch)
tree36b6702f3296a3dd1bbaccabde196cd61d1955f6 /gcc/tree-vect-patterns.c
parent872da9a6f664a06d73c987aa0cb2e5b830158a10 (diff)
downloadgcc-89b3c97eed75c1e7c492bc727e0016003c5809cc.zip
gcc-89b3c97eed75c1e7c492bc727e0016003c5809cc.tar.gz
gcc-89b3c97eed75c1e7c492bc727e0016003c5809cc.tar.bz2
vect: Fix wrong check in vect_recog_mulhs_pattern [PR101596]
As PR101596 showed, vect_recog_mulhs_pattern uses target_precision to check the scale_term is expected or not, it could be wrong when the precision of the actual used new_type larger than target_precision as shown by the example. This patch is to use precision of new_type instead of target_precision for the scale_term matching check. Bootstrapped & regtested on powerpc64le-linux-gnu P10, powerpc64-linux-gnu P8, x86_64-redhat-linux and aarch64-linux-gnu. gcc/ChangeLog: PR tree-optimization/101596 * tree-vect-patterns.c (vect_recog_mulhs_pattern): Fix wrong check by using new_type's precision instead. gcc/testsuite/ChangeLog: PR tree-optimization/101596 * gcc.target/powerpc/pr101596-1.c: New test. * gcc.target/powerpc/pr101596-2.c: Likewise. * gcc.target/powerpc/pr101596-3.c: Likewise.
Diffstat (limited to 'gcc/tree-vect-patterns.c')
-rw-r--r--gcc/tree-vect-patterns.c63
1 files changed, 36 insertions, 27 deletions
diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index 70bb751..743fd3f 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -1986,7 +1986,7 @@ vect_recog_mulhs_pattern (vec_info *vinfo,
stmt_vec_info mulh_stmt_info;
tree scale_term;
- internal_fn ifn;
+ bool rounding_p = false;
/* Check for the presence of the rounding term. */
if (gimple_assign_rhs_code (rshift_input_stmt) == PLUS_EXPR)
@@ -2035,37 +2035,18 @@ vect_recog_mulhs_pattern (vec_info *vinfo,
/* Get the scaling term. */
scale_term = gimple_assign_rhs2 (plus_input_stmt);
- /* Check that the scaling factor is correct. */
- if (TREE_CODE (scale_term) != INTEGER_CST)
- return NULL;
-
- /* Check pattern 2). */
- if (wi::to_widest (scale_term) + target_precision + 2
- != TYPE_PRECISION (lhs_type))
- return NULL;
-
- ifn = IFN_MULHRS;
+ rounding_p = true;
}
else
{
mulh_stmt_info = rshift_input_stmt_info;
scale_term = gimple_assign_rhs2 (last_stmt);
- /* Check that the scaling factor is correct. */
- if (TREE_CODE (scale_term) != INTEGER_CST)
- return NULL;
-
- /* Check for pattern 1). */
- if (wi::to_widest (scale_term) + target_precision + 1
- == TYPE_PRECISION (lhs_type))
- ifn = IFN_MULHS;
- /* Check for pattern 3). */
- else if (wi::to_widest (scale_term) + target_precision
- == TYPE_PRECISION (lhs_type))
- ifn = IFN_MULH;
- else
- return NULL;
}
+ /* Check that the scaling factor is constant. */
+ if (TREE_CODE (scale_term) != INTEGER_CST)
+ return NULL;
+
/* Check whether the scaling input term can be seen as two widened
inputs multiplied together. */
vect_unpromoted_value unprom_mult[2];
@@ -2076,13 +2057,41 @@ vect_recog_mulhs_pattern (vec_info *vinfo,
if (nops != 2)
return NULL;
- vect_pattern_detected ("vect_recog_mulhs_pattern", last_stmt);
-
/* Adjust output precision. */
if (TYPE_PRECISION (new_type) < target_precision)
new_type = build_nonstandard_integer_type
(target_precision, TYPE_UNSIGNED (new_type));
+ unsigned mult_precision = TYPE_PRECISION (new_type);
+ internal_fn ifn;
+ /* Check that the scaling factor is expected. Instead of
+ target_precision, we should use the one that we actually
+ use for internal function. */
+ if (rounding_p)
+ {
+ /* Check pattern 2). */
+ if (wi::to_widest (scale_term) + mult_precision + 2
+ != TYPE_PRECISION (lhs_type))
+ return NULL;
+
+ ifn = IFN_MULHRS;
+ }
+ else
+ {
+ /* Check for pattern 1). */
+ if (wi::to_widest (scale_term) + mult_precision + 1
+ == TYPE_PRECISION (lhs_type))
+ ifn = IFN_MULHS;
+ /* Check for pattern 3). */
+ else if (wi::to_widest (scale_term) + mult_precision
+ == TYPE_PRECISION (lhs_type))
+ ifn = IFN_MULH;
+ else
+ return NULL;
+ }
+
+ vect_pattern_detected ("vect_recog_mulhs_pattern", last_stmt);
+
/* Check for target support. */
tree new_vectype = get_vectype_for_scalar_type (vinfo, new_type);
if (!new_vectype