vect: Recog mul_highpart pattern [PR100696]
This patch is to extend the existing pattern mulhs handlings to cover normal multiply highpart pattern recognization, it introduces one new internal function IFN_MULH for 1:1 map to [su]mul_highpart optab. Since it covers MULT_HIGHPART_EXPR with optab support, i386 part change is to ensure it follows the consistent costing path. Bootstrapped & regtested on powerpc64le-linux-gnu P9, x86_64-redhat-linux and aarch64-linux-gnu. gcc/ChangeLog: PR tree-optimization/100696 * internal-fn.c (first_commutative_argument): Add info for IFN_MULH. * internal-fn.def (IFN_MULH): New internal function. * tree-vect-patterns.c (vect_recog_mulhs_pattern): Add support to recog normal multiply highpart as IFN_MULH. * config/i386/i386.c (ix86_add_stmt_cost): Adjust for combined function CFN_MULH. gcc/testsuite/ChangeLog: PR tree-optimization/100696 * gcc.target/i386/pr100637-3w.c: Adjust for mul_highpart recog.
This commit is contained in:
parent
21ea2f9320
commit
a1d2756077
5 changed files with 37 additions and 13 deletions
|
@ -22568,6 +22568,9 @@ ix86_add_stmt_cost (class vec_info *vinfo, void *data, int count,
|
|||
mode == SFmode ? ix86_cost->fmass
|
||||
: ix86_cost->fmasd);
|
||||
break;
|
||||
case CFN_MULH:
|
||||
stmt_cost = ix86_multiplication_cost (ix86_cost, mode);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -3703,6 +3703,7 @@ first_commutative_argument (internal_fn fn)
|
|||
case IFN_FNMS:
|
||||
case IFN_AVG_FLOOR:
|
||||
case IFN_AVG_CEIL:
|
||||
case IFN_MULH:
|
||||
case IFN_MULHS:
|
||||
case IFN_MULHRS:
|
||||
case IFN_FMIN:
|
||||
|
|
|
@ -169,6 +169,8 @@ DEF_INTERNAL_SIGNED_OPTAB_FN (AVG_FLOOR, ECF_CONST | ECF_NOTHROW, first,
|
|||
DEF_INTERNAL_SIGNED_OPTAB_FN (AVG_CEIL, ECF_CONST | ECF_NOTHROW, first,
|
||||
savg_ceil, uavg_ceil, binary)
|
||||
|
||||
DEF_INTERNAL_SIGNED_OPTAB_FN (MULH, ECF_CONST | ECF_NOTHROW, first,
|
||||
smul_highpart, umul_highpart, binary)
|
||||
DEF_INTERNAL_SIGNED_OPTAB_FN (MULHS, ECF_CONST | ECF_NOTHROW, first,
|
||||
smulhs, umulhs, binary)
|
||||
DEF_INTERNAL_SIGNED_OPTAB_FN (MULHRS, ECF_CONST | ECF_NOTHROW, first,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* PR target/100637 */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-O2 -ftree-vectorize -msse4" } */
|
||||
/* { dg-options "-O2 -ftree-vectorize -msse4 -fno-vect-cost-model" } */
|
||||
|
||||
short r[2], a[2], b[2];
|
||||
unsigned short ur[2], ua[2], ub[2];
|
||||
|
@ -13,7 +13,7 @@ void mulh (void)
|
|||
r[i] = ((int) a[i] * b[i]) >> 16;
|
||||
}
|
||||
|
||||
/* { dg-final { scan-assembler "pmulhw" { xfail *-*-* } } } */
|
||||
/* { dg-final { scan-assembler "pmulhw" } } */
|
||||
|
||||
void mulhu (void)
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ void mulhu (void)
|
|||
ur[i] = ((unsigned int) ua[i] * ub[i]) >> 16;
|
||||
}
|
||||
|
||||
/* { dg-final { scan-assembler "pmulhuw" { xfail *-*-* } } } */
|
||||
/* { dg-final { scan-assembler "pmulhuw" } } */
|
||||
|
||||
void mulhrs (void)
|
||||
{
|
||||
|
|
|
@ -1934,8 +1934,15 @@ vect_recog_over_widening_pattern (vec_info *vinfo,
|
|||
|
||||
1) Multiply high with scaling
|
||||
TYPE res = ((TYPE) a * (TYPE) b) >> c;
|
||||
Here, c is bitsize (TYPE) / 2 - 1.
|
||||
|
||||
2) ... or also with rounding
|
||||
TYPE res = (((TYPE) a * (TYPE) b) >> d + 1) >> 1;
|
||||
Here, d is bitsize (TYPE) / 2 - 2.
|
||||
|
||||
3) Normal multiply high
|
||||
TYPE res = ((TYPE) a * (TYPE) b) >> e;
|
||||
Here, e is bitsize (TYPE) / 2.
|
||||
|
||||
where only the bottom half of res is used. */
|
||||
|
||||
|
@ -1980,7 +1987,6 @@ vect_recog_mulhs_pattern (vec_info *vinfo,
|
|||
stmt_vec_info mulh_stmt_info;
|
||||
tree scale_term;
|
||||
internal_fn ifn;
|
||||
unsigned int expect_offset;
|
||||
|
||||
/* Check for the presence of the rounding term. */
|
||||
if (gimple_assign_rhs_code (rshift_input_stmt) == PLUS_EXPR)
|
||||
|
@ -2029,25 +2035,37 @@ 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;
|
||||
|
||||
expect_offset = target_precision + 2;
|
||||
ifn = IFN_MULHRS;
|
||||
}
|
||||
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;
|
||||
|
||||
expect_offset = target_precision + 1;
|
||||
ifn = IFN_MULHS;
|
||||
/* 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 correct. */
|
||||
if (TREE_CODE (scale_term) != INTEGER_CST
|
||||
|| wi::to_widest (scale_term) + expect_offset
|
||||
!= TYPE_PRECISION (lhs_type))
|
||||
return NULL;
|
||||
|
||||
/* Check whether the scaling input term can be seen as two widened
|
||||
inputs multiplied together. */
|
||||
vect_unpromoted_value unprom_mult[2];
|
||||
|
|
Loading…
Add table
Reference in a new issue