Issue 174606
Summary LoongArch64: crash in llvm::SelectionDAG::ReplaceAllUsesWith when emitting a SIMD code
Labels new issue
Assignees
Reporter marxin
    The following LLVM IR was generated by the Wasmer for the LoongArch64 architecture:

```llvmir
; ModuleID = '<anonymous module> function f0'
source_filename = "<anonymous module> function f0"
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "loongarch64-unknown-linux-musl"

; Function Attrs: nocallback nofree nosync nounwind strictfp willreturn memory(inaccessiblemem: readwrite)
declare <4 x float> @llvm.experimental.constrained.fadd.v4f32(<4 x float>, <4 x float>, metadata, metadata) #1

; Function Attrs: nocallback nofree nosync nounwind strictfp willreturn memory(inaccessiblemem: readwrite)
declare <2 x i1> @llvm.experimental.constrained.fcmp.v2f64(<2 x double>, <2 x double>, metadata, metadata) #1

; Function Attrs: uwtable(sync)
define dllexport i128 @f0(ptr nofree align 16 dereferenceable(332) %0, float %1, float %2) #7 section "__TEXT,wasmer_function"{
entry:
  %param_1 = alloca float, align 4
 %param_0 = alloca float, align 4
  store float %1, ptr %param_0, align 4
 store float %2, ptr %param_1, align 4
  br label %start_of_code

start_of_code:                                    ; preds = %entry
  %local_0_get = load float, ptr %param_0, align 4, !tbaa !2
  %3 = insertelement <4 x float> undef, float %local_0_get, i32 0
  %4 = shufflevector <4 x float> %3, <4 x float> undef, <4 x i32> zeroinitializer
 %5 = bitcast <4 x float> %4 to i128
  %local_1_get = load float, ptr %param_1, align 4, !tbaa !4
  %6 = insertelement <4 x float> undef, float %local_1_get, i32 0
  %7 = shufflevector <4 x float> %6, <4 x float> undef, <4 x i32> zeroinitializer
  %8 = bitcast <4 x float> %7 to i128
  %9 = bitcast i128 %5 to <4 x float>
  %10 = bitcast i128 %8 to <4 x float>
  %11 = call <4 x float> @llvm.minimum.v4f32(<4 x float> %9, <4 x float> %10)
 %12 = call <4 x i1> @llvm.experimental.constrained.fcmp.v4f32(<4 x float> %11, <4 x float> %11, metadata !"uno", metadata !"fpexcept.strict")
 %13 = call <4 x float> @llvm.experimental.constrained.fadd.v4f32(<4 x float> %11, <4 x float> zeroinitializer, metadata !"round.tonearest", metadata !"fpexcept.strict")
  %14 = select <4 x i1> %12, <4 x float> %13, <4 x float> %11
  %15 = bitcast <4 x float> %14 to i128
  br label %return

return:                                           ; preds = %start_of_code
  %16 = phi i128 [ %15, %start_of_code ]
  ret i128 %16
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind strictfp willreturn memory(inaccessiblemem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #3 = { cold noreturn nounwind memory(inaccessiblemem: write) }
attributes #4 = { nounwind }
attributes #5 = { nocallback nofree nosync willreturn }
attributes #6 = { noreturn }
attributes #7 = { uwtable(sync) "frame-pointer"="non-leaf" "probe-stack"="inline-asm" }

!wasmer_tbaa_root = !{!0}
!local\200 = !{!1}
!local\200_memop = !{!2}
!local\201 = !{!3}
!local\201_memop = !{!4}

!0 = !{}
!1 = !{!"local 0", !0}
!2 = !{!1, !1, i64 0}
!3 = !{!"local 1", !0}
!4 = !{!3, !3, i64 0}
```

Crashes with the current `main` tip (5ff486d08e97b0d63f9799381d407e69ec5b1e28):

```
$ bin/llc ~/Programming/testcases/function_0.preopt.ll
...
#5  0x000055555ac9b0f6 in (anonymous namespace)::SelectionDAGLegalize::ExpandNode (this=0x7fffffffc0f0, Node=0x555564fba470)
    at /home/marxin/Programming/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:4385
#6 0x000055555ac8229a in (anonymous namespace)::SelectionDAGLegalize::LegalizeOp (this=0x7fffffffc0f0, Node=0x555564fba470)
    at /home/marxin/Programming/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1379
#7 0x000055555acaa92b in llvm::SelectionDAG::Legalize (this=0x555564f90450)
 at /home/marxin/Programming/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:6227
#8 0x000055555adf721e in llvm::SelectionDAGISel::CodeGenAndEmitDAG (this=0x555564f8fba0)
    at /home/marxin/Programming/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1097
#9 0x000055555adf5b2f in llvm::SelectionDAGISel::SelectBasicBlock (this=0x555564f8fba0, Begin=..., End=..., HadTailCall=@0x7fffffffc5b0: false)
    at /home/marxin/Programming/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:896
#10 0x000055555adfbe21 in llvm::SelectionDAGISel::SelectAllBasicBlocks (this=0x555564f8fba0, Fn=...)
    at /home/marxin/Programming/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1932
#11 0x000055555adf41cd in llvm::SelectionDAGISel::runOnMachineFunction (this=0x555564f8fba0, mf=...)
    at /home/marxin/Programming/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:634
#12 0x000055555790bece in llvm::LoongArchDAGToDAGISel::runOnMachineFunction (this=0x555564f8fba0, MF=...)
    at /home/marxin/Programming/llvm-project/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h:36
#13 0x000055555adf2e48 in llvm::SelectionDAGISelLegacy::runOnMachineFunction (this=0x555564f51e50, MF=...)
    at /home/marxin/Programming/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:401
#14 0x0000555559987e99 in llvm::MachineFunctionPass::runOnFunction (this=0x555564f51e50, F=...)
    at /home/marxin/Programming/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:108
#15 0x000055555a271ef6 in llvm::FPPassManager::runOnFunction (this=0x555564f85f60, F=...)
    at /home/marxin/Programming/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1398
#16 0x000055555a2721c8 in llvm::FPPassManager::runOnModule (this=0x555564f85f60, M=...) at /home/marxin/Programming/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1444
#17 0x000055555a272612 in (anonymous namespace)::MPPassManager::runOnModule (this=0x555564f6fd90, M=...)
    at /home/marxin/Programming/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1513
#18 0x000055555a26d77e in llvm::legacy::PassManagerImpl::run (this=0x555564f7b650, M=...)
    at /home/marxin/Programming/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:531
#19 0x000055555a272edb in llvm::legacy::PassManager::run (this=0x7fffffffd330, M=...) at /home/marxin/Programming/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1640
#20 0x0000555556110920 in compileModule (argv=0x7fffffffdbe8, PluginList=..., Context=..., OutputFilename="/home/marxin/Programming/testcases/function_0.preopt.s")
 at /home/marxin/Programming/llvm-project/llvm/tools/llc/llc.cpp:872
#21 0x000055555610db07 in main (argc=2, argv=0x7fffffffdbe8) at /home/marxin/Programming/llvm-project/llvm/tools/llc/llc.cpp:462
```

CC: @SixWeining @heiher
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to