Skip to content

Certain simd math operations imply fast-math, but operation naming does not make it apparent #84268

Closed
@calebzulawski

Description

@calebzulawski

In the following, is_infinite is optimized to always return zero, but it should instead perform fabs and cmp:

#![feature(platform_intrinsics, repr_simd)]

extern "platform-intrinsic" {
    fn simd_fabs<T>(x: T) -> T;
    fn simd_eq<T, U>(x: T, y: T) -> U;
}

#[repr(simd)]
pub struct V([f32; 4]);

#[repr(simd)]
pub struct M([i32; 4]);

pub fn is_infinite(v: V) -> M {
    unsafe {
        simd_eq(simd_fabs(v), V([f32::INFINITY; 4]))
    }
}

It works correctly in debug, and fails in release.

Playground link: https://play.rust-lang.org/?version=nightly&mode=release&edition=2018&gist=49b790d5e14139e6bea9e57b0ae381d5

The problem is related to simd_fabs, because in stdsimd we are currently using simd_xor instead of simd_fabs and that optimizes correctly.

Meta

rustc --version --verbose:

rustc 1.53.0-nightly (b0c818c5e 2021-04-16)
binary: rustc
commit-hash: b0c818c5e0fa37251d9fda2f656bf1041a2e1e1d
commit-date: 2021-04-16
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

Metadata

Metadata

Assignees

Labels

A-SIMDArea: SIMD (Single Instruction Multiple Data)A-codegenArea: Code generationC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions