llvm / llvm-project

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

Legalization of `@llvm.vector.reduce.fmax.v4f32` unsupported for AMDGPU using global-isel #114816

Open tpopp opened 1 week ago

tpopp commented 1 week ago

Attempting to lower the following code snippet with global isel fails in legalization:llc -global-isel reduced.ll

target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
target triple = "amdgcn-amd-amdhsa"

define amdgpu_kernel void @"main$async_dispatch_19_softmax_16384x16384xf32_dispatch_tensor_store"() {
  %1 = call float @llvm.vector.reduce.fmax.v4f32(<4 x float> zeroinitializer)
  store float %1, ptr addrspace(3) null, align 4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.vector.reduce.fmax.v4f32(<4 x float>) #0

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
# *** IR Dump Before Legalizer (legalizer) ***:
# Machine code for function main$async_dispatch_19_softmax_16384x16384xf32_dispatch_tensor_store: IsSSA, TracksLiveness
Function Live Ins: $sgpr0_sgpr1_sgpr2_sgpr3 in %0, $sgpr4_sgpr5 in %1, $sgpr6_sgpr7 in %2, $sgpr8_sgpr9 in %3, $vgpr0 in %4, $vgpr1 in %5, $vgpr2 in %6, $sgpr10 in %7, $sgpr11 in %8, $sgpr12 in %9, $sgpr13 in %10

bb.1 (%ir-block.0):
  liveins: $sgpr6_sgpr7
  %12:_(s32) = G_FCONSTANT float 0.000000e+00
  %11:_(<4 x s32>) = G_BUILD_VECTOR %12:_(s32), %12:_(s32), %12:_(s32), %12:_(s32)
  %13:_(s32) = G_VECREDUCE_FMAX %11:_(<4 x s32>)
  %14:_(p3) = G_CONSTANT i32 0
  G_STORE %13:_(s32), %14:_(p3) :: (store (s32) into `ptr addrspace(3) null`, addrspace 3)
  S_ENDPGM 0

# End machine code for function main$async_dispatch_19_softmax_16384x16384xf32_dispatch_tensor_store.
LLVM ERROR: unable to legalize instruction: %13:_(s32) = G_VECREDUCE_FMAX %11:_(<4 x s32>) (in function: main$async_dispatch_19_softmax_16384x16384xf32_dispatch_tensor_store)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/tpopp/gisel/iree-build/llvm-project/bin/llc -global-isel reduced.ll
1.      Running pass 'CallGraph Pass Manager' on module 'reduced.ll'.
2.      Running pass 'Legalizer' on function '@"main$async_dispatch_19_softmax_16384x16384xf32_dispatch_tensor_store"'
 #0 0x000062d303317d87 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x000062d303315fc0 llvm::sys::RunSignalHandlers() /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Support/Signals.cpp:106:18
 #2 0x000062d30331844a SignalHandler(int) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x000075c0bba42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000075c0bba969fc __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
 #5 0x000075c0bba969fc __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10
 #6 0x000075c0bba969fc pthread_kill ./nptl/./nptl/pthread_kill.c:89:10
 #7 0x000075c0bba42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x000075c0bba287f3 abort ./stdlib/./stdlib/abort.c:81:7
 #9 0x000062d30328c7b3 llvm::report_fatal_error(llvm::Twine const&, bool) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Support/ErrorHandling.cpp:126:5
#10 0x000062d3037c26e4 (/home/tpopp/gisel/iree-build/llvm-project/bin/llc+0x604b6e4)
#11 0x000062d3037c29c8 llvm::DiagnosticInfoOptimizationBase::~DiagnosticInfoOptimizationBase() /home/tpopp/gisel/iree/third_party/llvm-project/llvm/include/llvm/IR/DiagnosticInfo.h:414:7
#12 0x000062d3037c29c8 llvm::reportGISelFailure(llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, char const*, llvm::StringRef, llvm::MachineInstr const&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/CodeGen/GlobalISel/Utils.cpp:277:1
#13 0x000062d30375bffd llvm::Legalizer::runOnMachineFunction(llvm::MachineFunction&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp:0:5
#14 0x000062d30254d4c4 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:0:13
#15 0x000062d3029ca875 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:0:27
#16 0x000062d3020c143c (anonymous namespace)::CGPassManager::RunPassOnSCC(llvm::Pass*, llvm::CallGraphSCC&, llvm::CallGraph&, bool&, bool&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:180:25
#17 0x000062d3020c143c (anonymous namespace)::CGPassManager::RunAllPassesOnSCC(llvm::CallGraphSCC&, llvm::CallGraph&, bool&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:469:9
#18 0x000062d3020c143c (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:534:18
#19 0x000062d3029cb002 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:0:27
#20 0x000062d3010b25e3 compileModule(char**, llvm::LLVMContext&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/tools/llc/llc.cpp:755:17
#21 0x000062d3010b25e3 main /home/tpopp/gisel/iree/third_party/llvm-project/llvm/tools/llc/llc.cpp:412:22
#22 0x000075c0bba29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#23 0x000075c0bba29e40 call_init ./csu/../csu/libc-start.c:128:20
#24 0x000075c0bba29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#25 0x000062d3010afd25 _start (/home/tpopp/gisel/iree-build/llvm-project/bin/llc+0x3938d25)
llvmbot commented 1 week ago

@llvm/issue-subscribers-backend-amdgpu

Author: Tres (tpopp)

Attempting to lower the following code snippet with global isel fails in legalization:`llc -global-isel reduced.ll` ``` target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9" target triple = "amdgcn-amd-amdhsa" define amdgpu_kernel void @"main$async_dispatch_19_softmax_16384x16384xf32_dispatch_tensor_store"() { %1 = call float @llvm.vector.reduce.fmax.v4f32(<4 x float> zeroinitializer) store float %1, ptr addrspace(3) null, align 4 ret void } ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) declare float @llvm.vector.reduce.fmax.v4f32(<4 x float>) #0 attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } ``` ``` # *** IR Dump Before Legalizer (legalizer) ***: # Machine code for function main$async_dispatch_19_softmax_16384x16384xf32_dispatch_tensor_store: IsSSA, TracksLiveness Function Live Ins: $sgpr0_sgpr1_sgpr2_sgpr3 in %0, $sgpr4_sgpr5 in %1, $sgpr6_sgpr7 in %2, $sgpr8_sgpr9 in %3, $vgpr0 in %4, $vgpr1 in %5, $vgpr2 in %6, $sgpr10 in %7, $sgpr11 in %8, $sgpr12 in %9, $sgpr13 in %10 bb.1 (%ir-block.0): liveins: $sgpr6_sgpr7 %12:_(s32) = G_FCONSTANT float 0.000000e+00 %11:_(<4 x s32>) = G_BUILD_VECTOR %12:_(s32), %12:_(s32), %12:_(s32), %12:_(s32) %13:_(s32) = G_VECREDUCE_FMAX %11:_(<4 x s32>) %14:_(p3) = G_CONSTANT i32 0 G_STORE %13:_(s32), %14:_(p3) :: (store (s32) into `ptr addrspace(3) null`, addrspace 3) S_ENDPGM 0 # End machine code for function main$async_dispatch_19_softmax_16384x16384xf32_dispatch_tensor_store. LLVM ERROR: unable to legalize instruction: %13:_(s32) = G_VECREDUCE_FMAX %11:_(<4 x s32>) (in function: main$async_dispatch_19_softmax_16384x16384xf32_dispatch_tensor_store) PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /home/tpopp/gisel/iree-build/llvm-project/bin/llc -global-isel reduced.ll 1. Running pass 'CallGraph Pass Manager' on module 'reduced.ll'. 2. Running pass 'Legalizer' on function '@"main$async_dispatch_19_softmax_16384x16384xf32_dispatch_tensor_store"' #0 0x000062d303317d87 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13 #1 0x000062d303315fc0 llvm::sys::RunSignalHandlers() /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Support/Signals.cpp:106:18 #2 0x000062d30331844a SignalHandler(int) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1 #3 0x000075c0bba42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x000075c0bba969fc __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76 #5 0x000075c0bba969fc __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10 #6 0x000075c0bba969fc pthread_kill ./nptl/./nptl/pthread_kill.c:89:10 #7 0x000075c0bba42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6 #8 0x000075c0bba287f3 abort ./stdlib/./stdlib/abort.c:81:7 #9 0x000062d30328c7b3 llvm::report_fatal_error(llvm::Twine const&, bool) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Support/ErrorHandling.cpp:126:5 #10 0x000062d3037c26e4 (/home/tpopp/gisel/iree-build/llvm-project/bin/llc+0x604b6e4) #11 0x000062d3037c29c8 llvm::DiagnosticInfoOptimizationBase::~DiagnosticInfoOptimizationBase() /home/tpopp/gisel/iree/third_party/llvm-project/llvm/include/llvm/IR/DiagnosticInfo.h:414:7 #12 0x000062d3037c29c8 llvm::reportGISelFailure(llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, char const*, llvm::StringRef, llvm::MachineInstr const&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/CodeGen/GlobalISel/Utils.cpp:277:1 #13 0x000062d30375bffd llvm::Legalizer::runOnMachineFunction(llvm::MachineFunction&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/CodeGen/GlobalISel/Legalizer.cpp:0:5 #14 0x000062d30254d4c4 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:0:13 #15 0x000062d3029ca875 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:0:27 #16 0x000062d3020c143c (anonymous namespace)::CGPassManager::RunPassOnSCC(llvm::Pass*, llvm::CallGraphSCC&, llvm::CallGraph&, bool&, bool&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:180:25 #17 0x000062d3020c143c (anonymous namespace)::CGPassManager::RunAllPassesOnSCC(llvm::CallGraphSCC&, llvm::CallGraph&, bool&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:469:9 #18 0x000062d3020c143c (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/Analysis/CallGraphSCCPass.cpp:534:18 #19 0x000062d3029cb002 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:0:27 #20 0x000062d3010b25e3 compileModule(char**, llvm::LLVMContext&) /home/tpopp/gisel/iree/third_party/llvm-project/llvm/tools/llc/llc.cpp:755:17 #21 0x000062d3010b25e3 main /home/tpopp/gisel/iree/third_party/llvm-project/llvm/tools/llc/llc.cpp:412:22 #22 0x000075c0bba29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #23 0x000075c0bba29e40 call_init ./csu/../csu/libc-start.c:128:20 #24 0x000075c0bba29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5 #25 0x000062d3010afd25 _start (/home/tpopp/gisel/iree-build/llvm-project/bin/llc+0x3938d25) ```