@@ -10165,16 +10165,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10165
10165
try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), ptr_src);
10166
10166
try sema.validateRuntimeValue(block, ptr_src, operand);
10167
10167
try sema.checkLogicalPtrOperation(block, ptr_src, ptr_ty);
10168
- if (!is_vector or zcu.backendSupportsFeature(.all_vector_instructions)) {
10169
- return block.addBitCast(dest_ty, operand);
10170
- }
10171
- const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
10172
- for (new_elems, 0..) |*new_elem, i| {
10173
- const idx_ref = try pt.intRef(.usize, i);
10174
- const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
10175
- new_elem.* = try block.addBitCast(.usize, old_elem);
10176
- }
10177
- return block.addAggregateInit(dest_ty, new_elems);
10168
+ return block.addBitCast(dest_ty, operand);
10178
10169
}
10179
10170
10180
10171
fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
@@ -10640,17 +10631,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
10640
10631
if (dst_bits >= src_bits) {
10641
10632
return sema.coerce(block, dest_ty, operand, operand_src);
10642
10633
}
10643
- if (!is_vector or zcu.backendSupportsFeature(.all_vector_instructions)) {
10644
- return block.addTyOp(.fptrunc, dest_ty, operand);
10645
- }
10646
- const vec_len = operand_ty.vectorLen(zcu);
10647
- const new_elems = try sema.arena.alloc(Air.Inst.Ref, vec_len);
10648
- for (new_elems, 0..) |*new_elem, i| {
10649
- const idx_ref = try pt.intRef(.usize, i);
10650
- const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
10651
- new_elem.* = try block.addTyOp(.fptrunc, dest_scalar_ty, old_elem);
10652
- }
10653
- return block.addAggregateInit(dest_ty, new_elems);
10634
+ return block.addTyOp(.fptrunc, dest_ty, operand);
10654
10635
}
10655
10636
10656
10637
fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
@@ -20722,16 +20703,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
20722
20703
.storage = .{ .elems = new_elems },
20723
20704
} }));
20724
20705
}
20725
- if (!is_vector or zcu.backendSupportsFeature(.all_vector_instructions)) {
20726
- return block.addBitCast(dest_ty, operand);
20727
- }
20728
- const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
20729
- for (new_elems, 0..) |*new_elem, i| {
20730
- const idx_ref = try pt.intRef(.usize, i);
20731
- const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
20732
- new_elem.* = try block.addBitCast(.u1, old_elem);
20733
- }
20734
- return block.addAggregateInit(dest_ty, new_elems);
20706
+ return block.addBitCast(dest_ty, operand);
20735
20707
}
20736
20708
20737
20709
fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
@@ -22327,42 +22299,23 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22327
22299
.storage = .{ .repeated_elem = (try pt.intValue(dest_scalar_ty, 0)).toIntern() },
22328
22300
} }));
22329
22301
}
22330
- if (!is_vector or zcu.backendSupportsFeature(.all_vector_instructions)) {
22331
- const result = try block.addTyOp(if (block.float_mode == .optimized) .int_from_float_optimized else .int_from_float, dest_ty, operand);
22332
- if (block.wantSafety()) {
22333
- const back = try block.addTyOp(.float_from_int, operand_ty, result);
22334
- const diff = try block.addBinOp(if (block.float_mode == .optimized) .sub_optimized else .sub, operand, back);
22335
- const ok = if (is_vector) ok: {
22336
- const ok_pos = try block.addCmpVector(diff, Air.internedToRef((try sema.splat(operand_ty, try pt.floatValue(operand_scalar_ty, 1.0))).toIntern()), .lt);
22337
- const ok_neg = try block.addCmpVector(diff, Air.internedToRef((try sema.splat(operand_ty, try pt.floatValue(operand_scalar_ty, -1.0))).toIntern()), .gt);
22338
- const ok = try block.addBinOp(.bit_and, ok_pos, ok_neg);
22339
- break :ok try block.addReduce(ok, .And);
22340
- } else ok: {
22341
- const ok_pos = try block.addBinOp(if (block.float_mode == .optimized) .cmp_lt_optimized else .cmp_lt, diff, Air.internedToRef((try pt.floatValue(operand_ty, 1.0)).toIntern()));
22342
- const ok_neg = try block.addBinOp(if (block.float_mode == .optimized) .cmp_gt_optimized else .cmp_gt, diff, Air.internedToRef((try pt.floatValue(operand_ty, -1.0)).toIntern()));
22343
- break :ok try block.addBinOp(.bool_and, ok_pos, ok_neg);
22344
- };
22345
- try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);
22346
- }
22347
- return result;
22348
- }
22349
- const len = dest_ty.vectorLen(zcu);
22350
- const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
22351
- for (new_elems, 0..) |*new_elem, i| {
22352
- const idx_ref = try pt.intRef(.usize, i);
22353
- const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
22354
- const result = try block.addTyOp(if (block.float_mode == .optimized) .int_from_float_optimized else .int_from_float, dest_scalar_ty, old_elem);
22355
- if (block.wantSafety()) {
22356
- const back = try block.addTyOp(.float_from_int, operand_scalar_ty, result);
22357
- const diff = try block.addBinOp(.sub, old_elem, back);
22358
- const ok_pos = try block.addBinOp(if (block.float_mode == .optimized) .cmp_lt_optimized else .cmp_lt, diff, Air.internedToRef((try pt.floatValue(operand_scalar_ty, 1.0)).toIntern()));
22359
- const ok_neg = try block.addBinOp(if (block.float_mode == .optimized) .cmp_gt_optimized else .cmp_gt, diff, Air.internedToRef((try pt.floatValue(operand_scalar_ty, -1.0)).toIntern()));
22360
- const ok = try block.addBinOp(.bool_and, ok_pos, ok_neg);
22361
- try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);
22362
- }
22363
- new_elem.* = result;
22302
+ const result = try block.addTyOp(if (block.float_mode == .optimized) .int_from_float_optimized else .int_from_float, dest_ty, operand);
22303
+ if (block.wantSafety()) {
22304
+ const back = try block.addTyOp(.float_from_int, operand_ty, result);
22305
+ const diff = try block.addBinOp(if (block.float_mode == .optimized) .sub_optimized else .sub, operand, back);
22306
+ const ok = if (is_vector) ok: {
22307
+ const ok_pos = try block.addCmpVector(diff, Air.internedToRef((try sema.splat(operand_ty, try pt.floatValue(operand_scalar_ty, 1.0))).toIntern()), .lt);
22308
+ const ok_neg = try block.addCmpVector(diff, Air.internedToRef((try sema.splat(operand_ty, try pt.floatValue(operand_scalar_ty, -1.0))).toIntern()), .gt);
22309
+ const ok = try block.addBinOp(.bit_and, ok_pos, ok_neg);
22310
+ break :ok try block.addReduce(ok, .And);
22311
+ } else ok: {
22312
+ const ok_pos = try block.addBinOp(if (block.float_mode == .optimized) .cmp_lt_optimized else .cmp_lt, diff, Air.internedToRef((try pt.floatValue(operand_ty, 1.0)).toIntern()));
22313
+ const ok_neg = try block.addBinOp(if (block.float_mode == .optimized) .cmp_gt_optimized else .cmp_gt, diff, Air.internedToRef((try pt.floatValue(operand_ty, -1.0)).toIntern()));
22314
+ break :ok try block.addBinOp(.bool_and, ok_pos, ok_neg);
22315
+ };
22316
+ try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);
22364
22317
}
22365
- return block.addAggregateInit(dest_ty, new_elems) ;
22318
+ return result ;
22366
22319
}
22367
22320
22368
22321
fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
@@ -22377,7 +22330,6 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22377
22330
const operand_ty = sema.typeOf(operand);
22378
22331
22379
22332
try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src);
22380
- const is_vector = dest_ty.zigTypeTag(zcu) == .vector;
22381
22333
22382
22334
const dest_scalar_ty = dest_ty.scalarType(zcu);
22383
22335
const operand_scalar_ty = operand_ty.scalarType(zcu);
@@ -22393,17 +22345,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22393
22345
}
22394
22346
22395
22347
try sema.requireRuntimeBlock(block, src, operand_src);
22396
- if (!is_vector or zcu.backendSupportsFeature(.all_vector_instructions)) {
22397
- return block.addTyOp(.float_from_int, dest_ty, operand);
22398
- }
22399
- const len = operand_ty.vectorLen(zcu);
22400
- const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
22401
- for (new_elems, 0..) |*new_elem, i| {
22402
- const idx_ref = try pt.intRef(.usize, i);
22403
- const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
22404
- new_elem.* = try block.addTyOp(.float_from_int, dest_scalar_ty, old_elem);
22405
- }
22406
- return block.addAggregateInit(dest_ty, new_elems);
22348
+ return block.addTyOp(.float_from_int, dest_ty, operand);
22407
22349
}
22408
22350
22409
22351
fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
@@ -22473,69 +22415,34 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
22473
22415
}
22474
22416
try sema.requireRuntimeBlock(block, src, operand_src);
22475
22417
try sema.checkLogicalPtrOperation(block, src, ptr_ty);
22476
- if (!is_vector or zcu.backendSupportsFeature(.all_vector_instructions)) {
22477
- if (block.wantSafety() and (try elem_ty.hasRuntimeBitsSema(pt) or elem_ty.zigTypeTag(zcu) == .@"fn")) {
22478
- if (!ptr_ty.isAllowzeroPtr(zcu)) {
22479
- const is_non_zero = if (is_vector) all_non_zero: {
22480
- const zero_usize = Air.internedToRef((try sema.splat(operand_ty, .zero_usize)).toIntern());
22481
- const is_non_zero = try block.addCmpVector(operand_coerced, zero_usize, .neq);
22482
- break :all_non_zero try block.addReduce(is_non_zero, .And);
22483
- } else try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize);
22484
- try sema.addSafetyCheck(block, src, is_non_zero, .cast_to_null);
22485
- }
22486
- if (ptr_align.compare(.gt, .@"1")) {
22487
- const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1;
22488
- const align_mask = Air.internedToRef((try sema.splat(operand_ty, try pt.intValue(
22489
- .usize,
22490
- if (elem_ty.fnPtrMaskOrNull(zcu)) |mask|
22491
- align_bytes_minus_1 & mask
22492
- else
22493
- align_bytes_minus_1,
22494
- ))).toIntern());
22495
- const remainder = try block.addBinOp(.bit_and, operand_coerced, align_mask);
22496
- const is_aligned = if (is_vector) all_aligned: {
22497
- const splat_zero_usize = Air.internedToRef((try sema.splat(operand_ty, .zero_usize)).toIntern());
22498
- const is_aligned = try block.addCmpVector(remainder, splat_zero_usize, .eq);
22499
- break :all_aligned try block.addReduce(is_aligned, .And);
22500
- } else try block.addBinOp(.cmp_eq, remainder, .zero_usize);
22501
- try sema.addSafetyCheck(block, src, is_aligned, .incorrect_alignment);
22502
- }
22503
- }
22504
- return block.addBitCast(dest_ty, operand_coerced);
22505
- }
22506
-
22507
- const len = dest_ty.vectorLen(zcu);
22508
22418
if (block.wantSafety() and (try elem_ty.hasRuntimeBitsSema(pt) or elem_ty.zigTypeTag(zcu) == .@"fn")) {
22509
- for (0..len) |i| {
22510
- const idx_ref = try pt.intRef(.usize, i);
22511
- const elem_coerced = try block.addBinOp(.array_elem_val, operand_coerced, idx_ref);
22512
- if (!ptr_ty.isAllowzeroPtr(zcu)) {
22513
- const is_non_zero = try block.addBinOp(.cmp_neq, elem_coerced, .zero_usize);
22514
- try sema.addSafetyCheck(block, src, is_non_zero, .cast_to_null);
22515
- }
22516
- if (ptr_align.compare(.gt, .@"1")) {
22517
- const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1;
22518
- const align_mask = Air.internedToRef((try pt.intValue(
22519
- .usize,
22520
- if (elem_ty.fnPtrMaskOrNull(zcu)) |mask|
22521
- align_bytes_minus_1 & mask
22522
- else
22523
- align_bytes_minus_1,
22524
- )).toIntern());
22525
- const remainder = try block.addBinOp(.bit_and, elem_coerced, align_mask);
22526
- const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize);
22527
- try sema.addSafetyCheck(block, src, is_aligned, .incorrect_alignment);
22528
- }
22529
- }
22530
- }
22531
-
22532
- const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
22533
- for (new_elems, 0..) |*new_elem, i| {
22534
- const idx_ref = try pt.intRef(.usize, i);
22535
- const old_elem = try block.addBinOp(.array_elem_val, operand_coerced, idx_ref);
22536
- new_elem.* = try block.addBitCast(ptr_ty, old_elem);
22537
- }
22538
- return block.addAggregateInit(dest_ty, new_elems);
22419
+ if (!ptr_ty.isAllowzeroPtr(zcu)) {
22420
+ const is_non_zero = if (is_vector) all_non_zero: {
22421
+ const zero_usize = Air.internedToRef((try sema.splat(operand_ty, .zero_usize)).toIntern());
22422
+ const is_non_zero = try block.addCmpVector(operand_coerced, zero_usize, .neq);
22423
+ break :all_non_zero try block.addReduce(is_non_zero, .And);
22424
+ } else try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize);
22425
+ try sema.addSafetyCheck(block, src, is_non_zero, .cast_to_null);
22426
+ }
22427
+ if (ptr_align.compare(.gt, .@"1")) {
22428
+ const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1;
22429
+ const align_mask = Air.internedToRef((try sema.splat(operand_ty, try pt.intValue(
22430
+ .usize,
22431
+ if (elem_ty.fnPtrMaskOrNull(zcu)) |mask|
22432
+ align_bytes_minus_1 & mask
22433
+ else
22434
+ align_bytes_minus_1,
22435
+ ))).toIntern());
22436
+ const remainder = try block.addBinOp(.bit_and, operand_coerced, align_mask);
22437
+ const is_aligned = if (is_vector) all_aligned: {
22438
+ const splat_zero_usize = Air.internedToRef((try sema.splat(operand_ty, .zero_usize)).toIntern());
22439
+ const is_aligned = try block.addCmpVector(remainder, splat_zero_usize, .eq);
22440
+ break :all_aligned try block.addReduce(is_aligned, .And);
22441
+ } else try block.addBinOp(.cmp_eq, remainder, .zero_usize);
22442
+ try sema.addSafetyCheck(block, src, is_aligned, .incorrect_alignment);
22443
+ }
22444
+ }
22445
+ return block.addBitCast(dest_ty, operand_coerced);
22539
22446
}
22540
22447
22541
22448
fn ptrFromIntVal(
0 commit comments