llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.04k stars 11.98k forks source link

`LLVM ERROR: Cannot select: t391: v16f32 = fp_extend t442` where ` t442: v16bf16` #64460

Closed joker-eph closed 1 year ago

joker-eph commented 1 year ago
LLVM ERROR: Cannot select: t391: v16f32 = fp_extend t442
  t442: v16bf16,ch = load<(load (s256) from %stack.1 + 32)> t438, t624, undef:i64
    t624: i64 = or FrameIndex:i64<1>, Constant:i64<32>
      t437: i64 = FrameIndex<1>
      t440: i64 = Constant<32>
    t15: i64 = undef
In function: dump_vec

Here is the input to SelectionDag from a debug log:

[LowerAMXTYpe][combineAMXcast] IR dump after optimizeAMXCastFromPhi:
define void @dump_vec(ptr %0) {
  %2 = call { ptr, ptr, i64, [1 x i64], [1 x i64] } @sparseValuesBF16(ptr %0)
  %3 = extractvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %2, 3, 0
  %4 = trunc i64 %3 to i32
  %5 = insertelement <32 x i32> undef, i32 %4, i32 0
  %6 = shufflevector <32 x i32> %5, <32 x i32> undef, <32 x i32> zeroinitializer
  %7 = icmp sgt <32 x i32> %6, <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
  %8 = extractvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %2, 1
  %9 = getelementptr bfloat, ptr %8, i64 0
  %10 = call <32 x bfloat> @llvm.masked.load.v32bf16.p0(ptr %9, i32 2, <32 x i1> %7, <32 x bfloat> <bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80, bfloat 0xRBF80>)
  %11 = fpext <32 x bfloat> %10 to <32 x float>
  call void @printOpen()
  %12 = extractelement <32 x float> %11, i64 0
  call void @printF32(float %12)
  call void @printComma()
  %13 = extractelement <32 x float> %11, i64 1
  call void @printF32(float %13)
  call void @printComma()
  %14 = extractelement <32 x float> %11, i64 2
  call void @printF32(float %14)
  call void @printComma()
  %15 = extractelement <32 x float> %11, i64 3
  call void @printF32(float %15)
  call void @printComma()
  %16 = extractelement <32 x float> %11, i64 4
  call void @printF32(float %16)
  call void @printComma()
  %17 = extractelement <32 x float> %11, i64 5
  call void @printF32(float %17)
  call void @printComma()
  %18 = extractelement <32 x float> %11, i64 6
  call void @printF32(float %18)
  call void @printComma()
  %19 = extractelement <32 x float> %11, i64 7
  call void @printF32(float %19)
  call void @printComma()
  %20 = extractelement <32 x float> %11, i64 8
  call void @printF32(float %20)
  call void @printComma()
  %21 = extractelement <32 x float> %11, i64 9
  call void @printF32(float %21)
  call void @printComma()
  %22 = extractelement <32 x float> %11, i64 10
  call void @printF32(float %22)
  call void @printComma()
  %23 = extractelement <32 x float> %11, i64 11
  call void @printF32(float %23)
  call void @printComma()
  %24 = extractelement <32 x float> %11, i64 12
  call void @printF32(float %24)
  call void @printComma()
  %25 = extractelement <32 x float> %11, i64 13
  call void @printF32(float %25)
  call void @printComma()
  %26 = extractelement <32 x float> %11, i64 14
  call void @printF32(float %26)
  call void @printComma()
  %27 = extractelement <32 x float> %11, i64 15
  call void @printF32(float %27)
  call void @printComma()
  %28 = extractelement <32 x float> %11, i64 16
  call void @printF32(float %28)
  call void @printComma()
  %29 = extractelement <32 x float> %11, i64 17
  call void @printF32(float %29)
  call void @printComma()
  %30 = extractelement <32 x float> %11, i64 18
  call void @printF32(float %30)
  call void @printComma()
  %31 = extractelement <32 x float> %11, i64 19
  call void @printF32(float %31)
  call void @printComma()
  %32 = extractelement <32 x float> %11, i64 20
  call void @printF32(float %32)
  call void @printComma()
  %33 = extractelement <32 x float> %11, i64 21
  call void @printF32(float %33)
  call void @printComma()
  %34 = extractelement <32 x float> %11, i64 22
  call void @printF32(float %34)
  call void @printComma()
  %35 = extractelement <32 x float> %11, i64 23
  call void @printF32(float %35)
  call void @printComma()
  %36 = extractelement <32 x float> %11, i64 24
  call void @printF32(float %36)
  call void @printComma()
  %37 = extractelement <32 x float> %11, i64 25
  call void @printF32(float %37)
  call void @printComma()
  %38 = extractelement <32 x float> %11, i64 26
  call void @printF32(float %38)
  call void @printComma()
  %39 = extractelement <32 x float> %11, i64 27
  call void @printF32(float %39)
  call void @printComma()
  %40 = extractelement <32 x float> %11, i64 28
  call void @printF32(float %40)
  call void @printComma()
  %41 = extractelement <32 x float> %11, i64 29
  call void @printF32(float %41)
  call void @printComma()
  %42 = extractelement <32 x float> %11, i64 30
  call void @printF32(float %42)
  call void @printComma()
  %43 = extractelement <32 x float> %11, i64 31
  call void @printF32(float %43)
  call void @printClose()
  call void @printNewline()
  ret void
}

Reproduce with the attached test running

bin/llc /tmp/test.ll  -mtriple=x86_64-unknown-linux-gnu   -mcpu="znver4"

test.ll.txt

joker-eph commented 1 year ago

Ping on this @phoebewang ? I think it'd be nice to fix it quickly and back port in 17.0.0

phoebewang commented 1 year ago

Sorry, busy on other tasks. Will try to solve it ASAP.

tru commented 1 year ago

What's the status on this issue? We are getting close to 17.x final, so it would be nice to know if we are still waiting for a issue fixed here.

phoebewang commented 1 year ago

I just root caused it but was stalled due to family issues. I'll back to it this week and hope solve it by EOW. I see the final date is Sep 5th. So think should be good to catch up with.

phoebewang commented 1 year ago

Candidate patch: https://reviews.llvm.org/D158950

llvmbot commented 1 year ago

@llvm/issue-subscribers-backend-x86

joker-eph commented 1 year ago

This fixes the crash, but somehow the test is providing incorrect result now:

llvm-project/mlir/test/Integration/Dialect/SparseTensor/CPU/dense_output_bf16.mlir:106:12: error: CHECK: expected string not found in input
 // CHECK: ( 1, 11, 0, 2, 13, 0, 0, 0, 0, 0, 14, 3, 0, 0, 0, 0, 15, 4, 16, 0, 5, 6, 0, 0, 0, 0, 0, 0, 7, 8, 0, 9 )
           ^
<stdin>:1:1: note: scanning from here
( 5.83155e-39, 5.98653e-39, 0, 5.87747e-39, 5.99801e-39, 0, 0, 0, 0, 0, 6.00375e-39, 5.90043e-39, 0, 0, 0, 0, 6.00949e-39, 5.92339e-39, 6.01522e-39, 0, 5.93487e-39, 5.94635e-39, 0, 0, 0, 0, 0, 0, 5.95783e-39, 5.96931e-39, 0, 5.97505e-39 )
^

Input file: <stdin>
Check file: llvm-project/mlir/test/Integration/Dialect/SparseTensor/CPU/dense_output_bf16.mlir

The result looks pretty far from what we expect

joker-eph commented 1 year ago

CC: @RKSimon since you reviewed here: https://reviews.llvm.org/D158950

phoebewang commented 1 year ago

I'll look at the new problem

phoebewang commented 1 year ago

@joker-eph could you help to have a quick check about changing 8 to 16 in the code below:

    In = DAG.getNode(ISD::ZERO_EXTEND, DL, NVT, In);
    In = DAG.getNode(ISD::SHL, DL, NVT, In, DAG.getConstant(8, DL, NVT));
    return DAG.getBitcast(VT, In);

I don't have a target with AVX512BF16 to verify it.

phoebewang commented 1 year ago

Checked changing to 16 solve the problem.

tru commented 1 year ago

Should this be backported.

phoebewang commented 1 year ago

Should this be backported.

This has been backported through #65032

joker-eph commented 1 year ago

It's fine it seems you cherry-picked the final commit @tru

tru commented 1 year ago

Ah it was a separate issue. Ok - thanks for confirming!