Skip to content

[codegen] Compile copysign more optimally #1074

@lattner

Description

@lattner
Bugzilla Link 702
Resolution FIXED
Resolved on Feb 22, 2010 12:55
Version 1.0
OS All

Extended Description

It would be nice to add:

  1. an llvm intrinsic (llvm.copysign.f32/f64), that represents copysign[f] when negative zeros
    and SNANs are not important (basically -ffast-math), the CFE could generate this.
  2. a selectiondag node to represent the same condition, also when UnsafeFPMath is enabled.

Then the legalizer can turn copysign into either 1) stores to mem followed by bitfield stuff and a load,
or 2) fabs/fneg/setcc/select if the target has them.

With this, the PPC backend would codegen copysign as:

copysign(x, y) {
fabs xPos, x
fnabs xNeg, x
fsel x, y, xPos, xNeg
return x;
}

which is nice and fast. X86/SSE has a similar lowering, but it would be custom lowered.

This is important for codes that use the FORTRAN copysign intrinsic or the C99 copysign functions
heavily.

-Chris

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions