authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-05 21:28:39-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-05 21:28:39-07:00
logd8fc8d0118a6ae99c0298d584faf1d8b5c6712c4
treeff9a621f147afc17a29b8b0d0f3cd32e0dc7d05b
parent558ad1909573abfe2c9387391917c110ef95310e

compiler_rt: work around LLVM optimizing __muloti4 to call itself

This is a workaround for https://github.com/llvm/llvm-project/issues/56403

2 files changed, 9 insertions(+), 8 deletions(-)

lib/compiler_rt/mulo.zig+9
......@@ -65,6 +65,15 @@ pub fn __mulodi4(a: i64, b: i64, overflow: *c_int) callconv(.C) i64 {
6565}
6666
6767pub 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-8
......@@ -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;