Bug 89386 - Generation of vectorized MULHRS (Multiply High with Round and Scale) instruction
Summary: Generation of vectorized MULHRS (Multiply High with Round and Scale) instruction
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 10.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: vectorizer
  Show dependency treegraph
 
Reported: 2019-02-18 10:47 UTC by Uroš Bizjak
Modified: 2020-05-19 10:50 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Uroš Bizjak 2019-02-18 10:47:43 UTC
This PR is similar to PR85693 and PR85694, where missing generation of vectorized SAD (Sum of Absolute Difference) and AVG (Average) instruction was reported.

Following code:

--cut here--
#define N 1024

unsigned short as[N], bs[N], cs[N];

void
foo_short (void)
{
  int i;

  for (i = 0; i < N; i++)
    as[i] = ((((int)bs[i] * (int)cs[i]) >> 14) + 1) >> 1;
}
--cut here--

should vectorize with pmulhrsw SSSE3 instruction.
Comment 1 rsandifo@gcc.gnu.org 2019-09-12 10:00:30 UTC
Author: rsandifo
Date: Thu Sep 12 09:59:58 2019
New Revision: 275682

URL: https://gcc.gnu.org/viewcvs?rev=275682&root=gcc&view=rev
Log:
Vectorise multiply high with scaling operations (PR 89386)

2019-09-12  Yuliang Wang  <yuliang.wang@arm.com>

gcc/
	PR tree-optimization/89386
	* config/aarch64/aarch64-sve2.md (<su>mull<bt><Vwide>)
	(<r>shrnb<mode>, <r>shrnt<mode>): New SVE2 patterns.
	(<su>mulh<r>s<mode>3): New pattern for MULHRS.
	* config/aarch64/iterators.md (UNSPEC_SMULLB, UNSPEC_SMULLT)
	(UNSPEC_UMULLB, UNSPEC_UMULLT, UNSPEC_SHRNB, UNSPEC_SHRNT)
	(UNSPEC_RSHRNB, UNSPEC_RSHRNT, UNSPEC_SMULHS, UNSPEC_SMULHRS)
	UNSPEC_UMULHS, UNSPEC_UMULHRS): New unspecs.
	(MULLBT, SHRNB, SHRNT, MULHRS): New int iterators.
	(su, r): Handle the unspecs above.
	(bt): New int attribute.
	* internal-fn.def (IFN_MULHS, IFN_MULHRS): New internal functions.
	* internal-fn.c (first_commutative_argument): Commutativity info for
	above.
	* optabs.def (smulhs_optab, smulhrs_optab, umulhs_optab)
	(umulhrs_optab): New optabs.
	* doc/md.texi (smulhs$var{m3}, umulhs$var{m3})
	(smulhrs$var{m3}, umulhrs$var{m3}): Documentation for the above.
	* tree-vect-patterns.c (vect_recog_mulhs_pattern): New pattern
	function.
	(vect_vect_recog_func_ptrs): Add it.
	* testsuite/gcc.target/aarch64/sve2/mulhrs_1.c: New test.
	* testsuite/gcc.dg/vect/vect-mulhrs-1.c: As above.
	* testsuite/gcc.dg/vect/vect-mulhrs-2.c: As above.
	* testsuite/gcc.dg/vect/vect-mulhrs-3.c: As above.
	* testsuite/gcc.dg/vect/vect-mulhrs-4.c: As above.
	* doc/sourcebuild.texi (vect_mulhrs_hi): Document new target selector.
	* testsuite/lib/target-supports.exp
	(check_effective_target_vect_mulhrs_hi): Return true for AArch64
	with SVE2.

Added:
    trunk/gcc/testsuite/gcc.dg/vect/vect-mulhrs-1.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-mulhrs-2.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-mulhrs-3.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-mulhrs-4.c
    trunk/gcc/testsuite/gcc.target/aarch64/sve2/mulhrs_1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/aarch64/aarch64-sve2.md
    trunk/gcc/config/aarch64/iterators.md
    trunk/gcc/doc/md.texi
    trunk/gcc/doc/sourcebuild.texi
    trunk/gcc/internal-fn.c
    trunk/gcc/internal-fn.def
    trunk/gcc/optabs.def
    trunk/gcc/testsuite/lib/target-supports.exp
    trunk/gcc/tree-vect-patterns.c
Comment 2 uros 2019-09-12 19:18:56 UTC
Author: uros
Date: Thu Sep 12 19:18:25 2019
New Revision: 275689

URL: https://gcc.gnu.org/viewcvs?rev=275689&root=gcc&view=rev
Log:
	PR tree-optimization/89386
	* config/i386/sse.md (smulhrs<mode>3): New expander.
	(smulhrsv4hi3): Ditto.

testsuite/ChangeLog:

	PR tree-optimization/89386
	* gcc.target/i386/pr89386.c: New test.
	* gcc.target/i386/pr89386-1.c: Ditto.


Added:
    trunk/gcc/testsuite/gcc.target/i386/pr89386-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr89386.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/sse.md
    trunk/gcc/testsuite/ChangeLog
Comment 3 Uroš Bizjak 2020-05-19 10:50:37 UTC
Fixed also for x86 targets.