From d8fc8d0118a6ae99c0298d584faf1d8b5c6712c4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 5 Jul 2022 21:28:39 -0700 Subject: [PATCH] compiler_rt: work around LLVM optimizing __muloti4 to call itself This is a workaround for https://github.com/llvm/llvm-project/issues/56403 --- lib/compiler_rt/mulo.zig | 9 +++++++++ test/behavior/math.zig | 8 -------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/compiler_rt/mulo.zig b/lib/compiler_rt/mulo.zig index cd2d127c34..8347a1fbe8 100644 --- a/lib/compiler_rt/mulo.zig +++ b/lib/compiler_rt/mulo.zig @@ -65,6 +65,15 @@ pub fn __mulodi4(a: i64, b: i64, overflow: *c_int) callconv(.C) i64 { } pub fn __muloti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 { + switch (builtin.zig_backend) { + .stage1, .stage2_llvm => { + // Workaround for https://github.com/llvm/llvm-project/issues/56403 + // When we call the genericSmall implementation instead, LLVM optimizer + // optimizes __muloti4 to a call to itself. + return muloXi4_genericFast(i128, a, b, overflow); + }, + else => {}, + } if (2 * @bitSizeOf(i128) <= @bitSizeOf(usize)) { return muloXi4_genericFast(i128, a, b, overflow); } else { diff --git a/test/behavior/math.zig b/test/behavior/math.zig index c7a1967204..7b280bca4e 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -609,14 +609,6 @@ test "128-bit multiplication" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO - if ((builtin.zig_backend == .stage1 or builtin.zig_backend == .stage2_llvm) and - builtin.cpu.arch == .wasm32) - { - // TODO This regressed with LLVM 14 due to the __muloti4 compiler-rt symbol - // being lowered to call itself despite having the "nobuiltin" attribute. - return error.SkipZigTest; - } - var a: i128 = 3; var b: i128 = 2; var c = a * b;