From 53083c7ac06d7377096e5fecddf24dcc7d465fc3 Mon Sep 17 00:00:00 2001 From: "halide-ci[bot]" <266445882+halide-ci[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:31:40 +0000 Subject: [PATCH 1/4] Upgrade halide-llvm to 24.0.0.dev122887+gc01eb67c --- uv.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/uv.lock b/uv.lock index fcb9b098e549..3d884aae8a64 100644 --- a/uv.lock +++ b/uv.lock @@ -448,7 +448,7 @@ wheels = [ [[package]] name = "halide-llvm" -version = "24.0.0.dev117054+g7e2f1c59" +version = "24.0.0.dev122887+gc01eb67c" source = { registry = "https://pypi.halide-lang.org/simple" } resolution-markers = [ "python_full_version >= '3.13' and (platform_machine == 'armv7l' or platform_machine == 'armv8l')", @@ -456,14 +456,14 @@ resolution-markers = [ "python_full_version < '3.13' and platform_machine != 'armv7l' and platform_machine != 'armv8l'", ] wheels = [ - { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev117054%2Bg7e2f1c59/halide_llvm-24.0.0.dev117054%2Bg7e2f1c59-py3-none-macosx_11_0_arm64.whl", hash = "sha256:1a7b8d556cb6a1c968a03f654279fa772beff6ef47e5586e4e1d56944314496e" }, - { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev117054%2Bg7e2f1c59/halide_llvm-24.0.0.dev117054%2Bg7e2f1c59-py3-none-macosx_11_0_x86_64.whl", hash = "sha256:c40b9e3beadda19e3db9cf309536cf0263513f559048bfeca4c703a998004e03" }, - { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev117054%2Bg7e2f1c59/halide_llvm-24.0.0.dev117054%2Bg7e2f1c59-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9f652f7684db96a54611aa5d95efc9579e6f8baaa4a0ca482088259a7befed34" }, - { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev117054%2Bg7e2f1c59/halide_llvm-24.0.0.dev117054%2Bg7e2f1c59-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:228b211fa5be423b2f471a1120802f6422e12a9689de7bb2f4fb54feeb50252b" }, - { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev117054%2Bg7e2f1c59/halide_llvm-24.0.0.dev117054%2Bg7e2f1c59-py3-none-manylinux_2_28_i686.whl", hash = "sha256:9e9ae338da164c917d55e7f6a3b2b2d3431525298574a23aa52a98e3e621813d" }, - { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev117054%2Bg7e2f1c59/halide_llvm-24.0.0.dev117054%2Bg7e2f1c59-py3-none-manylinux_2_31_armv7l.whl", hash = "sha256:6f646fac7fa4c277f8c238d2a582972f4d4cb950db150b0edc887a9f448bf57d" }, - { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev117054%2Bg7e2f1c59/halide_llvm-24.0.0.dev117054%2Bg7e2f1c59-py3-none-win32.whl", hash = "sha256:293922e9a52905b96e8a52d5b0c7207df6a51c13bf6b0a49b2408a0da516548d" }, - { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev117054%2Bg7e2f1c59/halide_llvm-24.0.0.dev117054%2Bg7e2f1c59-py3-none-win_amd64.whl", hash = "sha256:9adb786f550a4c5d46525e845ca5dd3011243faf099dc9fc7435c52bdbc2f986" }, + { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev122887%2Bgc01eb67c/halide_llvm-24.0.0.dev122887%2Bgc01eb67c-py3-none-macosx_11_0_arm64.whl", hash = "sha256:f19e4671d5c038333eda0ace75c06581dfa6c1808ce6edce2304f47442edef45" }, + { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev122887%2Bgc01eb67c/halide_llvm-24.0.0.dev122887%2Bgc01eb67c-py3-none-macosx_11_0_x86_64.whl", hash = "sha256:4af6ed04801a917ff7fb5041662a09299c7307ebdce9ae9291d99bc4bc09fc6b" }, + { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev122887%2Bgc01eb67c/halide_llvm-24.0.0.dev122887%2Bgc01eb67c-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:bb4d7996a04f99ca981a9ff129e870af7cc5a8ef8e4fc051653082a0ff19ac32" }, + { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev122887%2Bgc01eb67c/halide_llvm-24.0.0.dev122887%2Bgc01eb67c-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3dc5273776c5054e3b982b591563821b528aba9108fc5551eb3cece5a6ef6071" }, + { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev122887%2Bgc01eb67c/halide_llvm-24.0.0.dev122887%2Bgc01eb67c-py3-none-manylinux_2_28_i686.whl", hash = "sha256:c10339037a8797c464007fddd44b7dab17d3d16b0bc7decb4acedc0851ae7c5f" }, + { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev122887%2Bgc01eb67c/halide_llvm-24.0.0.dev122887%2Bgc01eb67c-py3-none-manylinux_2_31_armv7l.whl", hash = "sha256:02bf95616e92cc525003abb737ddf9de3cef433a79a965c35ee31ff6fa720d14" }, + { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev122887%2Bgc01eb67c/halide_llvm-24.0.0.dev122887%2Bgc01eb67c-py3-none-win32.whl", hash = "sha256:85c0b470753c0876121b56a2263063696412aedfdfda626169954c8af0ddcb6b" }, + { url = "https://github.com/halide/pypi/releases/download/halide-llvm%4024.0.0.dev122887%2Bgc01eb67c/halide_llvm-24.0.0.dev122887%2Bgc01eb67c-py3-none-win_amd64.whl", hash = "sha256:4a437091d32c6b0197974db0a753832f4f7ece7e0008247ad75e2c125511db26" }, ] [[package]] @@ -562,7 +562,7 @@ ci-llvm-23 = [ ci-llvm-main = [ { name = "abi3audit" }, { name = "cmake" }, - { name = "halide-llvm", version = "24.0.0.dev117054+g7e2f1c59", source = { registry = "https://pypi.halide-lang.org/simple" } }, + { name = "halide-llvm", version = "24.0.0.dev122887+gc01eb67c", source = { registry = "https://pypi.halide-lang.org/simple" } }, { name = "imageio", version = "2.37.4", source = { registry = "https://piwheels.org/simple" }, marker = "(platform_machine == 'armv7l' or platform_machine == 'armv8l' or extra == 'group-16-halide-workspace-ci-llvm-23') and extra == 'group-16-halide-workspace-ci-llvm-main' or extra == 'group-16-halide-workspace-ci-llvm-22' and (extra == 'group-16-halide-workspace-ci-llvm-23' or extra == 'group-16-halide-workspace-ci-llvm-main')" }, { name = "imageio", version = "2.38.1", source = { registry = "https://pypi.org/simple" }, marker = "platform_machine != 'armv7l' and platform_machine != 'armv8l' and extra == 'group-16-halide-workspace-ci-llvm-main' or extra == 'group-16-halide-workspace-ci-llvm-22' and (extra == 'group-16-halide-workspace-ci-llvm-23' or extra == 'group-16-halide-workspace-ci-llvm-main') or extra == 'group-16-halide-workspace-ci-llvm-23' and extra == 'group-16-halide-workspace-ci-llvm-main'" }, { name = "imageio-ffmpeg" }, From 8e86a8f7aa676ae34176f1e79f69b66d66e35cb0 Mon Sep 17 00:00:00 2001 From: Alex Reinking Date: Mon, 23 Nov 2026 16:06:43 -0500 Subject: [PATCH 2/4] Include after LLVM_Headers.h in JITModule.cpp Upstream LLVM commit d8cdd9b226 (PR #243316) moved StringTableBuilder::add inline and added #include "llvm/BinaryFormat/COFF.h" to StringTableBuilder.h, which is transitively included by LLVM_Headers.h via BitcodeWriter.h. When is included first, macros in (such as IMAGE_FILE_MACHINE_UNKNOWN) collide with enum declarations in llvm/BinaryFormat/COFF.h. Move the block after LLVM_Headers.h, matching LLVM_Output.cpp. --- src/JITModule.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/JITModule.cpp b/src/JITModule.cpp index 91638578f4f0..1da39925b336 100644 --- a/src/JITModule.cpp +++ b/src/JITModule.cpp @@ -4,16 +4,6 @@ #include #include -#ifdef _WIN32 -#ifdef _MSC_VER -#define NOMINMAX -#endif -#include -#else -#include -#include -#endif - #include "CodeGen_Internal.h" #include "CodeGen_LLVM.h" #include "Debug.h" @@ -25,6 +15,18 @@ #include "Util.h" #include "WasmExecutor.h" +// Must be included after LLVM_Headers.h because defines macros +// (e.g. IMAGE_FILE_MACHINE_UNKNOWN) that conflict with llvm/BinaryFormat/COFF.h. +#ifdef _WIN32 +#ifdef _MSC_VER +#define NOMINMAX +#endif +#include +#else +#include +#include +#endif + namespace Halide { namespace Internal { From 49f4ca06d3989858ccbd82c41f23c60db18fab84 Mon Sep 17 00:00:00 2001 From: Alex Reinking Date: Mon, 23 Nov 2026 17:10:11 -0500 Subject: [PATCH 3/4] Parse HL_LLVM_ARGS with LibraryOptionsContext on LLVM 24+ In LLVM 24, cl::ParseCommandLineOptions no longer recognizes library options declared in TableGen (such as MachineScheduler's -misched-regpressure, migrated in upstream PR #244327). Parse HL_LLVM_ARGS via cl::parseCommandLineOptions into a shared LibraryOptionsContext, assign it to LLVMContexts used for compilation, and attach it to TargetOptions::MCOptions::LibraryOptions (replaying it after -aarch64-use-featcpa-codegen=true for arm64e_x1 modules). --- src/CodeGen_Internal.cpp | 60 ++++++++++++++++++---------------------- src/CodeGen_Internal.h | 11 ++++++++ src/CodeGen_LLVM.cpp | 7 +++++ src/CodeGen_PTX_Dev.cpp | 3 ++ src/JITModule.cpp | 3 ++ 5 files changed, 51 insertions(+), 33 deletions(-) diff --git a/src/CodeGen_Internal.cpp b/src/CodeGen_Internal.cpp index 4c2232a93745..e8f3f14b2bad 100644 --- a/src/CodeGen_Internal.cpp +++ b/src/CodeGen_Internal.cpp @@ -622,40 +622,23 @@ const llvm::cl::LibraryOptionsContext *get_arm64e_x1_library_options() { static std::once_flag init_once; std::call_once(init_once, []() { CodeGen_LLVM::initialize_llvm(); - std::vector env_tokens; - std::string env_args = get_env_variable("HL_LLVM_ARGS"); - if (!env_args.empty()) { - env_tokens = split_string(env_args, " "); - } - std::vector c_args = {"llc"}; - bool next_is_featcpa_value = false; - for (const std::string &tok : env_tokens) { - if (tok.empty()) { - continue; - } - if (next_is_featcpa_value) { - next_is_featcpa_value = false; - if (tok[0] != '-') { - c_args.push_back(tok.c_str()); - continue; - } - } - llvm::StringRef stripped(tok); - stripped.consume_front("-"); - stripped.consume_front("-"); - if (stripped.starts_with("aarch64-use-featcpa-codegen")) { - c_args.push_back(tok.c_str()); - next_is_featcpa_value = !stripped.contains('='); - } - } - if (c_args.size() == 1) { - c_args.push_back("-aarch64-use-featcpa-codegen=true"); - } + const llvm::cl::LibraryOptionsContext &base = get_llvm_library_options(); // In LLVM 24+, target backend flags migrated from cl::opt to per-context // TableGen LibraryOptions read from TargetOptions::MCOptions::LibraryOptions. - // Pass &llvm::nulls() so this stays non-fatal if a future LLVM release - // enables CPA codegen unconditionally and removes the flag. - llvm::cl::parseCommandLineOptions(ctx, c_args, "Halide compiler\n", &llvm::nulls()); + // Enable aarch64-use-featcpa-codegen first, then replay any LibraryOptions + // parsed from HL_LLVM_ARGS so explicit user overrides still win and other + // HL_LLVM_ARGS flags remain active. Pass &llvm::nulls() so this stays + // non-fatal if a future LLVM release enables CPA codegen unconditionally + // and removes the flag. + std::vector default_args = {"llc", "-aarch64-use-featcpa-codegen=true"}; + llvm::cl::parseCommandLineOptions(ctx, default_args, "Halide compiler\n", &llvm::nulls()); + if (!base.args().empty()) { + std::vector replay_args; + replay_args.reserve(base.args().size() + 1); + replay_args.push_back("llc"); + replay_args.insert(replay_args.end(), base.args().begin(), base.args().end()); + llvm::cl::parseCommandLineOptions(ctx, replay_args, "Halide compiler\n", &llvm::nulls()); + } }); return &ctx; } @@ -663,6 +646,13 @@ const llvm::cl::LibraryOptionsContext *get_arm64e_x1_library_options() { } // namespace +#if LLVM_VERSION >= 240 +llvm::cl::LibraryOptionsContext &get_llvm_library_options() { + static llvm::cl::LibraryOptionsContext ctx; + return ctx; +} +#endif + void get_target_options(const llvm::Module &module, llvm::TargetOptions &options) { std::string mabi = get_modflag_string(module, "halide_mabi"); @@ -685,11 +675,15 @@ void get_target_options(const llvm::Module &module, llvm::TargetOptions &options options.UseInitArray = true; options.MCOptions.X86RelaxRelocations = false; options.MCOptions.ABIName = mabi; -#if defined(WITH_AARCH64) && LLVM_VERSION >= 240 +#if LLVM_VERSION >= 240 + CodeGen_LLVM::initialize_llvm(); + options.MCOptions.LibraryOptions = &get_llvm_library_options(); +#ifdef WITH_AARCH64 if (get_modflag_bool(module, "halide_arm64e_x1")) { options.MCOptions.LibraryOptions = get_arm64e_x1_library_options(); } #endif +#endif } void clone_target_options(const llvm::Module &from, llvm::Module &to) { diff --git a/src/CodeGen_Internal.h b/src/CodeGen_Internal.h index d1c3662ccb04..05a024018c05 100644 --- a/src/CodeGen_Internal.h +++ b/src/CodeGen_Internal.h @@ -29,6 +29,11 @@ class Type; class Value; template class IRBuilder; +#if LLVM_VERSION >= 240 +namespace cl { +class LibraryOptionsContext; +} // namespace cl +#endif } // namespace llvm namespace Halide { @@ -98,6 +103,12 @@ Expr lower_round_half_away_from_zero(const Expr &); /** Given an llvm::Module, set llvm:TargetOptions information */ void get_target_options(const llvm::Module &module, llvm::TargetOptions &options); +#if LLVM_VERSION >= 240 +/** Return the process-wide LLVM LibraryOptionsContext populated from + * HL_LLVM_ARGS during CodeGen_LLVM::initialize_llvm(). */ +llvm::cl::LibraryOptionsContext &get_llvm_library_options(); +#endif + /** Given two llvm::Modules, clone target options from one to the other */ void clone_target_options(const llvm::Module &from, llvm::Module &to); diff --git a/src/CodeGen_LLVM.cpp b/src/CodeGen_LLVM.cpp index 7aaf6aec8893..45028ffd98dd 100644 --- a/src/CodeGen_LLVM.cpp +++ b/src/CodeGen_LLVM.cpp @@ -207,6 +207,9 @@ CodeGen_LLVM::CodeGen_LLVM(const Target &t) void CodeGen_LLVM::set_context(llvm::LLVMContext &context) { this->context = &context; +#if LLVM_VERSION >= 240 + context.getLibraryOptions().assign(get_llvm_library_options()); +#endif set_effective_vscale(target_vscale()); } @@ -284,7 +287,11 @@ void CodeGen_LLVM::initialize_llvm() { c_arg_vec.push_back(s.c_str()); } } +#if LLVM_VERSION >= 240 + cl::parseCommandLineOptions(get_llvm_library_options(), c_arg_vec, "Halide compiler\n"); +#else cl::ParseCommandLineOptions((int)(c_arg_vec.size()), &c_arg_vec[0], "Halide compiler\n"); +#endif } }); } diff --git a/src/CodeGen_PTX_Dev.cpp b/src/CodeGen_PTX_Dev.cpp index cc2100b04654..b42edae3e218 100644 --- a/src/CodeGen_PTX_Dev.cpp +++ b/src/CodeGen_PTX_Dev.cpp @@ -185,6 +185,9 @@ class CodeGen_PTX_Dev : public CodeGen_LLVM, public CodeGen_GPU_Dev { CodeGen_PTX_Dev::CodeGen_PTX_Dev(const Target &host) : CodeGen_LLVM(host) { context = new llvm::LLVMContext(); +#if LLVM_VERSION >= 240 + context->getLibraryOptions().assign(get_llvm_library_options()); +#endif } CodeGen_PTX_Dev::~CodeGen_PTX_Dev() { diff --git a/src/JITModule.cpp b/src/JITModule.cpp index 1da39925b336..c3ff9d1ccd9b 100644 --- a/src/JITModule.cpp +++ b/src/JITModule.cpp @@ -364,6 +364,9 @@ void compile_module_impl( // Ensure that LLVM is initialized CodeGen_LLVM::initialize_llvm(); +#if LLVM_VERSION >= 240 + m->getContext().getLibraryOptions().assign(get_llvm_library_options()); +#endif if (!WasmModule::can_jit_target(target)) { auto pac_abi = [](const Target &x) { From 63ef94a81de929198f388a237b864c8f0ef762a7 Mon Sep 17 00:00:00 2001 From: Alex Reinking Date: Mon, 23 Nov 2026 17:10:11 -0500 Subject: [PATCH 4/4] Slice wide SVE interleaved loads to native width on LLVM 24+ Upstream LLVM PR #234342 removed AArch64TargetLowering's IR-level lowerDeinterleaveIntrinsicToLoad(), relying on post-legalize SelectionDAG combining for multi-vector SVE deinterleaves. Under a fixed vscale_range (such as vector_bits_128), type legalization folds split load offsets to fixed constants, causing areNonVolatileConsecutiveLoads() to fail when comparing against scalable byte offsets and falling back to ldp + uzp1/uzp2. Slice interleaved loads to native_vector_bits() / op->type.bits() for SVE as well as NEON on LLVM 24+ so each chunk matches the pre-legalize performVectorDeinterleaveCombine() directly. --- src/CodeGen_ARM.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/CodeGen_ARM.cpp b/src/CodeGen_ARM.cpp index b21d5ea12ea1..dc1cf9e25531 100644 --- a/src/CodeGen_ARM.cpp +++ b/src/CodeGen_ARM.cpp @@ -2086,10 +2086,13 @@ void CodeGen_ARM::visit(const Shuffle *op) { #if LLVM_VERSION >= 240 // LLVM 24 folds slices into deinterleave shuffles, obscuring the - // interleaved-load pattern. Load one native-width result at a time. + // interleaved-load pattern, and removed InterleavedAccessPass lowering + // of multi-vector SVE deinterleave intrinsics (whose post-legalize DAG + // combine fails to match consecutive loads under vscale_range). Load + // one native-width result at a time. const Ramp *ramp = load->index.as(); internal_assert(ramp && is_const_one(ramp->stride)); - const int native_lanes = target_vscale() == 0 ? native_vector_bits() / op->type.bits() : op->type.lanes(); + const int native_lanes = native_vector_bits() / op->type.bits(); vector slices; for (int i = 0; i < op->type.lanes(); i += native_lanes) { const int slice_lanes = std::min(native_lanes, op->type.lanes() - i);