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

[BUG] Compiler crash in LLVM APIntOps::ScaleBitMask #3918

Open
adityasz opened this issue Dec 29, 2024 · 4 comments
Open

[BUG] Compiler crash in LLVM APIntOps::ScaleBitMask #3918

adityasz opened this issue Dec 29, 2024 · 4 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@adityasz
Copy link

Bug description

$ mojo build main.mojo
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0.	Running pass 'Function Pass Manager' on module ''.
1.	Running pass 'X86 DAG->DAG Instruction Selection' on function '@main'
 #0 0x0000559d94b3ae4b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) Signals.cpp:0:0
 #1 0x0000559d94b38da9 llvm::sys::RunSignalHandlers() Signals.cpp:0:0
 #2 0x0000559d94b3b4cd SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f6b96cec090 __restore_rt (/lib64/libc.so.6+0x1a090)
 #4 0x0000559d94ae6e8d llvm::APIntOps::ScaleBitMask(llvm::APInt const&, unsigned int, bool) APInt.cpp:0:0
 #5 0x0000559d938a7462 llvm::SelectionDAG::computeKnownBits(llvm::SDValue, llvm::APInt const&, unsigned int) const SelectionDAG.cpp:0:0
 #6 0x0000559d938a2dab llvm::SelectionDAG::computeKnownBits(llvm::SDValue, unsigned int) const SelectionDAG.cpp:0:0
 #7 0x0000559d938a4ff0 llvm::SelectionDAG::computeKnownBits(llvm::SDValue, llvm::APInt const&, unsigned int) const SelectionDAG.cpp:0:0
 #8 0x0000559d93a1031c llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const TargetLowering.cpp:0:0
 #9 0x0000559d93a097a4 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const TargetLowering.cpp:0:0
#10 0x0000559d93a0a06c llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const TargetLowering.cpp:0:0
#11 0x0000559d93a07032 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const TargetLowering.cpp:0:0
#12 0x0000559d92f7417c llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int) const X86ISelLowering.cpp:0:0
#13 0x0000559d93a0a81c llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const TargetLowering.cpp:0:0
#14 0x0000559d93a0630e llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const TargetLowering.cpp:0:0
#15 0x0000559d93a0617c llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::TargetLowering::DAGCombinerInfo&) const TargetLowering.cpp:0:0
#16 0x0000559d92fa9653 combineMOVMSK(llvm::SDNode*, llvm::SelectionDAG&, llvm::TargetLowering::DAGCombinerInfo&, llvm::X86Subtarget const&) X86ISelLowering.cpp:0:0
#17 0x0000559d92f781d3 llvm::X86TargetLowering::PerformDAGCombine(llvm::SDNode*, llvm::TargetLowering::DAGCombinerInfo&) const X86ISelLowering.cpp:0:0
#18 0x0000559d937b576b (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) DAGCombiner.cpp:0:0
#19 0x0000559d937b43ad llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) DAGCombiner.cpp:0:0
#20 0x0000559d939354ac llvm::SelectionDAGISel::CodeGenAndEmitDAG() SelectionDAGISel.cpp:0:0
#21 0x0000559d93934e45 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) SelectionDAGISel.cpp:0:0
#22 0x0000559d93932d6a llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) SelectionDAGISel.cpp:0:0
#23 0x0000559d93931641 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) SelectionDAGISel.cpp:0:0
#24 0x0000559d93616873 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) MachineFunctionPass.cpp:0:0
#25 0x0000559d945f3775 llvm::FPPassManager::runOnFunction(llvm::Function&) LegacyPassManager.cpp:0:0
#26 0x0000559d945fa504 llvm::FPPassManager::runOnModule(llvm::Module&) LegacyPassManager.cpp:0:0
#27 0x0000559d945f4411 llvm::legacy::PassManagerImpl::run(llvm::Module&) LegacyPassManager.cpp:0:0
#28 0x0000559d91d369bc void llvm::detail::UniqueFunctionBase<void>::CallImpl<compileOptimizedLLVMModuleToObject(M::KGEN::LLVMModuleAndContext, mlir::Location, llvm::TargetMachine&, std::mutex&, M::AsyncRT::Runtime&, bool, bool, M::KGEN::CompilationOptions, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey>>, std::optional<unsigned long>, std::optional<unsigned long>, unsigned int)::$_0>(void*) ObjectCompiler.cpp:0:0
#29 0x0000559d921c2ff1 void (anonymous namespace)::WorkQueueThread::runItemsImpl<(anonymous namespace)::WorkQueueThread::runOnThread()::$_0, (anonymous namespace)::WorkQueueThread::runOnThread()::$_1>((anonymous namespace)::WorkQueueThread::runOnThread()::$_0, (anonymous namespace)::WorkQueueThread::runOnThread()::$_1, bool, llvm::StringLiteral, llvm::StringLiteral) ThreadPoolWorkQueue.cpp:0:0
#30 0x0000559d921c28c7 (anonymous namespace)::WorkQueueThread::runOnThread() ThreadPoolWorkQueue.cpp:0:0
#31 0x00007f6b96fbab65 execute_native_thread_routine /home/conda/feedstock_root/build_artifacts/gcc_compilers_1729025086244/work/build/x86_64-conda-linux-gnu/libstdc++-v3/src/c++11/../../../../../libstdc++-v3/src/c++11/thread.cc:106:5
#32 0x00007f6b96d43148 start_thread (/lib64/libc.so.6+0x71148)
#33 0x00007f6b96dc70cc __GI___clone3 (/lib64/libc.so.6+0xf50cc)
mojo crashed!
Please file a bug report.
zsh: floating point exception (core dumped)  mojo build main.mojo

Steps to reproduce

from memory import bitcast

fn main():
    var x = SIMD[DType.uint8, 8](1)
    var y = bitcast[DType.bool](x)
    print(y)

System information

- Fedora 41 (Workstation)
- `mojo 25.1.0.dev2024122805 (3497ff0b)`
- `magic 0.5.1 - (based on pixi 0.37.0)` 


$ magic info
     Magic version: 0.5.1
System
------------
      Pixi version: 0.37.0
          Platform: linux-64
  Virtual packages: __unix=0=0
                  : __linux=6.12.5=0
                  : __glibc=2.40=0
                  : __cuda=12.4=0
                  : __archspec=1=skylake
         Cache dir: /home/aditya/.cache/rattler/cache
      Auth storage: /home/aditya/.rattler/credentials.json
  Config locations: No config files found

Global
------------
           Bin dir: /home/aditya/.local/share/modular/bin
   Environment dir: /home/aditya/.local/share/modular/envs
      Manifest dir: /home/aditya/.local/share/modular/manifests/pixi-global.toml
@adityasz adityasz added bug Something isn't working mojo-repo Tag all issues with this label labels Dec 29, 2024
@lattner
Copy link
Collaborator

lattner commented Dec 30, 2024

@npanchen Looks like an upstream LLVM bug. Could you take a look whenever you get a chance?

@soraros
Copy link
Contributor

soraros commented Dec 31, 2024

I think this is because the bitcast is invalid. xref

from memory import bitcast

fn main():
  print(f(0))

@no_inline
fn f(a: SIMD[DType.uint8, 8]) -> SIMD[DType.bool, 8]:
  return bitcast[DType.bool, 8](a)  # Invalid bitcast: %2 = bitcast <8 x i8> %0 to <8 x i1>

Copy link
Collaborator

lattner commented Jan 8, 2025

Ah yes, that would do it.

@npanchen
Copy link
Contributor

npanchen commented Jan 8, 2025

@npanchen Looks like an upstream LLVM bug. Could you take a look whenever you get a chance?

absolutely. At least we shouldn't crash like that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

4 participants