diff options
| author | Rue <78876133+IOKG04@users.noreply.github.com> | 2025-08-13 02:56:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-13 00:56:31 +0000 |
| commit | dd4e25cf4410017cb113c0cb1c85c6e5c75729e3 (patch) | |
| tree | 282f8563663e31d08c17d51b17a76b94b7cc5137 /src/codegen | |
| parent | 749f10af49022597d873d41df5c600e97e5c4a37 (diff) | |
| download | zig-dd4e25cf4410017cb113c0cb1c85c6e5c75729e3.tar.gz zig-dd4e25cf4410017cb113c0cb1c85c6e5c75729e3.zip | |
optimize `@intCast` in llvm backend (#24739)
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/llvm.zig | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 15b6ce7f12..a46c2d0e76 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -9234,8 +9234,7 @@ pub const FuncGen = struct { const dest_is_enum = dest_ty.zigTypeTag(zcu) == .@"enum"; - safety: { - if (!safety) break :safety; + bounds_check: { const dest_scalar = dest_ty.scalarType(zcu); const operand_scalar = operand_ty.scalarType(zcu); @@ -9254,7 +9253,7 @@ pub const FuncGen = struct { }; }; - if (!have_min_check and !have_max_check) break :safety; + if (!have_min_check and !have_max_check) break :bounds_check; const operand_llvm_ty = try o.lowerType(pt, operand_ty); const operand_scalar_llvm_ty = try o.lowerType(pt, operand_scalar); @@ -9272,12 +9271,16 @@ pub const FuncGen = struct { const vec_ty = ok_maybe_vec.typeOfWip(&fg.wip); break :ok try fg.wip.callIntrinsic(.normal, .none, .@"vector.reduce.and", &.{vec_ty}, &.{ok_maybe_vec}, ""); } else ok_maybe_vec; - const fail_block = try fg.wip.block(1, "IntMinFail"); - const ok_block = try fg.wip.block(1, "IntMinOk"); - _ = try fg.wip.brCond(ok, ok_block, fail_block, .none); - fg.wip.cursor = .{ .block = fail_block }; - try fg.buildSimplePanic(panic_id); - fg.wip.cursor = .{ .block = ok_block }; + if (safety) { + const fail_block = try fg.wip.block(1, "IntMinFail"); + const ok_block = try fg.wip.block(1, "IntMinOk"); + _ = try fg.wip.brCond(ok, ok_block, fail_block, .none); + fg.wip.cursor = .{ .block = fail_block }; + try fg.buildSimplePanic(panic_id); + fg.wip.cursor = .{ .block = ok_block }; + } else { + _ = try fg.wip.callIntrinsic(.normal, .none, .assume, &.{}, &.{ok}, ""); + } } if (have_max_check) { @@ -9288,12 +9291,16 @@ pub const FuncGen = struct { const vec_ty = ok_maybe_vec.typeOfWip(&fg.wip); break :ok try fg.wip.callIntrinsic(.normal, .none, .@"vector.reduce.and", &.{vec_ty}, &.{ok_maybe_vec}, ""); } else ok_maybe_vec; - const fail_block = try fg.wip.block(1, "IntMaxFail"); - const ok_block = try fg.wip.block(1, "IntMaxOk"); - _ = try fg.wip.brCond(ok, ok_block, fail_block, .none); - fg.wip.cursor = .{ .block = fail_block }; - try fg.buildSimplePanic(panic_id); - fg.wip.cursor = .{ .block = ok_block }; + if (safety) { + const fail_block = try fg.wip.block(1, "IntMaxFail"); + const ok_block = try fg.wip.block(1, "IntMaxOk"); + _ = try fg.wip.brCond(ok, ok_block, fail_block, .none); + fg.wip.cursor = .{ .block = fail_block }; + try fg.buildSimplePanic(panic_id); + fg.wip.cursor = .{ .block = ok_block }; + } else { + _ = try fg.wip.callIntrinsic(.normal, .none, .assume, &.{}, &.{ok}, ""); + } } } |
