Bug 55180 - Missed optimization abs(-x) -> abs(x)
Summary: Missed optimization abs(-x) -> abs(x)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 5.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on: 16107
Blocks:
  Show dependency treegraph
 
Reported: 2012-11-02 14:55 UTC by Marc Glisse
Modified: 2014-12-01 04:28 UTC (History)
0 users

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 Marc Glisse 2012-11-02 14:55:45 UTC
double f(double x){
  double y=-x;
  return __builtin_fabs(y);
}

The negation doesn't disappear, even at -Ofast, I still see both "xor" and "and" in the asm. (I don't think this optimization requires any unsafe math option, but I am not completely sure about the trapping behavior)

Note that if I write __builtin_fabs(-x), the negation is removed before it has a chance to appear in a dump.
Comment 1 Andrew Pinski 2012-11-02 15:43:29 UTC
Related to or a dup of bug 16107.
Comment 2 Marc Glisse 2012-11-02 16:11:43 UTC
Thanks, I had missed that one. ABS_EXPR is a bit special in that it has its own tree code, instead of appearing as a call to a builtin function, but the issue is the same indeed, the optimization is there but can never be applied.

*** This bug has been marked as a duplicate of bug 16107 ***
Comment 3 Andrew Pinski 2014-12-01 04:27:58 UTC
Reopening since this is not a dup of that bug.
Comment 4 Andrew Pinski 2014-12-01 04:28:50 UTC
But it was fixed in GCC 5.0.