Bug 109843 - signbit comparisons -> copysign optimization
Summary: signbit comparisons -> copysign optimization
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 14.0
: P3 enhancement
Target Milestone: ---
Assignee: Andrew Pinski
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2023-05-13 16:45 UTC by Andrew Pinski
Modified: 2023-11-09 04:24 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-11-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2023-05-13 16:45:57 UTC
float copysign1(float  x, float y)
{
        bool t = __builtin_signbit(x) == 0;
        bool t1 = __builtin_signbit(y) == 0;
        return (t == t1) ? y : -y;
}
float copysign2(float  x, float y)
{
        bool t = __builtin_signbit(x) != 0;
        bool t1 = __builtin_signbit(y) != 0;
        return (t == t1) ? y : -y;
}
float copysign3(float  x, float y)
{
        bool t = __builtin_signbit(x) != 0;
        bool t1 = __builtin_signbit(y) == 0;
        return (t != t1) ? y : -y;
}
float copysign4(float  x, float y)
{
        bool t = __builtin_signbit(x) == 0;
        bool t1 = __builtin_signbit(y) != 0;
        return (t != t1) ? y : -y;
}
float copysign5(float  x, float y)
{
        return __builtin_copysignf(x, y);
}

These all should end up being the same code.
Hopefully I didn't mess these up.
Comment 1 Andrew Pinski 2023-11-09 04:24:59 UTC
Mine.