[LLVMdev] some thoughts on the semantics of !fpmath

Duncan Sands baldrick at free.fr
Wed Apr 18 13:46:08 PDT 2012


Hi Dan,

>> I don't understand how it can not be safe: if the metadata is dropped
>> then the optimizers have to be more strict, thus it is safe.
>
> Here's an example:
>
>    %z = fadd float %x, %y, !fpmath !{ float 1000.0 }
>    %p = fcmp ogt %z, 0.0
>    br i1 %p, label %true, label %false
> true:
>    %d = call float @llvm.sqrt.f32(float %z)
>
> This ought to be safe, since no matter now imprecise the fadd is,
> the compare and branch protects the sqrt.
>
> Now suppose a metadata-unaware optimizer can do value-range analysis
> and can prove that the fadd always produces a positive finite value.

this just means that passes doing floating point value-range analysis
need to be metadata aware.

Ciao, Duncan.

> Then it's safe to replace the fcmp with true and delete the branch.
>
> Then a metadata-aware codegen translates the fadd with reduced
> precision, as permitted by the metadata. At runtime, the fadd may
> return a negative value sometimes, because that could well be within
> 1000.0 ULPs of an expected non-negative result. But the branch is
> now gone, and undefined behavior sqrts out.
>
> Dan
>




More information about the llvm-dev mailing list