[Bug tree-optimization/112472] New: (trunc)copysign((extend)x, CST) is not optimized to just copysign(x, CST')
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Nov 10 04:16:50 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112472
Bug ID: 112472
Summary: (trunc)copysign((extend)x, CST) is not optimized to
just copysign(x, CST')
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
float f(float a, float b)
{
return (float)__builtin_copysign(a,-3.0);
}
```
This should be optimized to just:
```
_tmp = .COPYSIGN(a, -1.0)
return _tmp;
```
The pattern for that does this for the non-constant second argument case is:
```
/* Simplify (trunc)copysign ((extend)x, (extend)y) to copysignf (x, y),
x,y is float value, similar for _Float16/double. */
(for copysigns (COPYSIGN_ALL)
(simplify
(convert (copysigns (convert@2 @0) (convert @1)))
(if (optimize
&& !HONOR_SNANS (@2)
&& types_match (type, TREE_TYPE (@0))
&& types_match (type, TREE_TYPE (@1))
&& TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2))
&& direct_internal_fn_supported_p (IFN_COPYSIGN,
type, OPTIMIZE_FOR_BOTH))
(IFN_COPYSIGN @0 @1))))
```
We should be able to handle (convert @1) as a constant ...
More information about the Gcc-bugs
mailing list