microsoft / microsoft/BitNet

LLVM bug triggered by BitNet's code patterns

Open
#294 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
40.3k
Forks
3.7k
PR merge metrics
No merged PRs in 30d

Description

On Apple M2 silicon it seems that the BitNet code is triggering a LLVM optimization bug. Others have reported this as the build running for hours: issue #251, #260, etc. I have observed this with Apple clang version 17.0.0 and Homebrew clang version 20.1.6. The issue is with InterleavedLoadCombine optimization pass and the specific vector shuffle patterns in the BitNet code. The same infinite recursion is happening with VectorInfo::computeFromSVI calling itself recursively. The fix for me was to disable the problematic optimization. With optimization disabled I was able to compile llama-cli and run inference.

diff setup_env.py setup_env.py.orig 
214,227c214
<     
<     # Add LLVM optimization flags to work around the interleaved load combine bug
<     llvm_fix_flags = "-O2 -mllvm -disable-interleaved-load-combine"
<     
<     run_command([
<         "cmake", "-B", "build", 
<         *COMPILER_EXTRA_ARGS[arch], 
<         *OS_EXTRA_ARGS.get(platform.system(), []), 
<         "-DCMAKE_C_COMPILER=clang", 
<         "-DCMAKE_CXX_COMPILER=clang++",
<         f"-DCMAKE_CXX_FLAGS={llvm_fix_flags}",
<         f"-DCMAKE_C_FLAGS={llvm_fix_flags}"
<     ], log_step="generate_build_files")
<     
---
>     run_command(["cmake", "-B", "build", *COMPILER_EXTRA_ARGS[arch], *OS_EXTRA_ARGS.get(platform.system(), []), "-DCMAKE_C_COMPILER=clang", "-DCMAKE_CXX_COMPILER=clang++"], log_step="generate_build_files")

Sample of clang.txt

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review setup_env.py around lines 214-227 and the CMake compiler-flag generation, then compare the reported Apple clang and Homebrew clang behavior with the linked clang.txt sample. A fix is complete when the Apple M2 build no longer hangs in InterleavedLoadCombine and llama-cli compiles and runs inference.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
build-system, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.