Skip to content

handling trigonometric function under "-ffast-math" #61617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
k-arrows opened this issue Mar 22, 2023 · 3 comments
Closed

handling trigonometric function under "-ffast-math" #61617

k-arrows opened this issue Mar 22, 2023 · 3 comments
Labels
duplicate Resolved as duplicate llvm:instcombine

Comments

@k-arrows
Copy link

k-arrows commented Mar 22, 2023

Consider the following code under -ffast-math.

#include <math.h>

float f1(float x)
{
    return tanf(x) * cosf(x);
}

float f2(float x)
{
    return sinf(x) / tanf(x);
}

GCC

f1:
        b       sinf
f2:
        b       cosf

Clang

f1:                                     // @f1
        stp     d9, d8, [sp, #-32]!             // 16-byte Folded Spill
        stp     x29, x30, [sp, #16]             // 16-byte Folded Spill
        add     x29, sp, #16
        fmov    s8, s0
        bl      tanf
        fmov    s9, s0
        fmov    s0, s8
        bl      cosf
        fmul    s0, s9, s0
        ldp     x29, x30, [sp, #16]             // 16-byte Folded Reload
        ldp     d9, d8, [sp], #32               // 16-byte Folded Reload
        ret
f2:                                     // @f2
        stp     d9, d8, [sp, #-32]!             // 16-byte Folded Spill
        stp     x29, x30, [sp, #16]             // 16-byte Folded Spill
        add     x29, sp, #16
        fmov    s8, s0
        bl      sinf
        fmov    s9, s0
        fmov    s0, s8
        bl      tanf
        fdiv    s0, s9, s0
        ldp     x29, x30, [sp, #16]             // 16-byte Folded Reload
        ldp     d9, d8, [sp], #32               // 16-byte Folded Reload
        ret

https://godbolt.org/z/Kf9r1aPj7

This difference is not specific to AArch64.

@RKSimon
Copy link
Collaborator

RKSimon commented Mar 22, 2023

We do a few trig combines already (see InstCombinerImpl::visitFDiv), but we're missing a Intrinsic::tan which should be dealt with first

@RKSimon
Copy link
Collaborator

RKSimon commented Mar 22, 2023

See: Issue #34950

@k-arrows
Copy link
Author

Thank you for your explanation. I understand that this issue is a duplicate.

@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Mar 22, 2023
@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Resolved as duplicate llvm:instcombine
Projects
None yet
Development

No branches or pull requests

3 participants