Skip to content

[RISC-V] LLVM ERROR: Invalid size request on a scalable vector #125306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ewlu opened this issue Jan 31, 2025 · 4 comments
Closed

[RISC-V] LLVM ERROR: Invalid size request on a scalable vector #125306

ewlu opened this issue Jan 31, 2025 · 4 comments
Assignees
Labels
backend:RISC-V crash Prefer [crash-on-valid] or [crash-on-invalid] release:backport

Comments

@ewlu
Copy link

ewlu commented Jan 31, 2025

Testcase:

target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "riscv64-unknown-linux-gnu"

define i32 @main(ptr %0) #0 {
entry:
  store <16 x i16> zeroinitializer, ptr null, align 2
  store <8 x i32> zeroinitializer, ptr %0, align 4
  store <4 x i32> zeroinitializer, ptr getelementptr inbounds nuw (i8, ptr null, i64 64), align 4
  store i32 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 80), align 4
  %1 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 29916), align 4
  %broadcast.splatinsert53 = insertelement <4 x i32> zeroinitializer, i32 %1, i64 0
  %2 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28484), align 4
  %broadcast.splatinsert55 = insertelement <4 x i32> zeroinitializer, i32 %2, i64 0
  %3 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %broadcast.splatinsert53, <4 x i32> %broadcast.splatinsert55)
  %4 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28368), align 4
  %broadcast.splatinsert57 = insertelement <4 x i32> zeroinitializer, i32 %4, i64 0
  %5 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %3, <4 x i32> %broadcast.splatinsert57)
  store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 3704), align 2
  store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 4630), align 2
  %6 = shufflevector <4 x i32> %5, <4 x i32> zeroinitializer, <2 x i32> <i32 0, i32 4>
  store <2 x i32> %6, ptr getelementptr inbounds nuw (i8, ptr null, i64 16), align 4
  store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 5556), align 2
  store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 6482), align 2
  store <2 x i32> zeroinitializer, ptr getelementptr inbounds nuw (i8, ptr null, i64 24), align 4
  store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 7408), align 2
  store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 8334), align 2
  store <2 x i32> zeroinitializer, ptr getelementptr inbounds nuw (i8, ptr null, i64 32), align 4
  store i16 0, ptr %0, align 2
  store <2 x i32> zeroinitializer, ptr getelementptr inbounds nuw (i8, ptr null, i64 40), align 4
  %7 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 29916), align 4
  %broadcast.splatinsert165 = insertelement <4 x i32> poison, i32 %7, i64 0
  %8 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28484), align 4
  %broadcast.splatinsert167 = insertelement <4 x i32> poison, i32 %8, i64 0
  %9 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %broadcast.splatinsert165, <4 x i32> %broadcast.splatinsert167)
  %10 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28368), align 4
  %broadcast.splatinsert169 = insertelement <4 x i32> poison, i32 %10, i64 0
  %11 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %9, <4 x i32> %broadcast.splatinsert169)
  store i16 0, ptr null, align 2
  %12 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 29916), align 4
  %broadcast.splatinsert179 = insertelement <4 x i32> poison, i32 %12, i64 0
  %13 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28484), align 4
  %broadcast.splatinsert181 = insertelement <4 x i32> poison, i32 %13, i64 0
  %14 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %broadcast.splatinsert179, <4 x i32> %broadcast.splatinsert181)
  %15 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28368), align 4
  %broadcast.splatinsert183 = insertelement <4 x i32> poison, i32 %15, i64 0
  %16 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %14, <4 x i32> %broadcast.splatinsert183)
  %17 = shufflevector <4 x i32> %11, <4 x i32> %16, <2 x i32> <i32 0, i32 4>
  store <2 x i32> %17, ptr null, align 4
  ret i32 0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.smin.v4i32(<4 x i32>, <4 x i32>) #1

; uselistorder directives
uselistorder ptr null, { 0, 1, 11, 6, 17, 16, 10, 15, 14, 9, 13, 12, 5, 4, 3, 8, 7, 2 }
uselistorder ptr @llvm.smin.v4i32, { 5, 4, 3, 2, 1, 0 }

attributes #0 = { "target-features"="+64bit,+a,+c,+d,+f,+m,+relax,+v,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-sdext,-experimental-sdtrig,-experimental-smctr,-experimental-ssctr,-experimental-svukte,-experimental-xqcia,-experimental-xqciac,-experimental-xqcicli,-experimental-xqcicm,-experimental-xqcics,-experimental-xqcicsr,-experimental-xqciint,-experimental-xqcilo,-experimental-xqcilsm,-experimental-xqcisls,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-sha,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smdbltrp,-smepmp,-smmpm,-smnpm,-smrnmi,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssdbltrp,-ssnpm,-sspm,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-supm,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-svvptc,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xmipscmove,-xmipslsp,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zabha,-zacas,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

Command/backtrace:

$ /scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc reduced.ll
LLVM ERROR: Invalid size request on a scalable vector.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc reduced.ll
1.      Running pass 'Function Pass Manager' on module 'reduced.ll'.
2.      Running pass 'RISC-V DAG->DAG Pattern Instruction Selection' on function '@main'
 #0 0x000061aae52a1672 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x2092672)
 #1 0x000061aae529e6bf llvm::sys::RunSignalHandlers() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x208f6bf)
 #2 0x000061aae529e7fc SignalHandler(int) Signals.cpp:0:0
 #3 0x00007b9270045320 (/lib/x86_64-linux-gnu/libc.so.6+0x45320)
 #4 0x00007b927009eb1c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007b927009eb1c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007b927009eb1c pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007b927004526e raise ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007b92700288ff abort ./stdlib/abort.c:81:7
 #9 0x000061aae3860302 llvm::Regex::match(llvm::StringRef, llvm::SmallVectorImpl<llvm::StringRef>*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*) const (.cold) Regex.cpp:0:0
#10 0x000061aae51ec13e (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x1fdd13e)
#11 0x000061aae5241738 (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x2032738)
#12 0x000061aae3ac63ac llvm::EVT::getVectorNumElements() const (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x8b73ac)
#13 0x000061aae3b3e130 lowerVECTOR_SHUFFLE(llvm::SDValue, llvm::SelectionDAG&, llvm::RISCVSubtarget const&) RISCVISelLowering.cpp:0:0
#14 0x000061aae4edfda9 (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) LegalizeDAG.cpp:0:0
#15 0x000061aae4ee2a80 llvm::SelectionDAG::Legalize() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x1cd3a80)
#16 0x000061aae50177de llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x1e087de)
#17 0x000061aae501a849 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x1e0b849)
#18 0x000061aae501bf5a llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x1e0cf5a)
#19 0x000061aae50068d7 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x1df78d7)
#20 0x000061aae40bcfab llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#21 0x000061aae4729181 llvm::FPPassManager::runOnFunction(llvm::Function&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x151a181)
#22 0x000061aae47295d1 llvm::FPPassManager::runOnModule(llvm::Module&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x151a5d1)
#23 0x000061aae4729f64 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x151af64)
#24 0x000061aae394e942 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#25 0x000061aae3867827 main (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x658827)
#26 0x00007b927002a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#27 0x00007b927002a28b call_init ./csu/../csu/libc-start.c:128:20
#28 0x00007b927002a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#29 0x000061aae3943cc5 _start (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x734cc5)
Aborted (core dumped)

Godbolt: https://godbolt.org/z/1v7P6eddE

Found via fuzzer (C program before reduction)

@EugeneZelenko EugeneZelenko added backend:RISC-V crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:SelectionDAG SelectionDAGISel as well and removed new issue labels Jan 31, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 31, 2025

@llvm/issue-subscribers-backend-risc-v

Author: Edwin Lu (ewlu)

Testcase: ```llvm ir target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128" target triple = "riscv64-unknown-linux-gnu"

define i32 @main(ptr %0) #0 {
entry:
store <16 x i16> zeroinitializer, ptr null, align 2
store <8 x i32> zeroinitializer, ptr %0, align 4
store <4 x i32> zeroinitializer, ptr getelementptr inbounds nuw (i8, ptr null, i64 64), align 4
store i32 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 80), align 4
%1 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 29916), align 4
%broadcast.splatinsert53 = insertelement <4 x i32> zeroinitializer, i32 %1, i64 0
%2 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28484), align 4
%broadcast.splatinsert55 = insertelement <4 x i32> zeroinitializer, i32 %2, i64 0
%3 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %broadcast.splatinsert53, <4 x i32> %broadcast.splatinsert55)
%4 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28368), align 4
%broadcast.splatinsert57 = insertelement <4 x i32> zeroinitializer, i32 %4, i64 0
%5 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %3, <4 x i32> %broadcast.splatinsert57)
store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 3704), align 2
store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 4630), align 2
%6 = shufflevector <4 x i32> %5, <4 x i32> zeroinitializer, <2 x i32> <i32 0, i32 4>
store <2 x i32> %6, ptr getelementptr inbounds nuw (i8, ptr null, i64 16), align 4
store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 5556), align 2
store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 6482), align 2
store <2 x i32> zeroinitializer, ptr getelementptr inbounds nuw (i8, ptr null, i64 24), align 4
store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 7408), align 2
store i16 0, ptr getelementptr inbounds nuw (i8, ptr null, i64 8334), align 2
store <2 x i32> zeroinitializer, ptr getelementptr inbounds nuw (i8, ptr null, i64 32), align 4
store i16 0, ptr %0, align 2
store <2 x i32> zeroinitializer, ptr getelementptr inbounds nuw (i8, ptr null, i64 40), align 4
%7 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 29916), align 4
%broadcast.splatinsert165 = insertelement <4 x i32> poison, i32 %7, i64 0
%8 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28484), align 4
%broadcast.splatinsert167 = insertelement <4 x i32> poison, i32 %8, i64 0
%9 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %broadcast.splatinsert165, <4 x i32> %broadcast.splatinsert167)
%10 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28368), align 4
%broadcast.splatinsert169 = insertelement <4 x i32> poison, i32 %10, i64 0
%11 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %9, <4 x i32> %broadcast.splatinsert169)
store i16 0, ptr null, align 2
%12 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 29916), align 4
%broadcast.splatinsert179 = insertelement <4 x i32> poison, i32 %12, i64 0
%13 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28484), align 4
%broadcast.splatinsert181 = insertelement <4 x i32> poison, i32 %13, i64 0
%14 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %broadcast.splatinsert179, <4 x i32> %broadcast.splatinsert181)
%15 = load i32, ptr getelementptr inbounds nuw (i8, ptr null, i64 28368), align 4
%broadcast.splatinsert183 = insertelement <4 x i32> poison, i32 %15, i64 0
%16 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %14, <4 x i32> %broadcast.splatinsert183)
%17 = shufflevector <4 x i32> %11, <4 x i32> %16, <2 x i32> <i32 0, i32 4>
store <2 x i32> %17, ptr null, align 4
ret i32 0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.smin.v4i32(<4 x i32>, <4 x i32>) #1

; uselistorder directives
uselistorder ptr null, { 0, 1, 11, 6, 17, 16, 10, 15, 14, 9, 13, 12, 5, 4, 3, 8, 7, 2 }
uselistorder ptr @llvm.smin.v4i32, { 5, 4, 3, 2, 1, 0 }

attributes #0 = { "target-features"="+64bit,+a,+c,+d,+f,+m,+relax,+v,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-sdext,-experimental-sdtrig,-experimental-smctr,-experimental-ssctr,-experimental-svukte,-experimental-xqcia,-experimental-xqciac,-experimental-xqcicli,-experimental-xqcicm,-experimental-xqcics,-experimental-xqcicsr,-experimental-xqciint,-experimental-xqcilo,-experimental-xqcilsm,-experimental-xqcisls,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-sha,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smdbltrp,-smepmp,-smmpm,-smnpm,-smrnmi,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssdbltrp,-ssnpm,-sspm,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-supm,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-svvptc,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xmipscmove,-xmipslsp,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zabha,-zacas,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }


Command/backtrace:

$ /scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc reduced.ll
LLVM ERROR: Invalid size request on a scalable vector.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc reduced.ll

  1.  Running pass 'Function Pass Manager' on module 'reduced.ll'.
    
  2.  Running pass 'RISC-V DAG-&gt;DAG Pattern Instruction Selection' on function '@<!-- -->main'
    

#0 0x000061aae52a1672 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x2092672)
#1 0x000061aae529e6bf llvm::sys::RunSignalHandlers() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x208f6bf)
#2 0x000061aae529e7fc SignalHandler(int) Signals.cpp:0:0
#3 0x00007b9270045320 (/lib/x86_64-linux-gnu/libc.so.6+0x45320)
#4 0x00007b927009eb1c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007b927009eb1c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007b927009eb1c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007b927004526e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007b92700288ff abort ./stdlib/abort.c:81:7
#9 0x000061aae3860302 llvm::Regex::match(llvm::StringRef, llvm::SmallVectorImpl<llvm::StringRef>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>) const (.cold) Regex.cpp:0:0
#10 0x000061aae51ec13e (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x1fdd13e)
#11 0x000061aae5241738 (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x2032738)
#12 0x000061aae3ac63ac llvm::EVT::getVectorNumElements() const (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x8b73ac)
#13 0x000061aae3b3e130 lowerVECTOR_SHUFFLE(llvm::SDValue, llvm::SelectionDAG&, llvm::RISCVSubtarget const&) RISCVISelLowering.cpp:0:0
#14 0x000061aae4edfda9 (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) LegalizeDAG.cpp:0:0
#15 0x000061aae4ee2a80 llvm::SelectionDAG::Legalize() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x1cd3a80)
#16 0x000061aae50177de llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x1e087de)
#17 0x000061aae501a849 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x1e0b849)
#18 0x000061aae501bf5a llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x1e0cf5a)
#19 0x000061aae50068d7 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x1df78d7)
#20 0x000061aae40bcfab llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#21 0x000061aae4729181 llvm::FPPassManager::runOnFunction(llvm::Function&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x151a181)
#22 0x000061aae47295d1 llvm::FPPassManager::runOnModule(llvm::Module&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x151a5d1)
#23 0x000061aae4729f64 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x151af64)
#24 0x000061aae394e942 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#25 0x000061aae3867827 main (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x658827)
#26 0x00007b927002a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#27 0x00007b927002a28b call_init ./csu/../csu/libc-start.c:128:20
#28 0x00007b927002a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#29 0x000061aae3943cc5 _start (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/llc+0x734cc5)
Aborted (core dumped)


Godbolt: https://godbolt.org/z/1v7P6eddE

Found via fuzzer (C program before reduction)
</details>

@topperc
Copy link
Collaborator

topperc commented Feb 1, 2025

Candidate patch

diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 07e3390f3fbb..1dddb67f9ad8 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -4510,7 +4510,8 @@ static SDValue getSingleShuffleSrc(MVT VT, MVT ContainerVT, SDValue V1,
 
   // Src needs to have twice the number of elements.
   unsigned NumElts = VT.getVectorNumElements();
-  if (Src.getValueType().getVectorNumElements() != (NumElts * 2))
+  if (Src.getValueType().isScalableVector() ||
+      Src.getValueType().getVectorNumElements() != (NumElts * 2))
     return SDValue();
 
   // The extracts must extract the two halves of the source.

@topperc topperc self-assigned this Feb 3, 2025
topperc added a commit to topperc/llvm-project that referenced this issue Feb 3, 2025
… in getSingleShuffleSrc.

I have been unsuccessful at further reducing the test. The
failure requires a shuffle with 2 scalable->fixed extracts with
the same source. 0 is the only valid index for a scalable->fixed
extract so the 2 sources must be the same extract. Shuffles with
the same source are aggressively canonicalized to a unary shuffle.
So it requires the extracts to become identical through other
optimizations without the shuffle being canonicalized before it is
lowered.

Fixes llvm#125306.
@topperc topperc closed this as completed in 7c5100d Feb 3, 2025
@topperc topperc added this to the LLVM 20.X Release milestone Feb 3, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Feb 3, 2025
@topperc
Copy link
Collaborator

topperc commented Feb 3, 2025

/cherry-pick 7c5100d

@llvmbot
Copy link
Member

llvmbot commented Feb 3, 2025

/pull-request #125590

@EugeneZelenko EugeneZelenko removed the llvm:SelectionDAG SelectionDAGISel as well label Feb 3, 2025
@nikic nikic moved this from Needs Triage to Done in LLVM Release Status Feb 6, 2025
swift-ci pushed a commit to swiftlang/llvm-project that referenced this issue Feb 10, 2025
… in getSingleShuffleSrc. (llvm#125455)

I have been unsuccessful at further reducing the test. The
failure requires a shuffle with 2 scalable->fixed extracts with
the same source. 0 is the only valid index for a scalable->fixed
extract so the 2 sources must be the same extract. Shuffles with
the same source are aggressively canonicalized to a unary shuffle.
So it requires the extracts to become identical through other
optimizations without the shuffle being canonicalized before it is
lowered.

Fixes llvm#125306.

(cherry picked from commit 7c5100d)
Icohedron pushed a commit to Icohedron/llvm-project that referenced this issue Feb 11, 2025
… in getSingleShuffleSrc. (llvm#125455)

I have been unsuccessful at further reducing the test. The
failure requires a shuffle with 2 scalable->fixed extracts with
the same source. 0 is the only valid index for a scalable->fixed
extract so the 2 sources must be the same extract. Shuffles with
the same source are aggressively canonicalized to a unary shuffle.
So it requires the extracts to become identical through other
optimizations without the shuffle being canonicalized before it is
lowered.

Fixes llvm#125306.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:RISC-V crash Prefer [crash-on-valid] or [crash-on-invalid] release:backport
Projects
4 participants