diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 57ee1c8a6726..120618563e47 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1280,6 +1280,8 @@ pub const Object = struct { .tsan = options.sanitize_thread, .sancov = options.fuzz, .lto = options.lto, + // https://github.com/ziglang/zig/issues/21215 + .allow_fast_isel = !comp.root_mod.resolved_target.result.cpu.arch.isMIPS(), .asm_filename = null, .bin_filename = options.bin_path, .llvm_ir_filename = options.post_ir_path, diff --git a/src/codegen/llvm/bindings.zig b/src/codegen/llvm/bindings.zig index a5017568e541..08c5b0b0555d 100644 --- a/src/codegen/llvm/bindings.zig +++ b/src/codegen/llvm/bindings.zig @@ -91,6 +91,7 @@ pub const TargetMachine = opaque { tsan: bool, sancov: bool, lto: bool, + allow_fast_isel: bool, asm_filename: ?[*:0]const u8, bin_filename: ?[*:0]const u8, llvm_ir_filename: ?[*:0]const u8, diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index b6b6d05f5760..9465168dbdcd 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -258,7 +258,6 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi options.bin_filename? options.bin_filename : options.asm_filename); TargetMachine &target_machine = *reinterpret_cast(targ_machine_ref); - target_machine.setO0WantsFastISel(true); Module &llvm_module = *unwrap(module_ref); @@ -369,6 +368,12 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi } } + if (options.allow_fast_isel) { + target_machine.setO0WantsFastISel(true); + } else { + target_machine.setFastISel(false); + } + // Optimization phase module_pm.run(llvm_module, module_am); diff --git a/src/zig_llvm.h b/src/zig_llvm.h index cdc2adfb6d30..0935c780add9 100644 --- a/src/zig_llvm.h +++ b/src/zig_llvm.h @@ -59,6 +59,7 @@ struct ZigLLVMEmitOptions { bool tsan; bool sancov; bool lto; + bool allow_fast_isel; const char *asm_filename; const char *bin_filename; const char *llvm_ir_filename;