authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-23 18:16:21+01:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-23 18:17:14+01:00
logf644263a6c2df79f907af5fb40b2bb0586ea436f
tree300be64216bb8987fa2de36c6a6cb22264c2f24b
parent03eb332d3c9d1b24811c21d28ceee4008743b60e

Builder: fix llvm ir/bc difference with allocas


1 files changed, 18 insertions(+), 7 deletions(-)

src/codegen/llvm/Builder.zig+18-7
......@@ -5197,10 +5197,9 @@ pub const WipFunction = struct {
51975197 ) Allocator.Error!Value {
51985198 const scalar_ty = try ty.changeLength(1, self.builder);
51995199 const mask_ty = try ty.changeScalar(.i32, self.builder);
5200 const zero = try self.builder.intConst(.i32, 0);
52015200 const poison = try self.builder.poisonValue(scalar_ty);
5202 const mask = try self.builder.splatValue(mask_ty, zero);
5203 const scalar = try self.insertElement(poison, elem, zero.toValue(), name);
5201 const mask = try self.builder.splatValue(mask_ty, .@"0");
5202 const scalar = try self.insertElement(poison, elem, .@"0", name);
52045203 return self.shuffleVector(scalar, poison, mask, name);
52055204 }
52065205
......@@ -5278,7 +5277,10 @@ pub const WipFunction = struct {
52785277 },
52795278 .data = self.addExtraAssumeCapacity(Instruction.Alloca{
52805279 .type = ty,
5281 .len = len,
5280 .len = switch (len) {
5281 .none => .@"1",
5282 else => len,
5283 },
52825284 .info = .{ .alignment = alignment, .addr_space = addr_space },
52835285 }),
52845286 });
......@@ -6708,6 +6710,8 @@ pub const FastMathKind = enum {
67086710pub const Constant = enum(u32) {
67096711 false,
67106712 true,
6713 @"0",
6714 @"1",
67116715 none,
67126716 no_init = (1 << 30) - 1,
67136717 _,
......@@ -7492,6 +7496,8 @@ pub const Value = enum(u32) {
74927496 none = std.math.maxInt(u31),
74937497 false = first_constant + @intFromEnum(Constant.false),
74947498 true = first_constant + @intFromEnum(Constant.true),
7499 @"0" = first_constant + @intFromEnum(Constant.@"0"),
7500 @"1" = first_constant + @intFromEnum(Constant.@"1"),
74957501 _,
74967502
74977503 const first_constant = 1 << 30;
......@@ -8336,6 +8342,8 @@ pub fn init(options: Options) Allocator.Error!Builder {
83368342
83378343 assert(try self.intConst(.i1, 0) == .false);
83388344 assert(try self.intConst(.i1, 1) == .true);
8345 assert(try self.intConst(.i32, 0) == .@"0");
8346 assert(try self.intConst(.i32, 1) == .@"1");
83398347 assert(try self.noneConst(.token) == .none);
83408348 if (!self.strip) assert(try self.debugNone() == .none);
83418349
......@@ -9519,7 +9527,10 @@ pub fn printUnbuffered(
95199527 instruction_index.name(&function).fmt(self),
95209528 @tagName(tag),
95219529 extra.type.fmt(self),
9522 extra.len.fmt(function_index, self),
9530 Value.fmt(switch (extra.len) {
9531 .@"1" => .none,
9532 else => extra.len,
9533 }, function_index, self),
95239534 extra.info.alignment,
95249535 extra.info.addr_space,
95259536 });
......@@ -14510,8 +14521,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1451014521 const alignment = extra.info.alignment.toLlvm();
1451114522 try function_block.writeAbbrev(FunctionBlock.Alloca{
1451214523 .inst_type = extra.type,
14513 .len_type = if (extra.len == .none) .i1 else extra.len.typeOf(@enumFromInt(func_index), self),
14514 .len_value = adapter.getValueIndex(if (extra.len == .none) Constant.true.toValue() else extra.len),
14524 .len_type = extra.len.typeOf(@enumFromInt(func_index), self),
14525 .len_value = adapter.getValueIndex(extra.len),
1451514526 .flags = .{
1451614527 .align_lower = @truncate(alignment),
1451714528 .inalloca = kind == .@"alloca inalloca",