Skip to content
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

[x86_64] insertelement after extractelement for vxi1 crashes when targeting sapphirerapids / znver4 CPU #64439

Closed
HazyFish opened this issue Aug 4, 2023 · 2 comments
Assignees
Labels
backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@HazyFish
Copy link
Contributor

HazyFish commented Aug 4, 2023

Description

When targeting Intel sapphirerapids or AMD znver4 CPU, the following code crashes x86_64 backend with assertion Op.getScalarValueSizeInBits() == BitWidth && "Mask size mismatches value type size!" failed during TargetLowering::SimplifyDemandedBits in 'X86 DAG->DAG Instruction Selection' pass.

The problem doesn't exist when targeting znver3, alderlake, or raptorlake CPUs, or when CPU is not specified.

Minimal Reproduction

https://godbolt.org/z/s7jcjbfbr

Code

define void @f(ptr %0, <32 x i1> %1, i32 %2) {
BB:
  %E = extractelement <32 x i1> %1, i32 3
  %I = insertelement <32 x i1> %1, i1 %E, i32 %2
  store <32 x i1> %I, ptr %0
  ret void
}

Stack Trace

llc: /root/llvm-project/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:1075: bool llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, const llvm::APInt&, const llvm::APInt&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const: Assertion `Op.getScalarValueSizeInBits() == BitWidth && "Mask size mismatches value type size!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -mtriple=x86_64 -mcpu=znver4 <source>
1.	Running pass 'Function Pass Manager' on module '<source>'.
2.	Running pass 'X86 DAG->DAG Instruction Selection' on function '@f'
 #0 0x0000000003398418 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3398418)
 #1 0x0000000003395d0c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f6b2d987420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f6b2d44a00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f6b2d429859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f6b2d429729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f6b2d43afd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x00000000031cc515 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x31cc515)
 #8 0x0000000001d05986 llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x1d05986)
 #9 0x00000000031c3adb llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x31c3adb)
#10 0x00000000031c537e llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x31c537e)
#11 0x00000000031c4baa llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x31c4baa)
#12 0x0000000001d069f9 llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x1d069f9)
#13 0x00000000031c3adb llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x31c3adb)
#14 0x00000000031d7299 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x31d7299)
#15 0x00000000031d7459 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::TargetLowering::DAGCombinerInfo&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x31d7459)
#16 0x0000000001ce887e combineVectorShiftImm(llvm::SDNode*, llvm::SelectionDAG&, llvm::TargetLowering::DAGCombinerInfo&, llvm::X86Subtarget const&) X86ISelLowering.cpp:0:0
#17 0x0000000001cf5149 llvm::X86TargetLowering::PerformDAGCombine(llvm::SDNode*, llvm::TargetLowering::DAGCombinerInfo&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x1cf5149)
#18 0x0000000003019451 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) DAGCombiner.cpp:0:0
#19 0x000000000301af0c (anonymous namespace)::DAGCombiner::Run(llvm::CombineLevel) DAGCombiner.cpp:0:0
#20 0x000000000301d50c llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOpt::Level) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x301d50c)
#21 0x000000000316c6e7 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x316c6e7)
#22 0x000000000316ff88 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x316ff88)
#23 0x0000000003171c82 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#24 0x0000000001b894bc (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) X86ISelDAGToDAG.cpp:0:0
#25 0x0000000002680049 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#26 0x0000000002bf8bb9 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2bf8bb9)
#27 0x0000000002bf8df1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2bf8df1)
#28 0x0000000002bf9612 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2bf9612)
#29 0x000000000075e092 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#30 0x000000000069a7e6 main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x69a7e6)
#31 0x00007f6b2d42b083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#32 0x0000000000754a4e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x754a4e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
@HazyFish
Copy link
Contributor Author

HazyFish commented Aug 4, 2023

@DataCorrupted

@EugeneZelenko EugeneZelenko added backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Aug 4, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 4, 2023

@llvm/issue-subscribers-backend-x86

@RKSimon RKSimon self-assigned this Aug 5, 2023
@RKSimon RKSimon closed this as completed in ce2ec06 Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

4 participants