Skip to content

Commit 1eb5d70

Browse files
committed
x86_64: fix switch on big ints
1 parent bc10131 commit 1eb5d70

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/arch/x86_64/CodeGen.zig

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102890,9 +102890,6 @@ fn lowerSwitchBr(
102890102890
const relocs = try allocator.alloc(Mir.Inst.Index, case.items.len + case.ranges.len);
102891102891
defer allocator.free(relocs);
102892102892

102893-
var cond_temp = try cg.tempInit(condition_ty, condition);
102894-
const reset_index = cg.next_temp_index;
102895-
102896102893
try cg.spillEflagsIfOccupied();
102897102894
for (case.items, relocs[0..case.items.len]) |item, *reloc| {
102898102895
const item_mcv = try cg.resolveInst(item);
@@ -102903,6 +102900,7 @@ fn lowerSwitchBr(
102903102900
else => unreachable,
102904102901
},
102905102902
else => cc: {
102903+
var cond_temp = try cg.tempInit(condition_ty, condition);
102906102904
var item_temp = try cg.tempInit(condition_ty, item_mcv);
102907102905
const cc_temp = cond_temp.cmpInts(.eq, &item_temp, cg) catch |err| switch (err) {
102908102906
error.SelectFailed => unreachable,
@@ -102911,14 +102909,16 @@ fn lowerSwitchBr(
102911102909
try item_temp.die(cg);
102912102910
const cc = cc_temp.tracking(cg).short.eflags;
102913102911
try cc_temp.die(cg);
102914-
try cg.resetTemps(reset_index);
102912+
try cond_temp.die(cg);
102913+
try cg.resetTemps(@enumFromInt(0));
102915102914
break :cc cc;
102916102915
},
102917102916
};
102918102917
reloc.* = try cg.asmJccReloc(cc, undefined);
102919102918
}
102920102919

102921102920
for (case.ranges, relocs[case.items.len..]) |range, *reloc| {
102921+
var cond_temp = try cg.tempInit(condition_ty, condition);
102922102922
const min_mcv = try cg.resolveInst(range[0]);
102923102923
const max_mcv = try cg.resolveInst(range[1]);
102924102924
// `null` means always false.
@@ -102962,7 +102962,8 @@ fn lowerSwitchBr(
102962102962
break :cc cc;
102963102963
},
102964102964
};
102965-
try cg.resetTemps(reset_index);
102965+
try cond_temp.die(cg);
102966+
try cg.resetTemps(@enumFromInt(0));
102966102967
// "Success" case is in `reloc`....
102967102968
if (lte_max) |cc| {
102968102969
reloc.* = try cg.asmJccReloc(cc, undefined);
@@ -102973,8 +102974,6 @@ fn lowerSwitchBr(
102973102974
if (lt_min_reloc) |r| cg.performReloc(r);
102974102975
}
102975102976

102976-
try cond_temp.die(cg);
102977-
try cg.resetTemps(@enumFromInt(0));
102978102977
cg.checkInvariantsAfterAirInst();
102979102978

102980102979
// The jump to skip this case if the conditions all failed.

test/behavior/switch.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ fn testSwitchWithAllRanges(x: u32, y: u32) u32 {
4343
}
4444

4545
test "switch arbitrary int size" {
46-
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
4746
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
4847
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
4948
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO

0 commit comments

Comments
 (0)