]> git.ipfire.org Git - thirdparty/gcc.git/commit
middle-end: Don't apply copysign optimization if target does not implement optab...
authorTamar Christina <tamar.christina@arm.com>
Wed, 10 Jan 2024 17:18:28 +0000 (17:18 +0000)
committerTamar Christina <tamar.christina@arm.com>
Wed, 10 Jan 2024 17:19:02 +0000 (17:19 +0000)
commit7cbe41d35e6a60776484e04e42e408de9fc82954
tree6f1e9e741abf6ef8815b0405b30c8d24681d5e70
parent113475d03b0ab1ab18a509e8e5844c1a43983b24
middle-end: Don't apply copysign optimization if target does not implement optab [PR112468]

Currently GCC does not treat IFN_COPYSIGN the same as the copysign tree expr.
The latter has a libcall fallback and the IFN can only do optabs.

Because of this the change I made to optimize copysign only works if the
target has impemented the optab, but it should work for those that have the
libcall too.

More annoyingly if a target has vector versions of ABS and NEG but not COPYSIGN
then the change made them lose vectorization.

The proper fix for this is to treat the IFN the same as the tree EXPR and to
enhance expand_COPYSIGN to also support vector calls.

I have such a patch for GCC 15 but it's quite big and too invasive for stage-4.
As such this is a minimal fix, just don't apply the transformation and leave
targets which don't have the optab unoptimized.

Targets list for check_effective_target_ifn_copysign was gotten by grepping for
copysign and looking at the optab.

gcc/ChangeLog:

PR tree-optimization/112468
* doc/sourcebuild.texi: Document ifn_copysign.
* match.pd: Only apply transformation if target supports the IFN.

gcc/testsuite/ChangeLog:

PR tree-optimization/112468
* gcc.dg/fold-copysign-1.c: Modify tests based on if target supports
IFN_COPYSIGN.
* gcc.dg/pr55152-2.c: Likewise.
* gcc.dg/tree-ssa/abs-4.c: Likewise.
* gcc.dg/tree-ssa/backprop-6.c: Likewise.
* gcc.dg/tree-ssa/copy-sign-2.c: Likewise.
* gcc.dg/tree-ssa/mult-abs-2.c: Likewise.
* lib/target-supports.exp (check_effective_target_ifn_copysign): New.
gcc/doc/sourcebuild.texi
gcc/match.pd
gcc/testsuite/gcc.dg/fold-copysign-1.c
gcc/testsuite/gcc.dg/pr55152-2.c
gcc/testsuite/gcc.dg/tree-ssa/abs-4.c
gcc/testsuite/gcc.dg/tree-ssa/backprop-6.c
gcc/testsuite/gcc.dg/tree-ssa/copy-sign-2.c
gcc/testsuite/gcc.dg/tree-ssa/mult-abs-2.c
gcc/testsuite/lib/target-supports.exp