Skip to content

[mlir][Arith][LLVM] No fast math handling for extf and truncf #156692

@zero9178

Description

@zero9178

Given the following programs:

func.func @test1(%arg0: f32) -> bf16 {
    %0 = arith.truncf %arg0 fastmath<fast> : f32 to bf16
    return %0 : bf16
}

func.func @test2(%0: bf16) -> f32 {
    %1 = arith.extf %0 fastmath<fast> : bf16 to f32
    return %1 : f32
}

the convert-to-llvm pass produces the following IR:

module {
  llvm.func @test1(%arg0: f32) -> f32 {
    %0 = llvm.fptrunc %arg0 {fastmath = #arith.fastmath<fast>} : f32 to bf16
    llvm.return %arg0 : f32
  }
  llvm.func @test2(%arg0: bf16) -> f32 {
    %0 = llvm.fpext %arg0 {fastmath = #arith.fastmath<fast>} : bf16 to f32
    llvm.return %0 : f32
  }
}

https://godbolt.org/z/ahs6jaEaP

As can be seen in the output, the fastmath property is taken as is from arith and not translated to LLVMs fast math flags.
Part of the reason seems to be that fpext and fptrunc in the LLVM dialect do not support fast math flags at the moment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions