Skip to content

Commit dd4e25c

Browse files
authored
optimize @intCast in llvm backend (#24739)
1 parent 749f10a commit dd4e25c

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/codegen/llvm.zig

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9234,8 +9234,7 @@ pub const FuncGen = struct {
92349234

92359235
const dest_is_enum = dest_ty.zigTypeTag(zcu) == .@"enum";
92369236

9237-
safety: {
9238-
if (!safety) break :safety;
9237+
bounds_check: {
92399238
const dest_scalar = dest_ty.scalarType(zcu);
92409239
const operand_scalar = operand_ty.scalarType(zcu);
92419240

@@ -9254,7 +9253,7 @@ pub const FuncGen = struct {
92549253
};
92559254
};
92569255

9257-
if (!have_min_check and !have_max_check) break :safety;
9256+
if (!have_min_check and !have_max_check) break :bounds_check;
92589257

92599258
const operand_llvm_ty = try o.lowerType(pt, operand_ty);
92609259
const operand_scalar_llvm_ty = try o.lowerType(pt, operand_scalar);
@@ -9272,12 +9271,16 @@ pub const FuncGen = struct {
92729271
const vec_ty = ok_maybe_vec.typeOfWip(&fg.wip);
92739272
break :ok try fg.wip.callIntrinsic(.normal, .none, .@"vector.reduce.and", &.{vec_ty}, &.{ok_maybe_vec}, "");
92749273
} else ok_maybe_vec;
9275-
const fail_block = try fg.wip.block(1, "IntMinFail");
9276-
const ok_block = try fg.wip.block(1, "IntMinOk");
9277-
_ = try fg.wip.brCond(ok, ok_block, fail_block, .none);
9278-
fg.wip.cursor = .{ .block = fail_block };
9279-
try fg.buildSimplePanic(panic_id);
9280-
fg.wip.cursor = .{ .block = ok_block };
9274+
if (safety) {
9275+
const fail_block = try fg.wip.block(1, "IntMinFail");
9276+
const ok_block = try fg.wip.block(1, "IntMinOk");
9277+
_ = try fg.wip.brCond(ok, ok_block, fail_block, .none);
9278+
fg.wip.cursor = .{ .block = fail_block };
9279+
try fg.buildSimplePanic(panic_id);
9280+
fg.wip.cursor = .{ .block = ok_block };
9281+
} else {
9282+
_ = try fg.wip.callIntrinsic(.normal, .none, .assume, &.{}, &.{ok}, "");
9283+
}
92819284
}
92829285

92839286
if (have_max_check) {
@@ -9288,12 +9291,16 @@ pub const FuncGen = struct {
92889291
const vec_ty = ok_maybe_vec.typeOfWip(&fg.wip);
92899292
break :ok try fg.wip.callIntrinsic(.normal, .none, .@"vector.reduce.and", &.{vec_ty}, &.{ok_maybe_vec}, "");
92909293
} else ok_maybe_vec;
9291-
const fail_block = try fg.wip.block(1, "IntMaxFail");
9292-
const ok_block = try fg.wip.block(1, "IntMaxOk");
9293-
_ = try fg.wip.brCond(ok, ok_block, fail_block, .none);
9294-
fg.wip.cursor = .{ .block = fail_block };
9295-
try fg.buildSimplePanic(panic_id);
9296-
fg.wip.cursor = .{ .block = ok_block };
9294+
if (safety) {
9295+
const fail_block = try fg.wip.block(1, "IntMaxFail");
9296+
const ok_block = try fg.wip.block(1, "IntMaxOk");
9297+
_ = try fg.wip.brCond(ok, ok_block, fail_block, .none);
9298+
fg.wip.cursor = .{ .block = fail_block };
9299+
try fg.buildSimplePanic(panic_id);
9300+
fg.wip.cursor = .{ .block = ok_block };
9301+
} else {
9302+
_ = try fg.wip.callIntrinsic(.normal, .none, .assume, &.{}, &.{ok}, "");
9303+
}
92979304
}
92989305
}
92999306

0 commit comments

Comments
 (0)