Skip to content
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

Loading/storing float/double on 32-bit x86 without SSE can cause the value to mutate #89791

Closed
beetrees opened this issue Apr 23, 2024 · 2 comments
Labels
backend:X86 duplicate Resolved as duplicate

Comments

@beetrees
Copy link
Contributor

In LLVM IR, it is valid to transform

%x = load i32, ptr %0
store i32 %x, ptr %1

into

%x = load float, ptr %0
store float %x, ptr %1

(alive2)

However, the 32-bit x86 backend will (when SSE is disabled) miscompile the second example:

fld     dword ptr [ecx]
fstp    dword ptr [eax]

(comparison)

This is a miscompilation as the fld/fstp instructions will convert bit patterns that are signalling NaNs to quiet NaNs (e.g. 0xff800001 -> 0xffc00001).

This can cause miscompilations like this one, where the optimiser replaced an integer load/store with a float load/store, ultimately resulting in a segfault.

Related to #44218.

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 23, 2024

@llvm/issue-subscribers-backend-x86

Author: None (beetrees)

In LLVM IR, it is valid to transform ```llvm %x = load i32, ptr %0 store i32 %x, ptr %1 ```

into

%x = load float, ptr %0
store float %x, ptr %1

(alive2)

However, the 32-bit x86 backend will (when SSE is disabled) miscompile the second example:

fld     dword ptr [ecx]
fstp    dword ptr [eax]

(comparison)

This is a miscompilation as the fld/fstp instructions will convert bit patterns that are signalling NaNs to quiet NaNs (e.g. 0xff800001 -> 0xffc00001).

This can cause miscompilations like this one, where the optimiser replaced an integer load/store with a float load/store, ultimately resulting in a segfault.

Related to #44218.

@efriedma-quic
Copy link
Collaborator

Duplicate of #44497

@efriedma-quic efriedma-quic marked this as a duplicate of #44497 Apr 24, 2024
@efriedma-quic efriedma-quic closed this as not planned Won't fix, can't repro, duplicate, stale Apr 24, 2024
@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants