On 6/16/2026 12:08 AM, Eikansh Gupta wrote:
Add a pattern for `(trunc)copysign ((extend)x, CST)`. Only the sign of
CST matters, not its value, so it can be simplified to
`copysign (x, -1.0/1.0)` depending on the sign of CST.
PR tree-optimization/112472
gcc/ChangeLog:
* match.pd ((trunc)copysign ((extend)x, CST) --> copysign (x,
-1.0/1.0)):
New pattern.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr112472.c: New test.
Signed-off-by: Eikansh Gupta <[email protected]>
So rather than +-1.0, how about +-0.0. The advantage of using +-0.0 is
+0.0 and -0.0 can be synthesized trivially due to the form of their bit
patterns. So while we do improve on rv64 with your patch to this:
lui a5,%hi(.LC0)
flw fa5,%lo(.LC0)(a5)
fsgnj.s fa0,fa0,fa5
ret
Note how we pull the constant out of the constant pool. In theory with
an approved (but not yet committed) patch from Philip T. that would turn
into something like
bset a5, x0, 63
fmv.d.x fa5,a5
fsgnj.s fa0,fa0,fa5
ret
It's the same number of instructions, but does not hit memory, so it's
likely ~3c faster on most designs.
The only concern would be HONOR_SIGNED_ZEROS, but ISTM if that's off,
then use +-1.0.
Jeff