From 5e1a7f1a9735127b20638816d9ee7f4d332ad8f9 Mon Sep 17 00:00:00 2001 From: Ayush Ojha Date: Sun, 1 Feb 2026 00:01:17 -0800 Subject: [PATCH] Work around LLVM optimization bug on Apple Silicon LLVM's InterleavedLoadCombine pass triggers infinite recursion when compiling BitNet's vector shuffle patterns on Apple Silicon, causing builds to hang indefinitely. This affects both Apple Clang and Homebrew Clang (reported with versions 17.0.0 through 20.1.6). Added -mllvm -disable-interleaved-load-combine to CMAKE_C_FLAGS and CMAKE_CXX_FLAGS, scoped to Darwin + arm64 only. Fixes #294 --- setup_env.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/setup_env.py b/setup_env.py index 3bf5fb8f7..ea33feb81 100644 --- a/setup_env.py +++ b/setup_env.py @@ -211,7 +211,15 @@ def compile(): logging.error(f"Arch {arch} is not supported yet") exit(0) logging.info("Compiling the code using CMake.") - 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") + cmake_args = ["cmake", "-B", "build", *COMPILER_EXTRA_ARGS[arch], *OS_EXTRA_ARGS.get(platform.system(), []), "-DCMAKE_C_COMPILER=clang", "-DCMAKE_CXX_COMPILER=clang++"] + + # Work around LLVM InterleavedLoadCombine optimization bug on Apple Silicon + # that causes infinite recursion during compilation (see issue #294, #251, #260) + if platform.system() == "Darwin" and arch == "arm64": + llvm_flags = "-mllvm -disable-interleaved-load-combine" + cmake_args += [f"-DCMAKE_C_FLAGS={llvm_flags}", f"-DCMAKE_CXX_FLAGS={llvm_flags}"] + + run_command(cmake_args, log_step="generate_build_files") # run_command(["cmake", "--build", "build", "--target", "llama-cli", "--config", "Release"]) run_command(["cmake", "--build", "build", "--config", "Release"], log_step="compile")