Skip to content

fetestexcept reordered with floating point operation #34581

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
llvmbot opened this issue Nov 7, 2017 · 3 comments
Closed

fetestexcept reordered with floating point operation #34581

llvmbot opened this issue Nov 7, 2017 · 3 comments
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category floating-point Floating-point math invalid Resolved as invalid, i.e. not a bug

Comments

@llvmbot
Copy link
Member

llvmbot commented Nov 7, 2017

Bugzilla Link 35233
Version 4.0
OS Linux
Attachments C++11 file exhibiting the bug
Reporter LLVM Bugzilla Contributor
CC @andykaylor,@hfinkel,@rotateright

Extended Description

A static_cast of a uint64_t to a double on Clang 4.0 and AArch64 is reordered with a fettestexcept, resulting in the wrong floating point state being tested.

Example output from GCC 6.0: https://godbolt.org/g/pbAW4J

Here's Clang's output:

oot@mcsema-aarch64:/remill# ../remill-build/libraries/llvm/bin/clang++ -std=c++11 -O3 -c /tmp/convert.cc -S -o /tmp/convert.S
root@mcsema-aarch64:
/remill# cat /tmp/convert.S
.text
.file "/tmp/convert.cc"
.globl _Z9to_doubleR5flagsm
.p2align 2
.type _Z9to_doubleR5flagsm,@function
_Z9to_doubleR5flagsm: // @​_Z9to_doubleR5flagsm
// BB#0:
stp x20, x19, [sp, #-32]! // 8-byte Folded Spill
mov x19, x0
orr w0, wzr, #​0x1f
stp x29, x30, [sp, #​16] // 8-byte Folded Spill
add x29, sp, #​16 // =16
mov x20, x1
bl feclearexcept
orr w0, wzr, #​0x1f
bl fetestexcept
tbz w0, #​4, .LBB0_2
// BB#1:
orr w8, wzr, #​0x1
str w8, [x19]
.LBB0_2:
tbz w0, #​2, .LBB0_4
// BB#3:
orr w8, wzr, #​0x1
str w8, [x19, #​4]
.LBB0_4:
tbz w0, #​3, .LBB0_6
// BB#5:
orr w8, wzr, #​0x1
str w8, [x19, #​8]
.LBB0_6:
ucvtf d0, x20
tbz w0, #​0, .LBB0_8
// BB#7:
orr w8, wzr, #​0x1
str w8, [x19, #​12]
.LBB0_8:
ldp x29, x30, [sp, #​16] // 8-byte Folded Reload
ldp x20, x19, [sp], #​32 // 8-byte Folded Reload
ret
.Lfunc_end0:
.size _Z9to_doubleR5flagsm, .Lfunc_end0-_Z9to_doubleR5flagsm

@llvmbot
Copy link
Member Author

llvmbot commented Nov 7, 2017

clang version 4.0.1 (https://github.com/llvm-mirror/clang.git 3c8961bedc65c9a15cbe67a2ef385a0938f7cfef) (https://github.com/llvm-mirror/llvm.git c8fccc53ed66d505898f8850bcc690c977a7c9a7)

@hfinkel
Copy link
Collaborator

hfinkel commented Nov 7, 2017

FWIW, Clang/LLVM currently don't support floating-point environment access. In C, you'd need to use #pragma STDC FENV_ACCESS ON, which we don't support.

There is active work in this area (e.g., to add a mode in which the optimizer respects fp-environment access).

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@arsenm arsenm added floating-point Floating-point math invalid Resolved as invalid, i.e. not a bug labels Aug 17, 2023
@arsenm
Copy link
Contributor

arsenm commented Aug 17, 2023

This requires FENV_ACCESS enabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category floating-point Floating-point math invalid Resolved as invalid, i.e. not a bug
Projects
None yet
Development

No branches or pull requests

3 participants