Skip to content

math.erfc fails compilation on CPU #20164

Open

Description

@bjacob

Testcase:

func.func @test_exp2_f16() -> () {
  %input = util.unfoldable_constant dense<[-1.0]> : tensor<1xf16>
  %result_empty = tensor.empty() : tensor<1xf16>
  %result = linalg.generic {indexing_maps = [
      affine_map<(d0) -> (d0)>,
      affine_map<(d0) -> (d0)>
    ], iterator_types = ["parallel"]}
    ins(%input : tensor<1xf16>) outs(%result_empty : tensor<1xf16>) {
  ^bb0(%in: f16, %out: f16):
    %x = math.erfc %in : f16
    linalg.yield %x : f16
  } -> tensor<1xf16>
  check.expect_almost_eq_const(%result,   dense<[0.5]> : tensor<1xf16>) :  tensor<1xf16>
  return
}

Repro:

iree-compile --iree-hal-target-device=llvm-cpu --iree-llvmcpu-target-cpu=generic ~/a.mlir -o ~/a.vmfb

Result:

// -----// IR Dump Before ConvertToLLVMPass (iree-convert-to-llvm) //----- //
module {
  func.func @_test_exp2_f16_dispatch_0_elementwise() {
    %c0 = arith.constant 0 : index
    %0 = hal.interface.binding.subspan layout(<bindings = [#hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, Indirect>], flags = Indirect>) binding(0) alignment(64) offset(%c0) flags("ReadOnly|Indirect") : memref<f16>
    memref.assume_alignment %0, 64 : memref<f16>
    %1 = hal.interface.binding.subspan layout(<bindings = [#hal.pipeline.binding<storage_buffer, "ReadOnly|Indirect">, #hal.pipeline.binding<storage_buffer, Indirect>], flags = Indirect>) binding(1) alignment(64) offset(%c0) flags(Indirect) : memref<f16>
    memref.assume_alignment %1, 64 : memref<f16>
    %2 = memref.load %0[] : memref<f16>
    %3 = math.erfc %2 : f16
    memref.store %3, %1[] : memref<f16>
    return
  }
}

/home/benjacob/a.mlir:10:10: error: failed to legalize operation 'math.erfc' that was explicitly marked illegal
    %x = math.erfc %in : f16

Activity

  1. added
    codegen/llvm
    on Mar 5, 2025
  2. bjacob commented on Mar 5, 2025

    @bjacob
    CollaboratorAuthor

    Note this issue is about erfc, not erf.
    erfc is a recent addition to the math dialect.
    Also there is no erfc.c file under https://github.com/powderluv/musl/tree/main/src/math

  3. added a commit that references this issue on Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegen/llvm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions