authorgravatar for 78876133+IOKG04@users.noreply.github.comRue <78876133+IOKG04@users.noreply.github.com> 2025-08-13 02:56:31+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-08-13 00:56:31+00:00
logdd4e25cf4410017cb113c0cb1c85c6e5c75729e3
tree282f8563663e31d08c17d51b17a76b94b7cc5137
parent749f10af49022597d873d41df5c600e97e5c4a37
signaturebadge-check Signed by PGP key B5690EEEBB952194

optimize `@intCast` in llvm backend (#24739)


1 files changed, 22 insertions(+), 15 deletions(-)

src/codegen/llvm.zig+22-15
...@@ -9234,8 +9234,7 @@ pub const FuncGen = struct {...@@ -9234,8 +9234,7 @@ pub const FuncGen = struct {
92349234
9235 const dest_is_enum = dest_ty.zigTypeTag(zcu) == .@"enum";9235 const dest_is_enum = dest_ty.zigTypeTag(zcu) == .@"enum";
92369236
9237 safety: {9237 bounds_check: {
9238 if (!safety) break :safety;
9239 const dest_scalar = dest_ty.scalarType(zcu);9238 const dest_scalar = dest_ty.scalarType(zcu);
9240 const operand_scalar = operand_ty.scalarType(zcu);9239 const operand_scalar = operand_ty.scalarType(zcu);
92419240
...@@ -9254,7 +9253,7 @@ pub const FuncGen = struct {...@@ -9254,7 +9253,7 @@ pub const FuncGen = struct {
9254 };9253 };
9255 };9254 };
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
9259 const operand_llvm_ty = try o.lowerType(pt, operand_ty);9258 const operand_llvm_ty = try o.lowerType(pt, operand_ty);
9260 const operand_scalar_llvm_ty = try o.lowerType(pt, operand_scalar);9259 const operand_scalar_llvm_ty = try o.lowerType(pt, operand_scalar);
...@@ -9272,12 +9271,16 @@ pub const FuncGen = struct {...@@ -9272,12 +9271,16 @@ pub const FuncGen = struct {
9272 const vec_ty = ok_maybe_vec.typeOfWip(&fg.wip);9271 const vec_ty = ok_maybe_vec.typeOfWip(&fg.wip);
9273 break :ok try fg.wip.callIntrinsic(.normal, .none, .@"vector.reduce.and", &.{vec_ty}, &.{ok_maybe_vec}, "");9272 break :ok try fg.wip.callIntrinsic(.normal, .none, .@"vector.reduce.and", &.{vec_ty}, &.{ok_maybe_vec}, "");
9274 } else ok_maybe_vec;9273 } else ok_maybe_vec;
9275 const fail_block = try fg.wip.block(1, "IntMinFail");9274 if (safety) {
9276 const ok_block = try fg.wip.block(1, "IntMinOk");9275 const fail_block = try fg.wip.block(1, "IntMinFail");
9277 _ = try fg.wip.brCond(ok, ok_block, fail_block, .none);9276 const ok_block = try fg.wip.block(1, "IntMinOk");
9278 fg.wip.cursor = .{ .block = fail_block };9277 _ = try fg.wip.brCond(ok, ok_block, fail_block, .none);
9279 try fg.buildSimplePanic(panic_id);9278 fg.wip.cursor = .{ .block = fail_block };
9280 fg.wip.cursor = .{ .block = ok_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 }
9281 }9284 }
92829285
9283 if (have_max_check) {9286 if (have_max_check) {
...@@ -9288,12 +9291,16 @@ pub const FuncGen = struct {...@@ -9288,12 +9291,16 @@ pub const FuncGen = struct {
9288 const vec_ty = ok_maybe_vec.typeOfWip(&fg.wip);9291 const vec_ty = ok_maybe_vec.typeOfWip(&fg.wip);
9289 break :ok try fg.wip.callIntrinsic(.normal, .none, .@"vector.reduce.and", &.{vec_ty}, &.{ok_maybe_vec}, "");9292 break :ok try fg.wip.callIntrinsic(.normal, .none, .@"vector.reduce.and", &.{vec_ty}, &.{ok_maybe_vec}, "");
9290 } else ok_maybe_vec;9293 } else ok_maybe_vec;
9291 const fail_block = try fg.wip.block(1, "IntMaxFail");9294 if (safety) {
9292 const ok_block = try fg.wip.block(1, "IntMaxOk");9295 const fail_block = try fg.wip.block(1, "IntMaxFail");
9293 _ = try fg.wip.brCond(ok, ok_block, fail_block, .none);9296 const ok_block = try fg.wip.block(1, "IntMaxOk");
9294 fg.wip.cursor = .{ .block = fail_block };9297 _ = try fg.wip.brCond(ok, ok_block, fail_block, .none);
9295 try fg.buildSimplePanic(panic_id);9298 fg.wip.cursor = .{ .block = fail_block };
9296 fg.wip.cursor = .{ .block = ok_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 }
9297 }9304 }
9298 }9305 }
92999306