Commit d65318847f

Jacob Young <jacobly0@users.noreply.github.com>
2023-08-18 08:22:40
compiler_rt: fix fp sub being optimized to call itself
Closes #16844 Reduces #16846
1 parent 8219711
lib/compiler_rt/subdf3.zig
@@ -1,4 +1,5 @@
 const common = @import("./common.zig");
+const addf3 = @import("./addf3.zig").addf3;
 
 pub const panic = common.panic;
 
@@ -11,11 +12,14 @@ comptime {
 }
 
 fn __subdf3(a: f64, b: f64) callconv(.C) f64 {
-    const neg_b = @as(f64, @bitCast(@as(u64, @bitCast(b)) ^ (@as(u64, 1) << 63)));
-    return a + neg_b;
+    return sub(a, b);
 }
 
 fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {
+    return sub(a, b);
+}
+
+inline fn sub(a: f64, b: f64) f64 {
     const neg_b = @as(f64, @bitCast(@as(u64, @bitCast(b)) ^ (@as(u64, 1) << 63)));
-    return a + neg_b;
+    return addf3(f64, a, neg_b);
 }
lib/compiler_rt/subhf3.zig
@@ -1,4 +1,5 @@
 const common = @import("./common.zig");
+const addf3 = @import("./addf3.zig").addf3;
 
 pub const panic = common.panic;
 
@@ -8,5 +9,5 @@ comptime {
 
 fn __subhf3(a: f16, b: f16) callconv(.C) f16 {
     const neg_b = @as(f16, @bitCast(@as(u16, @bitCast(b)) ^ (@as(u16, 1) << 15)));
-    return a + neg_b;
+    return addf3(f16, a, neg_b);
 }
lib/compiler_rt/subsf3.zig
@@ -1,4 +1,5 @@
 const common = @import("./common.zig");
+const addf3 = @import("./addf3.zig").addf3;
 
 pub const panic = common.panic;
 
@@ -11,11 +12,14 @@ comptime {
 }
 
 fn __subsf3(a: f32, b: f32) callconv(.C) f32 {
-    const neg_b = @as(f32, @bitCast(@as(u32, @bitCast(b)) ^ (@as(u32, 1) << 31)));
-    return a + neg_b;
+    return sub(a, b);
 }
 
 fn __aeabi_fsub(a: f32, b: f32) callconv(.AAPCS) f32 {
+    return sub(a, b);
+}
+
+inline fn sub(a: f32, b: f32) f32 {
     const neg_b = @as(f32, @bitCast(@as(u32, @bitCast(b)) ^ (@as(u32, 1) << 31)));
-    return a + neg_b;
+    return addf3(f32, a, neg_b);
 }
lib/compiler_rt/subtf3.zig
@@ -1,4 +1,5 @@
 const common = @import("./common.zig");
+const addf3 = @import("./addf3.zig").addf3;
 
 pub const panic = common.panic;
 
@@ -21,5 +22,5 @@ fn _Qp_sub(c: *f128, a: *const f128, b: *const f128) callconv(.C) void {
 
 inline fn sub(a: f128, b: f128) f128 {
     const neg_b = @as(f128, @bitCast(@as(u128, @bitCast(b)) ^ (@as(u128, 1) << 127)));
-    return a + neg_b;
+    return addf3(f128, a, neg_b);
 }
test/behavior/atomics.zig
@@ -243,11 +243,6 @@ test "atomicrmw with ints" {
     if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
     if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
 
-    if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isMIPS()) {
-        // https://github.com/ziglang/zig/issues/16846
-        return error.SkipZigTest;
-    }
-
     try testAtomicRmwInts();
     try comptime testAtomicRmwInts();
 }
test/behavior/floatop.zig
@@ -711,18 +711,6 @@ test "@floor f80" {
         return error.SkipZigTest;
     }
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
-    if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isMIPS()) {
-        // https://github.com/ziglang/zig/issues/16846
-        return error.SkipZigTest;
-    }
-
     try testFloorLegacy(f80, 12.0);
     try comptime testFloorLegacy(f80, 12.0);
 }
@@ -734,13 +722,6 @@ test "@floor f128" {
     if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isARM()) {
         // https://github.com/ziglang/zig/issues/16848
         return error.SkipZigTest;
@@ -831,13 +812,6 @@ test "@ceil f80" {
         return error.SkipZigTest;
     }
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     try testCeilLegacy(f80, 12.0);
     try comptime testCeilLegacy(f80, 12.0);
 }
@@ -849,13 +823,6 @@ test "@ceil f128" {
     if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     try testCeilLegacy(f128, 12.0);
     try comptime testCeilLegacy(f128, 12.0);
 }
@@ -962,13 +929,6 @@ test "@trunc f128" {
     if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     try testTruncLegacy(f128, 12.0);
     try comptime testTruncLegacy(f128, 12.0);
 }
test/behavior/math.zig
@@ -1360,13 +1360,6 @@ test "float remainder division using @rem" {
     if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     try comptime frem(f16);
     try comptime frem(f32);
     try comptime frem(f64);
@@ -1410,13 +1403,6 @@ test "float modulo division using @mod" {
     if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
     if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     try comptime fmod(f16);
     try comptime fmod(f32);
     try comptime fmod(f64);
@@ -1480,13 +1466,6 @@ test "@round f80" {
     if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     try testRound(f80, 12.0);
     try comptime testRound(f80, 12.0);
 }
@@ -1499,13 +1478,6 @@ test "@round f128" {
     if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     try testRound(f128, 12.0);
     try comptime testRound(f128, 12.0);
 }
test/behavior/muladd.zig
@@ -62,13 +62,6 @@ test "@mulAdd f80" {
         return error.SkipZigTest;
     }
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     try comptime testMulAdd80();
     try testMulAdd80();
 }
@@ -93,13 +86,6 @@ test "@mulAdd f128" {
         return error.SkipZigTest;
     }
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     try comptime testMulAdd128();
     try testMulAdd128();
 }
@@ -203,13 +189,6 @@ test "vector f80" {
     if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     try comptime vector80();
     try vector80();
 }
@@ -235,13 +214,6 @@ test "vector f128" {
     if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     try comptime vector128();
     try vector128();
 }
test/behavior/vector.zig
@@ -104,13 +104,6 @@ test "vector float operators" {
     if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
 
-    if (builtin.zig_backend == .stage2_llvm and
-        (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
-    {
-        // https://github.com/ziglang/zig/issues/16844
-        return error.SkipZigTest;
-    }
-
     inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {
         const S = struct {
             fn doTheTest() !void {