Most of VP intrinsics are implemented in RISC-V backends, but vp.reduce.mul (element length > 1) does not yet. Legalizes vp.reduce.mul using ExpandVectorPredication Pass.
Details
Details
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Comment Actions
I'm afraid not.... expand vp pass seems not able to expand reduction (causes an assertion failure).
IR:
declare i8 @llvm.vp.reduce.mul.nxv2i8(i8, <vscale x 2 x i8>, <vscale x 2 x i1>, i32) define signext i8 @vpreduce_mul_nxv2i8(i8 signext %s, <vscale x 2 x i8> %v, <vscale x 2 x i1> %m, i32 zeroext %evl) { %r = call i8 @llvm.vp.reduce.mul.nxv2i8(i8 %s, <vscale x 2 x i8> %v, <vscale x 2 x i1> %m, i32 %evl) ret i8 %r }
After expand vp:
define signext i8 @vpreduce_mul_nxv2i8(i8 signext %s, <vscale x 2 x i8> %v, <vscale x 2 x i1> %m, i32 zeroext %evl) { %1 = call <vscale x 2 x i1> @llvm.get.active.lane.mask.nxv2i1.i32(i32 0, i32 %evl) %2 = and <vscale x 2 x i1> %1, %m %vscale = call i32 @llvm.vscale.i32() %scalable_size = mul nuw i32 %vscale, 2 %3 = select <vscale x 2 x i1> %2, <vscale x 2 x i8> %v, <vscale x 2 x i8> shufflevector (<vscale x 2 x i8> insertelement (<vscale x 2 x i8> poison, i8 1, i32 0), <vscale x 2 x i8> poison, <vscale x 2 x i32> zeroinitializer) %4 = call i8 @llvm.vector.reduce.mul.nxv2i8(<vscale x 2 x i8> %3) %5 = mul i8 %4, %s ret i8 %5 }
Other targets may not able to handle this as well. https://godbolt.org/z/qevxT5r8Y
Perhaps some of our next patches should be to improve the related passes (like Expand reduction intrinsics)?
Stack dump:
llc: <llvm-project>/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From *) [To = llvm::FixedVectorType, From = llvm::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: build/bin/llc -mtriple=riscv32 local/buddy/reduce/mul/scale.ll 1. Running pass 'Function Pass Manager' on module 'local/buddy/reduce/mul/scale.ll'. 2. Running pass 'Expand reduction intrinsics' on function '@vpreduce_mul_nxv2i8' #0 0x00007f5ebd0c31da llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) <llvm-project>/llvm/lib/Support/Unix/Signals.inc:567:11 #1 0x00007f5ebd0c338b PrintStackTraceSignalHandler(void*) <llvm-project>/llvm/lib/Support/Unix/Signals.inc:641:1 #2 0x00007f5ebd0c1a16 llvm::sys::RunSignalHandlers() <llvm-project>/llvm/lib/Support/Signals.cpp:104:5 #3 0x00007f5ebd0c3a75 SignalHandler(int) <llvm-project>/llvm/lib/Support/Unix/Signals.inc:412:1 #4 0x00007f5ebc7c2950 (/usr/lib64/libc.so.6+0x37950) #5 0x00007f5ebc80e42c (/usr/lib64/libc.so.6+0x8342c) #6 0x00007f5ebc7c28b2 raise (/usr/lib64/libc.so.6+0x378b2) #7 0x00007f5ebc7ad471 abort (/usr/lib64/libc.so.6+0x22471) #8 0x00007f5ebc7ad395 (/usr/lib64/libc.so.6+0x22395) #9 0x00007f5ebc7bbb92 (/usr/lib64/libc.so.6+0x30b92) #10 0x00007f5ec07c8c88 decltype(auto) llvm::cast<llvm::FixedVectorType, llvm::Type>(llvm::Type*) <llvm-project>/llvm/include/llvm/Support/Casting.h:579:10 #11 0x00007f5ec080c6d6 (anonymous namespace)::expandReductions(llvm::Function&, llvm::TargetTransformInfo const*) <llvm-project>/llvm/lib/CodeGen/ExpandReductions.cpp:147:15 #12 0x00007f5ec080c976 (anonymous namespace)::ExpandReductions::runOnFunction(llvm::Function&) <llvm-project>/llvm/lib/CodeGen/ExpandReductions.cpp:183:5 #13 0x00007f5ebdcb9643 llvm::FPPassManager::runOnFunction(llvm::Function&) <llvm-project>/llvm/lib/IR/LegacyPassManager.cpp:1430:23 #14 0x00007f5ebdcbe462 llvm::FPPassManager::runOnModule(llvm::Module&) <llvm-project>/llvm/lib/IR/LegacyPassManager.cpp:1476:16 #15 0x00007f5ebdcb9f19 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) <llvm-project>/llvm/lib/IR/LegacyPassManager.cpp:1545:23 #16 0x00007f5ebdcb9a8a llvm::legacy::PassManagerImpl::run(llvm::Module&) <llvm-project>/llvm/lib/IR/LegacyPassManager.cpp:535:16 #17 0x00007f5ebdcbe741 llvm::legacy::PassManager::run(llvm::Module&) <llvm-project>/llvm/lib/IR/LegacyPassManager.cpp:1672:3 #18 0x000055f10326689a compileModule(char**, llvm::LLVMContext&) <llvm-project>/llvm/tools/llc/llc.cpp:737:41 #19 0x000055f103264ca2 main <llvm-project>/llvm/tools/llc/llc.cpp:418:13 #20 0x00007f5ebc7ae34a (/usr/lib64/libc.so.6+0x2334a) #21 0x00007f5ebc7ae3fc __libc_start_main (/usr/lib64/libc.so.6+0x233fc) #22 0x000055f1032644b1 _start (build/bin/llc+0x284b1) zsh: IOT instruction (core dumped) build/bin/llc -mtriple=riscv32 local/buddy/reduce/mul/scale.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-mask-vp.ll | ||
---|---|---|
1010 ↗ | (On Diff #481667) | This test file has "mask" in its name because it is the test file for i1 vectors. These tests should be be in fixed-vectors-reduction-vp.ll |