Commit 7e1cba73fc

Andrew Kelley <andrew@ziglang.org>
2024-05-02 03:17:03
Type.intAbiAlignment: update for LLVM 18 changes
This function is intended to match what the backend desires. No kink shaming.
1 parent 88ada21
Changed files (1)
src/type.zig
@@ -1540,10 +1540,30 @@ pub const Type = struct {
     }
 
     pub fn intAbiAlignment(bits: u16, target: Target, use_llvm: bool) Alignment {
-        return Alignment.fromByteUnits(@min(
-            std.math.ceilPowerOfTwoPromote(u16, @as(u16, @intCast((@as(u17, bits) + 7) / 8))),
-            maxIntAlignment(target, use_llvm),
-        ));
+        return switch (target.cpu.arch) {
+            .x86 => switch (bits) {
+                0 => .none,
+                1...8 => .@"1",
+                9...16 => .@"2",
+                17...127 => .@"4",
+                else => .@"16",
+            },
+            .x86_64 => switch (bits) {
+                0 => .none,
+                1...8 => .@"1",
+                9...16 => .@"2",
+                17...32 => .@"4",
+                33...64 => .@"8",
+                else => switch (target_util.zigBackend(target, use_llvm)) {
+                    .stage2_x86_64 => .@"8",
+                    else => .@"16",
+                },
+            },
+            else => return Alignment.fromByteUnits(@min(
+                std.math.ceilPowerOfTwoPromote(u16, @as(u16, @intCast((@as(u17, bits) + 7) / 8))),
+                maxIntAlignment(target, use_llvm),
+            )),
+        };
     }
 
     pub fn maxIntAlignment(target: std.Target, use_llvm: bool) u16 {