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 {...@@ -5197,10 +5197,9 @@ pub const WipFunction = struct {
5197 ) Allocator.Error!Value {5197 ) Allocator.Error!Value {
5198 const scalar_ty = try ty.changeLength(1, self.builder);5198 const scalar_ty = try ty.changeLength(1, self.builder);
5199 const mask_ty = try ty.changeScalar(.i32, self.builder);5199 const mask_ty = try ty.changeScalar(.i32, self.builder);
5200 const zero = try self.builder.intConst(.i32, 0);
5201 const poison = try self.builder.poisonValue(scalar_ty);5200 const poison = try self.builder.poisonValue(scalar_ty);
5202 const mask = try self.builder.splatValue(mask_ty, zero);5201 const mask = try self.builder.splatValue(mask_ty, .@"0");
5203 const scalar = try self.insertElement(poison, elem, zero.toValue(), name);5202 const scalar = try self.insertElement(poison, elem, .@"0", name);
5204 return self.shuffleVector(scalar, poison, mask, name);5203 return self.shuffleVector(scalar, poison, mask, name);
5205 }5204 }
52065205
...@@ -5278,7 +5277,10 @@ pub const WipFunction = struct {...@@ -5278,7 +5277,10 @@ pub const WipFunction = struct {
5278 },5277 },
5279 .data = self.addExtraAssumeCapacity(Instruction.Alloca{5278 .data = self.addExtraAssumeCapacity(Instruction.Alloca{
5280 .type = ty,5279 .type = ty,
5281 .len = len,5280 .len = switch (len) {
5281 .none => .@"1",
5282 else => len,
5283 },
5282 .info = .{ .alignment = alignment, .addr_space = addr_space },5284 .info = .{ .alignment = alignment, .addr_space = addr_space },
5283 }),5285 }),
5284 });5286 });
...@@ -6708,6 +6710,8 @@ pub const FastMathKind = enum {...@@ -6708,6 +6710,8 @@ pub const FastMathKind = enum {
6708pub const Constant = enum(u32) {6710pub const Constant = enum(u32) {
6709 false,6711 false,
6710 true,6712 true,
6713 @"0",
6714 @"1",
6711 none,6715 none,
6712 no_init = (1 << 30) - 1,6716 no_init = (1 << 30) - 1,
6713 _,6717 _,
...@@ -7492,6 +7496,8 @@ pub const Value = enum(u32) {...@@ -7492,6 +7496,8 @@ pub const Value = enum(u32) {
7492 none = std.math.maxInt(u31),7496 none = std.math.maxInt(u31),
7493 false = first_constant + @intFromEnum(Constant.false),7497 false = first_constant + @intFromEnum(Constant.false),
7494 true = first_constant + @intFromEnum(Constant.true),7498 true = first_constant + @intFromEnum(Constant.true),
7499 @"0" = first_constant + @intFromEnum(Constant.@"0"),
7500 @"1" = first_constant + @intFromEnum(Constant.@"1"),
7495 _,7501 _,
74967502
7497 const first_constant = 1 << 30;7503 const first_constant = 1 << 30;
...@@ -8336,6 +8342,8 @@ pub fn init(options: Options) Allocator.Error!Builder {...@@ -8336,6 +8342,8 @@ pub fn init(options: Options) Allocator.Error!Builder {
83368342
8337 assert(try self.intConst(.i1, 0) == .false);8343 assert(try self.intConst(.i1, 0) == .false);
8338 assert(try self.intConst(.i1, 1) == .true);8344 assert(try self.intConst(.i1, 1) == .true);
8345 assert(try self.intConst(.i32, 0) == .@"0");
8346 assert(try self.intConst(.i32, 1) == .@"1");
8339 assert(try self.noneConst(.token) == .none);8347 assert(try self.noneConst(.token) == .none);
8340 if (!self.strip) assert(try self.debugNone() == .none);8348 if (!self.strip) assert(try self.debugNone() == .none);
83418349
...@@ -9519,7 +9527,10 @@ pub fn printUnbuffered(...@@ -9519,7 +9527,10 @@ pub fn printUnbuffered(
9519 instruction_index.name(&function).fmt(self),9527 instruction_index.name(&function).fmt(self),
9520 @tagName(tag),9528 @tagName(tag),
9521 extra.type.fmt(self),9529 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),
9523 extra.info.alignment,9534 extra.info.alignment,
9524 extra.info.addr_space,9535 extra.info.addr_space,
9525 });9536 });
...@@ -14510,8 +14521,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14510,8 +14521,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14510 const alignment = extra.info.alignment.toLlvm();14521 const alignment = extra.info.alignment.toLlvm();
14511 try function_block.writeAbbrev(FunctionBlock.Alloca{14522 try function_block.writeAbbrev(FunctionBlock.Alloca{
14512 .inst_type = extra.type,14523 .inst_type = extra.type,
14513 .len_type = if (extra.len == .none) .i1 else extra.len.typeOf(@enumFromInt(func_index), self),14524 .len_type = extra.len.typeOf(@enumFromInt(func_index), self),
14514 .len_value = adapter.getValueIndex(if (extra.len == .none) Constant.true.toValue() else extra.len),14525 .len_value = adapter.getValueIndex(extra.len),
14515 .flags = .{14526 .flags = .{
14516 .align_lower = @truncate(alignment),14527 .align_lower = @truncate(alignment),
14517 .inalloca = kind == .@"alloca inalloca",14528 .inalloca = kind == .@"alloca inalloca",