authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-23 18:59:18+01:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-23 19:40:07+01:00
log2c67a1ecd2d6680631e13c8a7bc56915d633eb29
tree35b70968e7ac345ff8cd2725edcc27fa58133894
parentf644263a6c2df79f907af5fb40b2bb0586ea436f

llvm: optimize i32 constants


2 files changed, 26 insertions(+), 35 deletions(-)

src/codegen/llvm.zig+25-32
......@@ -896,19 +896,22 @@ pub const Object = struct {
896896 .{ .optimized = comp.root_mod.optimize_mode != .Debug },
897897 );
898898
899 const i32_2 = try builder.intConst(.i32, 2);
900 const i32_3 = try builder.intConst(.i32, 3);
899901 const debug_info_version = try builder.debugModuleFlag(
900 try builder.debugConstant(try builder.intConst(.i32, 2)),
902 try builder.debugConstant(i32_2),
901903 try builder.metadataString("Debug Info Version"),
902 try builder.debugConstant(try builder.intConst(.i32, 3)),
904 try builder.debugConstant(i32_3),
903905 );
904906
905907 switch (comp.config.debug_format) {
906908 .strip => unreachable,
907909 .dwarf => |f| {
910 const i32_4 = try builder.intConst(.i32, 4);
908911 const dwarf_version = try builder.debugModuleFlag(
909 try builder.debugConstant(try builder.intConst(.i32, 2)),
912 try builder.debugConstant(i32_2),
910913 try builder.metadataString("Dwarf Version"),
911 try builder.debugConstant(try builder.intConst(.i32, 4)),
914 try builder.debugConstant(i32_4),
912915 );
913916 switch (f) {
914917 .@"32" => {
......@@ -919,9 +922,9 @@ pub const Object = struct {
919922 },
920923 .@"64" => {
921924 const dwarf64 = try builder.debugModuleFlag(
922 try builder.debugConstant(try builder.intConst(.i32, 2)),
925 try builder.debugConstant(i32_2),
923926 try builder.metadataString("DWARF64"),
924 try builder.debugConstant(try builder.intConst(.i32, 1)),
927 try builder.debugConstant(.@"1"),
925928 );
926929 try builder.debugNamed(try builder.metadataString("llvm.module.flags"), &.{
927930 debug_info_version,
......@@ -933,9 +936,9 @@ pub const Object = struct {
933936 },
934937 .code_view => {
935938 const code_view = try builder.debugModuleFlag(
936 try builder.debugConstant(try builder.intConst(.i32, 2)),
939 try builder.debugConstant(i32_2),
937940 try builder.metadataString("CodeView"),
938 try builder.debugConstant(try builder.intConst(.i32, 1)),
941 try builder.debugConstant(.@"1"),
939942 );
940943 try builder.debugNamed(try builder.metadataString("llvm.module.flags"), &.{
941944 debug_info_version,
......@@ -4265,7 +4268,7 @@ pub const Object = struct {
42654268 const err_align = err_int_ty.abiAlignment(mod);
42664269 const index: u32 = if (payload_align.compare(.gt, err_align)) 2 else 1;
42674270 return o.builder.gepConst(.inbounds, try o.lowerType(eu_ty), parent_ptr, null, &.{
4268 try o.builder.intConst(.i32, 0), try o.builder.intConst(.i32, index),
4271 .@"0", try o.builder.intConst(.i32, index),
42694272 });
42704273 },
42714274 .opt_payload => |opt_ptr| {
......@@ -4281,9 +4284,7 @@ pub const Object = struct {
42814284 return parent_ptr;
42824285 }
42834286
4284 return o.builder.gepConst(.inbounds, try o.lowerType(opt_ty), parent_ptr, null, &.{
4285 try o.builder.intConst(.i32, 0), try o.builder.intConst(.i32, 0),
4286 });
4287 return o.builder.gepConst(.inbounds, try o.lowerType(opt_ty), parent_ptr, null, &.{ .@"0", .@"0" });
42874288 },
42884289 .comptime_field => unreachable,
42894290 .elem => |elem_ptr| {
......@@ -4314,7 +4315,7 @@ pub const Object = struct {
43144315
43154316 const parent_llvm_ty = try o.lowerType(parent_ty);
43164317 return o.builder.gepConst(.inbounds, parent_llvm_ty, parent_ptr, null, &.{
4317 try o.builder.intConst(.i32, 0),
4318 .@"0",
43184319 try o.builder.intConst(.i32, @intFromBool(
43194320 layout.tag_size > 0 and layout.tag_align.compare(.gte, layout.payload_align),
43204321 )),
......@@ -4340,7 +4341,7 @@ pub const Object = struct {
43404341 parent_ptr,
43414342 null,
43424343 if (o.llvmFieldIndex(parent_ty, field_index)) |llvm_field_index| &.{
4343 try o.builder.intConst(.i32, 0),
4344 .@"0",
43444345 try o.builder.intConst(.i32, llvm_field_index),
43454346 } else &.{
43464347 try o.builder.intConst(.i32, @intFromBool(
......@@ -4353,7 +4354,7 @@ pub const Object = struct {
43534354 assert(parent_ty.isSlice(mod));
43544355 const parent_llvm_ty = try o.lowerType(parent_ty);
43554356 return o.builder.gepConst(.inbounds, parent_llvm_ty, parent_ptr, null, &.{
4356 try o.builder.intConst(.i32, 0), try o.builder.intConst(.i32, field_index),
4357 .@"0", try o.builder.intConst(.i32, field_index),
43574358 });
43584359 },
43594360 else => unreachable,
......@@ -7842,7 +7843,7 @@ pub const FuncGen = struct {
78427843 .none,
78437844 if (scalar_ty.isSignedInt(mod)) .@"smul.fix.sat" else .@"umul.fix.sat",
78447845 &.{try o.lowerType(inst_ty)},
7845 &.{ lhs, rhs, try o.builder.intValue(.i32, 0) },
7846 &.{ lhs, rhs, .@"0" },
78467847 "",
78477848 );
78487849 }
......@@ -8165,7 +8166,6 @@ pub const FuncGen = struct {
81658166
81668167 const libc_fn = try self.getLibcFunction(fn_name, &.{ scalar_llvm_ty, scalar_llvm_ty }, .i32);
81678168
8168 const zero = try o.builder.intConst(.i32, 0);
81698169 const int_cond: Builder.IntegerCondition = switch (pred) {
81708170 .eq => .eq,
81718171 .neq => .ne,
......@@ -8182,7 +8182,7 @@ pub const FuncGen = struct {
81828182 const init = try o.builder.poisonValue(vector_result_ty);
81838183 const result = try self.buildElementwiseCall(libc_fn, &params, init, vec_len);
81848184
8185 const zero_vector = try o.builder.splatValue(vector_result_ty, zero);
8185 const zero_vector = try o.builder.splatValue(vector_result_ty, .@"0");
81868186 return self.wip.icmp(int_cond, result, zero_vector, "");
81878187 }
81888188
......@@ -8195,7 +8195,7 @@ pub const FuncGen = struct {
81958195 &params,
81968196 "",
81978197 );
8198 return self.wip.icmp(int_cond, result, zero.toValue(), "");
8198 return self.wip.icmp(int_cond, result, .@"0", "");
81998199 }
82008200
82018201 const FloatOp = enum {
......@@ -9021,18 +9021,14 @@ pub const FuncGen = struct {
90219021 // https://github.com/ziglang/zig/issues/11946
90229022 return o.builder.intValue(llvm_usize, 0);
90239023 }
9024 const result = try self.wip.callIntrinsic(.normal, .none, .returnaddress, &.{}, &.{
9025 try o.builder.intValue(.i32, 0),
9026 }, "");
9024 const result = try self.wip.callIntrinsic(.normal, .none, .returnaddress, &.{}, &.{.@"0"}, "");
90279025 return self.wip.cast(.ptrtoint, result, llvm_usize, "");
90289026 }
90299027
90309028 fn airFrameAddress(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
90319029 _ = inst;
90329030 const o = self.dg.object;
9033 const result = try self.wip.callIntrinsic(.normal, .none, .frameaddress, &.{.ptr}, &.{
9034 try o.builder.intValue(.i32, 0),
9035 }, "");
9031 const result = try self.wip.callIntrinsic(.normal, .none, .frameaddress, &.{.ptr}, &.{.@"0"}, "");
90369032 return self.wip.cast(.ptrtoint, result, try o.lowerType(Type.usize), "");
90379033 }
90389034
......@@ -10116,7 +10112,6 @@ pub const FuncGen = struct {
1011610112 const field_align = mod.unionFieldNormalAlignment(union_obj, extra.field_index);
1011710113 const llvm_usize = try o.lowerType(Type.usize);
1011810114 const usize_zero = try o.builder.intValue(llvm_usize, 0);
10119 const i32_zero = try o.builder.intValue(.i32, 0);
1012010115
1012110116 const llvm_union_ty = t: {
1012210117 const payload_ty = p: {
......@@ -10155,7 +10150,7 @@ pub const FuncGen = struct {
1015510150 .flags = .{ .alignment = field_align },
1015610151 });
1015710152 if (layout.tag_size == 0) {
10158 const indices = [3]Builder.Value{ usize_zero, i32_zero, i32_zero };
10153 const indices = [3]Builder.Value{ usize_zero, .@"0", .@"0" };
1015910154 const len: usize = if (field_size == layout.payload_size) 2 else 3;
1016010155 const field_ptr =
1016110156 try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, indices[0..len], "");
......@@ -10165,11 +10160,9 @@ pub const FuncGen = struct {
1016510160
1016610161 {
1016710162 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));
10168 const indices: [3]Builder.Value =
10169 .{ usize_zero, try o.builder.intValue(.i32, payload_index), i32_zero };
10163 const indices: [3]Builder.Value = .{ usize_zero, try o.builder.intValue(.i32, payload_index), .@"0" };
1017010164 const len: usize = if (field_size == layout.payload_size) 2 else 3;
10171 const field_ptr =
10172 try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, indices[0..len], "");
10165 const field_ptr = try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, indices[0..len], "");
1017310166 try self.store(field_ptr, field_ptr_ty, llvm_payload, .none);
1017410167 }
1017510168 {
......@@ -10275,7 +10268,7 @@ pub const FuncGen = struct {
1027510268
1027610269 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1027710270 const dimension = pl_op.payload;
10278 if (dimension >= 3) return o.builder.intValue(.i32, 1);
10271 if (dimension >= 3) return .@"1";
1027910272
1028010273 // Fetch the dispatch pointer, which points to this structure:
1028110274 // https://github.com/RadeonOpenCompute/ROCR-Runtime/blob/adae6c61e10d371f7cbc3d0e94ae2c070cab18a4/src/inc/hsa.h#L2913
src/codegen/llvm/Builder.zig+1-3
......@@ -5533,9 +5533,7 @@ pub const WipFunction = struct {
55335533 name: []const u8,
55345534 ) Allocator.Error!Value {
55355535 assert(ty.isStruct(self.builder));
5536 return self.gep(.inbounds, ty, base, &.{
5537 try self.builder.intValue(.i32, 0), try self.builder.intValue(.i32, index),
5538 }, name);
5536 return self.gep(.inbounds, ty, base, &.{ .@"0", try self.builder.intValue(.i32, index) }, name);
55395537 }
55405538
55415539 pub fn conv(