Skip to content

Instantly share code, notes, and snippets.

@Artem-B
Created October 16, 2020 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Artem-B/98a4420dda4f0c36364ddc170a8b12c5 to your computer and use it in GitHub Desktop.
Save Artem-B/98a4420dda4f0c36364ddc170a8b12c5 to your computer and use it in GitHub Desktop.
LLVM crash repro
; ModuleID = 'x2.bc'
source_filename = "merged_12-9d953f.hip.i.cc"
target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32: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-ni:7"
target triple = "amdgcn-amd-amdhsa"
%struct.wibble = type { <4 x float> }
%struct.wombat = type { float }
@global = external hidden addrspace(1) global %struct.wibble*, align 8
; Function Attrs: convergent norecurse nounwind
define protected amdgpu_kernel void @widget() local_unnamed_addr #0 {
bb:
%tmp = alloca %struct.wombat, align 4, addrspace(5)
%tmp1 = addrspacecast %struct.wombat addrspace(5)* %tmp to %struct.wombat*
%tmp2 = bitcast %struct.wombat addrspace(5)* %tmp to i8 addrspace(5)*
call void @llvm.lifetime.start.p5i8(i64 4, i8 addrspace(5)* %tmp2) #3
call void @barney(%struct.wombat* %tmp1) #4
%tmp3 = getelementptr inbounds %struct.wombat, %struct.wombat* %tmp1, i64 0, i32 0
%tmp4 = load float, float* %tmp3, align 4, !tbaa !3
%tmp5 = insertelement <4 x float> undef, float %tmp4, i32 0
%tmp6 = shufflevector <4 x float> %tmp5, <4 x float> undef, <4 x i32> zeroinitializer
%tmp7 = load <4 x float>*, <4 x float>** addrspacecast (<4 x float>* addrspace(1)* bitcast (%struct.wibble* addrspace(1)* @global to <4 x float>* addrspace(1)*) to <4 x float>**), align 8, !tbaa !8
store <4 x float> %tmp6, <4 x float>* %tmp7, align 16, !tbaa.struct !10
call void @llvm.lifetime.end.p5i8(i64 4, i8 addrspace(5)* %tmp2) #3
ret void
}
; Function Attrs: argmemonly nounwind willreturn
declare void @llvm.lifetime.start.p5i8(i64 immarg, i8 addrspace(5)* nocapture) #1
; Function Attrs: convergent nounwind
declare hidden void @barney(%struct.wombat*) #2
; Function Attrs: argmemonly nounwind willreturn
declare void @llvm.lifetime.end.p5i8(i64 immarg, i8 addrspace(5)* nocapture) #1
attributes #0 = { convergent norecurse nounwind "amdgpu-flat-work-group-size"="1,1024" "amdgpu-implicitarg-num-bytes"="56" "denormal-fp-math-f32"="preserve-sign,preserve-sign" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx803" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+s-memrealtime" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { argmemonly nounwind willreturn }
attributes #2 = { convergent nounwind "denormal-fp-math-f32"="preserve-sign,preserve-sign" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx803" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+s-memrealtime" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #3 = { convergent nounwind "denormal-fp-math-f32"="preserve-sign,preserve-sign" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx803" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+s-memrealtime" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #4 = { nounwind }
!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 1}
!2 = !{!"clang version 12.0.0"}
!3 = !{!4, !5, i64 0}
!4 = !{!"_ZTS1c", !5, i64 0}
!5 = !{!"float", !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{i64 0, i64 16, !11}
!11 = !{!6, !6, i64 0}
@Artem-B
Copy link
Author

Artem-B commented Oct 16, 2020

Reproduce with

bin/opt -mtriple amdgcn-amd-amdhsa -passes='default<O3>' x2.ll

@Artem-B
Copy link
Author

Artem-B commented Oct 16, 2020

Stack:

opt: /home/foo/llvm/repo/llvm/lib/IR/Instructions.cpp:2914: static llvm::CastInst *llvm::CastInst::Create(Instruction::CastOps, llvm::Value *, llvm::Type *, const llvm::Twine &, llvm::Instruction *): Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/foo/llvm/build/debug/bin/opt -mtriple amdgcn-amd-amdhsa -passes=default<O3> x1.ll
 #0 0x0000000007248e0c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/foo/llvm/repo/llvm/lib/Support/Unix/Signals.inc:563:11
 #1 0x0000000007248fdb PrintStackTraceSignalHandler(void*) /home/foo/llvm/repo/llvm/lib/Support/Unix/Signals.inc:630:1
 #2 0x0000000007247556 llvm::sys::RunSignalHandlers() /home/foo/llvm/repo/llvm/lib/Support/Signals.cpp:70:5
 #3 0x0000000007249753 SignalHandler(int) /home/foo/llvm/repo/llvm/lib/Support/Unix/Signals.inc:405:1
 #4 0x00007ffff7f97140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14140)
 #5 0x00007ffff7a6fdb1 raise ./signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #6 0x00007ffff7a59537 abort ./stdlib/abort.c:81:7
 #7 0x00007ffff7a5940f get_sysdep_segment_value ./intl/loadmsgcat.c:509:8
 #8 0x00007ffff7a5940f _nl_load_domain ./intl/loadmsgcat.c:970:34
 #9 0x00007ffff7a685b2 (/lib/x86_64-linux-gnu/libc.so.6+0x345b2)
#10 0x0000000006631d42 llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::Instruction*) /home/foo/llvm/repo/llvm/lib/IR/Instructions.cpp:2916:11
#11 0x00000000040e24d4 llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&) /home/foo/llvm/repo/llvm/include/llvm/IR/IRBuilder.h:2110:52
#12 0x00000000040cfe42 llvm::IRBuilderBase::CreateBitCast(llvm::Value*, llvm::Type*, llvm::Twine const&) /home/foo/llvm/repo/llvm/include/llvm/IR/IRBuilder.h:2069:5
#13 0x00000000074e0e38 (anonymous namespace)::VectorCombine::vectorizeLoadInsert(llvm::Instruction&) /home/foo/llvm/repo/llvm/lib/Transforms/Vectorize/VectorCombine.cpp:150:10
#14 0x00000000074e05c9 (anonymous namespace)::VectorCombine::run() /home/foo/llvm/repo/llvm/lib/Transforms/Vectorize/VectorCombine.cpp:709:21
#15 0x00000000074e0321 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/foo/llvm/repo/llvm/lib/Transforms/Vectorize/VectorCombine.cpp:773:7
#16 0x00000000075d9a1b llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/foo/llvm/repo/llvm/include/llvm/IR/PassManagerInternal.h:85:5
#17 0x00000000066e07bf llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/foo/llvm/repo/llvm/include/llvm/IR/PassManager.h:517:16
#18 0x00000000049b95c7 llvm::ModuleToFunctionPassAdaptor<llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> > >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/foo/llvm/repo/llvm/include/llvm/IR/PassManager.h:1258:16
#19 0x00000000049b93eb llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor<llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> > >, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/foo/llvm/repo/llvm/include/llvm/IR/PassManagerInternal.h:85:5
#20 0x00000000066df7dc llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/foo/llvm/repo/llvm/include/llvm/IR/PassManager.h:517:16
#21 0x0000000003d6b644 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::StringRef>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) /home/foo/llvm/repo/llvm/tools/opt/NewPMDriver.cpp:428:3
#22 0x0000000003da2103 main /home/foo/llvm/repo/llvm/tools/opt/opt.cpp:792:12
#23 0x00007ffff7a5acca __libc_start_main ./csu/../csu/libc-start.c:308:16
#24 0x0000000003d6502a _start (/home/foo/llvm/build/debug/bin/opt+0x3d6502a)
[1]    1582920 abort      /home/foo/llvm/build/debug/bin/opt -mtriple   x1.ll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment