Skip to content

Commit d8fc8d0

Browse files
committed
compiler_rt: work around LLVM optimizing __muloti4 to call itself
This is a workaround for llvm/llvm-project#56403
1 parent 558ad19 commit d8fc8d0

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/compiler_rt/mulo.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ pub fn __mulodi4(a: i64, b: i64, overflow: *c_int) callconv(.C) i64 {
6565
}
6666

6767
pub fn __muloti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
68+
switch (builtin.zig_backend) {
69+
.stage1, .stage2_llvm => {
70+
// Workaround for https://github.com/llvm/llvm-project/issues/56403
71+
// When we call the genericSmall implementation instead, LLVM optimizer
72+
// optimizes __muloti4 to a call to itself.
73+
return muloXi4_genericFast(i128, a, b, overflow);
74+
},
75+
else => {},
76+
}
6877
if (2 * @bitSizeOf(i128) <= @bitSizeOf(usize)) {
6978
return muloXi4_genericFast(i128, a, b, overflow);
7079
} else {

test/behavior/math.zig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -609,14 +609,6 @@ test "128-bit multiplication" {
609609
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
610610
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
611611

612-
if ((builtin.zig_backend == .stage1 or builtin.zig_backend == .stage2_llvm) and
613-
builtin.cpu.arch == .wasm32)
614-
{
615-
// TODO This regressed with LLVM 14 due to the __muloti4 compiler-rt symbol
616-
// being lowered to call itself despite having the "nobuiltin" attribute.
617-
return error.SkipZigTest;
618-
}
619-
620612
var a: i128 = 3;
621613
var b: i128 = 2;
622614
var c = a * b;

0 commit comments

Comments
 (0)