This is an archive of the discontinued LLVM Phabricator instance.

[riscv] Enable strict assertions in InsertVSETVLI data flow
ClosedPublic

Authored by reames on May 9 2022, 2:29 PM.

Details

Summary

Now that all of the known bugs have been fixed, we can toggle this on and see what else falls out in broader testing.

Diff Detail

Event Timeline

reames created this revision.May 9 2022, 2:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2022, 2:29 PM
reames requested review of this revision.May 9 2022, 2:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2022, 2:29 PM

This is ready to go in, just pending an LGTM.

MaskRay accepted this revision.May 17 2022, 10:26 AM

s/riscv/RISCV/

This revision is now accepted and ready to land.May 17 2022, 10:26 AM

If this ready to go, can you please update the patch stack dependencies so that it's not blocked by D125270

If this ready to go, can you please update the patch stack dependencies so that it's not blocked by D125270

Done.

This revision was landed with ongoing or failed builds.May 17 2022, 11:12 AM
This revision was automatically updated to reflect the committed changes.

Why was this reverted?

Why was this reverted?

As noted in the reverting commit, I found a test case which tripped the assert. Should have a cleaned up test landed today, and probably a fix posted for review. It's a cross block variant of one I thought we'd already fully fixed.

pcwang-thead added a comment.EditedMay 29 2022, 11:00 PM

Here is an issue found in D125747. It seems that we will get compilation failures with -mllvm -scalable-vectorization=on using latest LLVM upstream.
Full command is: clang -O2 -march=rv64gcv -mllvm -riscv-v-vector-bits-max=128 -mllvm -riscv-v-vector-bits-min=128 -mllvm -scalable-vectorization=on .
When compiling TSVC, I got:

clang-15: llvm-project-upstream/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp:1172: void {anonymous}::RISCVInsertVSETVLI::emitVSETVLIs(llvm::MachineBasicBlock&): Assertion `CurInfo == Info.Exit && "InsertVSETVLI dataflow invariant violated"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: software/clang-riscv-upstream/bin/clang-15 -cc1 -triple riscv64-unknown-linux-gnu -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name tsc.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-feature +m -target-feature +a -target-feature +f -target-feature +d -target-feature +c -target-feature +v -target-feature +zve32f -target-feature +zve32x -target-feature +zve64d -target-feature +zve64f -target-feature +zve64x -target-feature +zvl128b -target-feature +zvl32b -target-feature +zvl64b -target-feature +relax -target-feature -save-restore -target-abi lp64d -msmall-data-limit 8 -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=workspace/issues/vectorize/TSVC -resource-dir software/clang-riscv-upstream/lib/clang/15.0.0 -isysroot software/release/sysroot/ -internal-isystem software/clang-riscv-upstream/lib/clang/15.0.0/include -internal-isystem software/release/sysroot//usr/local/include -internal-isystem software/release/lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/include -internal-externc-isystem software/release/sysroot//include -internal-externc-isystem software/release/sysroot//usr/include -O2 -fdebug-compilation-dir=workspace/issues/vectorize/TSVC -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -mllvm -riscv-v-vector-bits-max=128 -mllvm -riscv-v-vector-bits-min=128 -mllvm -scalable-vectorization=on -faddrsig -o /tmp/tsc-ef6646.o -x c tsc.c
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'tsc.c'.
4.      Running pass 'RISCV Insert VSETVLI pass' on function '@init'
 #0 0x0000563161942c8e llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) llvm-project-upstream/llvm/lib/Support/Unix/Signals.inc:565:0
 #1 0x0000563161942d45 PrintStackTraceSignalHandler(void*) llvm-project-upstream/llvm/lib/Support/Unix/Signals.inc:632:0
 #2 0x00005631619409ec llvm::sys::RunSignalHandlers() llvm-project-upstream/llvm/lib/Support/Signals.cpp:103:0
 #3 0x000056316194260f SignalHandler(int) llvm-project-upstream/llvm/lib/Support/Unix/Signals.inc:407:0
 #4 0x00007fb119b9e980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00007fb11884fe87 raise /build/glibc-uZu3wS/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007fb1188517f1 abort /build/glibc-uZu3wS/glibc-2.27/stdlib/abort.c:81:0
 #7 0x00007fb1188413fa __assert_fail_base /build/glibc-uZu3wS/glibc-2.27/assert/assert.c:89:0
 #8 0x00007fb118841472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
 #9 0x000056315f2af865 (anonymous namespace)::RISCVInsertVSETVLI::emitVSETVLIs(llvm::MachineBasicBlock&) llvm-project-upstream/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp:1171:0
#10 0x000056315f2b0f8c (anonymous namespace)::RISCVInsertVSETVLI::runOnMachineFunction(llvm::MachineFunction&) llvm-project-upstream/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp:1476:0
#11 0x0000563160757cff llvm::MachineFunctionPass::runOnFunction(llvm::Function&) llvm-project-upstream/llvm/lib/CodeGen/MachineFunctionPass.cpp:73:0
#12 0x0000563160eb0894 llvm::FPPassManager::runOnFunction(llvm::Function&) llvm-project-upstream/llvm/lib/IR/LegacyPassManager.cpp:1430:0
#13 0x0000563160eb0b3d llvm::FPPassManager::runOnModule(llvm::Module&) llvm-project-upstream/llvm/lib/IR/LegacyPassManager.cpp:1476:0
#14 0x0000563160eb0f65 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) llvm-project-upstream/llvm/lib/IR/LegacyPassManager.cpp:1545:0
#15 0x0000563160eabf87 llvm::legacy::PassManagerImpl::run(llvm::Module&) llvm-project-upstream/llvm/lib/IR/LegacyPassManager.cpp:535:0
#16 0x0000563160eb17ef llvm::legacy::PassManager::run(llvm::Module&) llvm-project-upstream/llvm/lib/IR/LegacyPassManager.cpp:1673:0
#17 0x0000563161e2b800 (anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) llvm-project-upstream/clang/lib/CodeGen/BackendUtil.cpp:1000:0
#18 0x0000563161e2ba04 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) llvm-project-upstream/clang/lib/CodeGen/BackendUtil.cpp:1025:0
#19 0x0000563161e2ca1c clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) llvm-project-upstream/clang/lib/CodeGen/BackendUtil.cpp:1181:0
#20 0x00005631632689b0 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) llvm-project-upstream/clang/lib/CodeGen/CodeGenAction.cpp:379:0
#21 0x0000563164ffc402 clang::ParseAST(clang::Sema&, bool, bool) llvm-project-upstream/clang/lib/Parse/ParseAST.cpp:182:0
#22 0x00005631628ea47f clang::ASTFrontendAction::ExecuteAction() llvm-project-upstream/clang/lib/Frontend/FrontendAction.cpp:1139:0
#23 0x0000563163265160 clang::CodeGenAction::ExecuteAction() llvm-project-upstream/clang/lib/CodeGen/CodeGenAction.cpp:1144:0
#24 0x00005631628e9d48 clang::FrontendAction::Execute() llvm-project-upstream/clang/lib/Frontend/FrontendAction.cpp:1036:0
#25 0x000056316281ed6b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) llvm-project-upstream/clang/lib/Frontend/CompilerInstance.cpp:1036:0
#26 0x0000563162a89d7c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) llvm-project-upstream/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:266:0
#27 0x000056315f2336b1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) llvm-project-upstream/clang/tools/driver/cc1_main.cpp:248:0
#28 0x000056315f227195 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) llvm-project-upstream/clang/tools/driver/driver.cpp:317:0
#29 0x000056315f2278b2 main llvm-project-upstream/clang/tools/driver/driver.cpp:388:0
#30 0x00007fb118832c87 __libc_start_main /build/glibc-uZu3wS/glibc-2.27/csu/../csu/libc-start.c:344:0
#31 0x000056315f22590a _start (software/clang-riscv-upstream/bin/clang-15+0x2ce490a)

Reduced LLVM IRs via llvm-reduce:

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

define i32 @init(ptr %b, i1 %0) {
entry:
  br label %vector.body8501

vector.body8501:                                  ; preds = %vector.body8501, %entry
  %vec.ind8503 = phi <4 x i64> [ %vec.ind.next8506, %vector.body8501 ], [ zeroinitializer, %entry ]
  %step.add8504 = add <4 x i64> %vec.ind8503, zeroinitializer
  %1 = getelementptr inbounds float, ptr %b, <4 x i64> %step.add8504
  call void @llvm.masked.scatter.v4f32.v4p0(<4 x float> zeroinitializer, <4 x ptr> %1, i32 0, <4 x i1> undef)
  %vec.ind.next8506 = add <4 x i64> %vec.ind8503, <i64 16, i64 16, i64 16, i64 16>
  br i1 %0, label %vector.body8513, label %vector.body8501

vector.body8513:                                  ; preds = %vector.body8513, %vector.body8501
  call void @llvm.masked.scatter.v4f32.v4p0(<4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, <4 x ptr> undef, i32 0, <4 x i1> undef)
  br label %vector.body8513
}

; Function Attrs: nocallback nofree nosync nounwind willreturn writeonly
declare void @llvm.masked.scatter.v4f32.v4p0(<4 x float>, <4 x ptr>, i32 immarg, <4 x i1>) #0

; uselistorder directives
uselistorder ptr @llvm.masked.scatter.v4f32.v4p0, { 1, 0 }

attributes #0 = { nocallback nofree nosync nounwind willreturn writeonly }

@reames can you take a look at this?

Here is an issue found in D125747. It seems that we will get compilation failures with -mllvm -scalable-vectorization=on using latest LLVM upstream.
Full command is: clang -O2 -march=rv64gcv -mllvm -riscv-v-vector-bits-max=128 -mllvm -riscv-v-vector-bits-min=128 -mllvm -scalable-vectorization=on .
When compiling TSVC, I got:

clang-15: llvm-project-upstream/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp:1172: void {anonymous}::RISCVInsertVSETVLI::emitVSETVLIs(llvm::MachineBasicBlock&): Assertion `CurInfo == Info.Exit && "InsertVSETVLI dataflow invariant violated"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: software/clang-riscv-upstream/bin/clang-15 -cc1 -triple riscv64-unknown-linux-gnu -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name tsc.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-feature +m -target-feature +a -target-feature +f -target-feature +d -target-feature +c -target-feature +v -target-feature +zve32f -target-feature +zve32x -target-feature +zve64d -target-feature +zve64f -target-feature +zve64x -target-feature +zvl128b -target-feature +zvl32b -target-feature +zvl64b -target-feature +relax -target-feature -save-restore -target-abi lp64d -msmall-data-limit 8 -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=workspace/issues/vectorize/TSVC -resource-dir software/clang-riscv-upstream/lib/clang/15.0.0 -isysroot software/release/sysroot/ -internal-isystem software/clang-riscv-upstream/lib/clang/15.0.0/include -internal-isystem software/release/sysroot//usr/local/include -internal-isystem software/release/lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/include -internal-externc-isystem software/release/sysroot//include -internal-externc-isystem software/release/sysroot//usr/include -O2 -fdebug-compilation-dir=workspace/issues/vectorize/TSVC -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -mllvm -riscv-v-vector-bits-max=128 -mllvm -riscv-v-vector-bits-min=128 -mllvm -scalable-vectorization=on -faddrsig -o /tmp/tsc-ef6646.o -x c tsc.c
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'tsc.c'.
4.      Running pass 'RISCV Insert VSETVLI pass' on function '@init'
 #0 0x0000563161942c8e llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) llvm-project-upstream/llvm/lib/Support/Unix/Signals.inc:565:0
 #1 0x0000563161942d45 PrintStackTraceSignalHandler(void*) llvm-project-upstream/llvm/lib/Support/Unix/Signals.inc:632:0
 #2 0x00005631619409ec llvm::sys::RunSignalHandlers() llvm-project-upstream/llvm/lib/Support/Signals.cpp:103:0
 #3 0x000056316194260f SignalHandler(int) llvm-project-upstream/llvm/lib/Support/Unix/Signals.inc:407:0
 #4 0x00007fb119b9e980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00007fb11884fe87 raise /build/glibc-uZu3wS/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007fb1188517f1 abort /build/glibc-uZu3wS/glibc-2.27/stdlib/abort.c:81:0
 #7 0x00007fb1188413fa __assert_fail_base /build/glibc-uZu3wS/glibc-2.27/assert/assert.c:89:0
 #8 0x00007fb118841472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
 #9 0x000056315f2af865 (anonymous namespace)::RISCVInsertVSETVLI::emitVSETVLIs(llvm::MachineBasicBlock&) llvm-project-upstream/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp:1171:0
#10 0x000056315f2b0f8c (anonymous namespace)::RISCVInsertVSETVLI::runOnMachineFunction(llvm::MachineFunction&) llvm-project-upstream/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp:1476:0
#11 0x0000563160757cff llvm::MachineFunctionPass::runOnFunction(llvm::Function&) llvm-project-upstream/llvm/lib/CodeGen/MachineFunctionPass.cpp:73:0
#12 0x0000563160eb0894 llvm::FPPassManager::runOnFunction(llvm::Function&) llvm-project-upstream/llvm/lib/IR/LegacyPassManager.cpp:1430:0
#13 0x0000563160eb0b3d llvm::FPPassManager::runOnModule(llvm::Module&) llvm-project-upstream/llvm/lib/IR/LegacyPassManager.cpp:1476:0
#14 0x0000563160eb0f65 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) llvm-project-upstream/llvm/lib/IR/LegacyPassManager.cpp:1545:0
#15 0x0000563160eabf87 llvm::legacy::PassManagerImpl::run(llvm::Module&) llvm-project-upstream/llvm/lib/IR/LegacyPassManager.cpp:535:0
#16 0x0000563160eb17ef llvm::legacy::PassManager::run(llvm::Module&) llvm-project-upstream/llvm/lib/IR/LegacyPassManager.cpp:1673:0
#17 0x0000563161e2b800 (anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) llvm-project-upstream/clang/lib/CodeGen/BackendUtil.cpp:1000:0
#18 0x0000563161e2ba04 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) llvm-project-upstream/clang/lib/CodeGen/BackendUtil.cpp:1025:0
#19 0x0000563161e2ca1c clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) llvm-project-upstream/clang/lib/CodeGen/BackendUtil.cpp:1181:0
#20 0x00005631632689b0 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) llvm-project-upstream/clang/lib/CodeGen/CodeGenAction.cpp:379:0
#21 0x0000563164ffc402 clang::ParseAST(clang::Sema&, bool, bool) llvm-project-upstream/clang/lib/Parse/ParseAST.cpp:182:0
#22 0x00005631628ea47f clang::ASTFrontendAction::ExecuteAction() llvm-project-upstream/clang/lib/Frontend/FrontendAction.cpp:1139:0
#23 0x0000563163265160 clang::CodeGenAction::ExecuteAction() llvm-project-upstream/clang/lib/CodeGen/CodeGenAction.cpp:1144:0
#24 0x00005631628e9d48 clang::FrontendAction::Execute() llvm-project-upstream/clang/lib/Frontend/FrontendAction.cpp:1036:0
#25 0x000056316281ed6b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) llvm-project-upstream/clang/lib/Frontend/CompilerInstance.cpp:1036:0
#26 0x0000563162a89d7c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) llvm-project-upstream/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:266:0
#27 0x000056315f2336b1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) llvm-project-upstream/clang/tools/driver/cc1_main.cpp:248:0
#28 0x000056315f227195 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) llvm-project-upstream/clang/tools/driver/driver.cpp:317:0
#29 0x000056315f2278b2 main llvm-project-upstream/clang/tools/driver/driver.cpp:388:0
#30 0x00007fb118832c87 __libc_start_main /build/glibc-uZu3wS/glibc-2.27/csu/../csu/libc-start.c:344:0
#31 0x000056315f22590a _start (software/clang-riscv-upstream/bin/clang-15+0x2ce490a)

Reduced LLVM IRs via llvm-reduce:

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

define i32 @init(ptr %b, i1 %0) {
entry:
  br label %vector.body8501

vector.body8501:                                  ; preds = %vector.body8501, %entry
  %vec.ind8503 = phi <4 x i64> [ %vec.ind.next8506, %vector.body8501 ], [ zeroinitializer, %entry ]
  %step.add8504 = add <4 x i64> %vec.ind8503, zeroinitializer
  %1 = getelementptr inbounds float, ptr %b, <4 x i64> %step.add8504
  call void @llvm.masked.scatter.v4f32.v4p0(<4 x float> zeroinitializer, <4 x ptr> %1, i32 0, <4 x i1> undef)
  %vec.ind.next8506 = add <4 x i64> %vec.ind8503, <i64 16, i64 16, i64 16, i64 16>
  br i1 %0, label %vector.body8513, label %vector.body8501

vector.body8513:                                  ; preds = %vector.body8513, %vector.body8501
  call void @llvm.masked.scatter.v4f32.v4p0(<4 x float> <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>, <4 x ptr> undef, i32 0, <4 x i1> undef)
  br label %vector.body8513
}

; Function Attrs: nocallback nofree nosync nounwind willreturn writeonly
declare void @llvm.masked.scatter.v4f32.v4p0(<4 x float>, <4 x ptr>, i32 immarg, <4 x i1>) #0

; uselistorder directives
uselistorder ptr @llvm.masked.scatter.v4f32.v4p0, { 1, 0 }

attributes #0 = { nocallback nofree nosync nounwind willreturn writeonly }

@reames can you take a look at this?

Form your IR,

call void @llvm.masked.scatter.v4f32.v4p0(<4 x float> zeroinitializer, <4 x ptr> %1, i32 0, <4 x i1> undef)

I think this is not loop vectorization as scale-vector,set -mllvm -scalable-vectorization=off , may also core dump? Could you try it?

Form your IR,

call void @llvm.masked.scatter.v4f32.v4p0(<4 x float> zeroinitializer, <4 x ptr> %1, i32 0, <4 x i1> undef)

I think this is not loop vectorization as scale-vector,set -mllvm -scalable-vectorization=off , may also core dump? Could you try it?

Yes, it will cause core dump even with -mllvm -scalable-vectorization=off, but will not if we remove -mllvm -riscv-v-vector-bits-max=128 -mllvm -riscv-v-vector-bits-min=128.
So, it seems that there are two problems here I guess:

  1. Some loops can't be vectorized by scalable vectorization and fixed-width vectorization is took as a fallback.
  2. There are some bugs in codes generated by fixed-width vectorization.

Form your IR,

call void @llvm.masked.scatter.v4f32.v4p0(<4 x float> zeroinitializer, <4 x ptr> %1, i32 0, <4 x i1> undef)

I think this is not loop vectorization as scale-vector,set -mllvm -scalable-vectorization=off , may also core dump? Could you try it?

Yes, it will cause core dump even with -mllvm -scalable-vectorization=off, but will not if we remove -mllvm -riscv-v-vector-bits-max=128 -mllvm -riscv-v-vector-bits-min=128.
So, it seems that there are two problems here I guess:

  1. Some loops can't be vectorized by scalable vectorization and fixed-width vectorization is took as a fallback.
  2. There are some bugs in codes generated by fixed-width vectorization.

I Update the LLVM,
command: clang --target=riscv64-unknown-elf --sysroot=$HOME/task/rvv/riscv64-unknown-elf --gcc-toolchain=$HOME/task/rvv -march=rv64gcv -O2 -mllvm -riscv-v-vector-bits-max=128 -mllvm -riscv-v-vector-bits-min=128 -mllvm -scalable-vectorization=on tsc.c dummy.c -lm -o test.o , But not core dump? Could you see what happend?

Form your IR,

call void @llvm.masked.scatter.v4f32.v4p0(<4 x float> zeroinitializer, <4 x ptr> %1, i32 0, <4 x i1> undef)

I think this is not loop vectorization as scale-vector,set -mllvm -scalable-vectorization=off , may also core dump? Could you try it?

Yes, it will cause core dump even with -mllvm -scalable-vectorization=off, but will not if we remove -mllvm -riscv-v-vector-bits-max=128 -mllvm -riscv-v-vector-bits-min=128.
So, it seems that there are two problems here I guess:

  1. Some loops can't be vectorized by scalable vectorization and fixed-width vectorization is took as a fallback.
  2. There are some bugs in codes generated by fixed-width vectorization.

I Update the LLVM,
command: clang --target=riscv64-unknown-elf --sysroot=$HOME/task/rvv/riscv64-unknown-elf --gcc-toolchain=$HOME/task/rvv -march=rv64gcv -O2 -mllvm -riscv-v-vector-bits-max=128 -mllvm -riscv-v-vector-bits-min=128 -mllvm -scalable-vectorization=on tsc.c dummy.c -lm -o test.o , But not core dump? Could you see what happend?

I have tried again and got the same failure.

# clang -v
clang version 15.0.0 (f199b2b00fdbc7234cb6362fe487259eb339dff9)

Did you modify source files of TSVC? I commented one line at line 44 since it's not for RISCV before I compiled the source files you uploaded:

// #include <xmmintrin.h>

@reames can you take a look at this?

Happy to, but first I need a stand alone reproducer.

I tried your LL file, and did not see a crash on the following command line:
./llc -O3 -march=riscv64 < <your-ir>

Please provide the exact llc command line you saw a failure with.

pcwang-thead added a comment.EditedMay 31 2022, 7:52 PM

@reames can you take a look at this?

Happy to, but first I need a stand alone reproducer.

I tried your LL file, and did not see a crash on the following command line:
./llc -O3 -march=riscv64 < <your-ir>

Please provide the exact llc command line you saw a failure with.

Thanks! The command is: llc -O2 -march=riscv64 -mattr=+v -riscv-v-vector-bits-max=128 -riscv-v-vector-bits-min=128 reduced.ll. The key is that we will get crash if vector-bits is specified.
And here is an example on Compiler Explorer: https://godbolt.org/z/41x691Y6x

reames added a comment.Jun 2 2022, 8:18 AM

@reames can you take a look at this?

Happy to, but first I need a stand alone reproducer.

I tried your LL file, and did not see a crash on the following command line:
./llc -O3 -march=riscv64 < <your-ir>

Please provide the exact llc command line you saw a failure with.

Thanks! The command is: llc -O2 -march=riscv64 -mattr=+v -riscv-v-vector-bits-max=128 -riscv-v-vector-bits-min=128 reduced.ll. The key is that we will get crash if vector-bits is specified.
And here is an example on Compiler Explorer: https://godbolt.org/z/41x691Y6x

This appears to have been a duplicate of the issue fixed in dcdb0bf. Can you confirm that the original issue is resolved for you?

@reames can you take a look at this?

Happy to, but first I need a stand alone reproducer.

I tried your LL file, and did not see a crash on the following command line:
./llc -O3 -march=riscv64 < <your-ir>

Please provide the exact llc command line you saw a failure with.

Thanks! The command is: llc -O2 -march=riscv64 -mattr=+v -riscv-v-vector-bits-max=128 -riscv-v-vector-bits-min=128 reduced.ll. The key is that we will get crash if vector-bits is specified.
And here is an example on Compiler Explorer: https://godbolt.org/z/41x691Y6x

This appears to have been a duplicate of the issue fixed in dcdb0bf. Can you confirm that the original issue is resolved for you?

Yes! Thanks!