mirror of
https://github.com/ziglang/zig.git
synced 2026-01-04 20:43:19 +00:00
stage2: fix implementation of liveness operandDies()
This commit is contained in:
parent
896472c20e
commit
a8065a05a5
@ -407,6 +407,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
|
||||
for (body.instructions) |inst| {
|
||||
const new_inst = try self.genFuncInst(inst);
|
||||
try inst_table.putNoClobber(self.gpa, inst, new_inst);
|
||||
// TODO process operand deaths
|
||||
}
|
||||
}
|
||||
|
||||
@ -1194,6 +1195,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
|
||||
while (true) {
|
||||
i -= 1;
|
||||
if (self.branch_stack.items[i].inst_table.get(inst)) |mcv| {
|
||||
assert(mcv != .dead);
|
||||
return mcv;
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ pub const Inst = struct {
|
||||
|
||||
pub fn operandDies(self: Inst, index: DeathsBitIndex) bool {
|
||||
assert(index < deaths_bits);
|
||||
return @truncate(u1, self.deaths << index) != 0;
|
||||
return @truncate(u1, self.deaths >> index) != 0;
|
||||
}
|
||||
|
||||
pub fn specialOperandDeaths(self: Inst) bool {
|
||||
|
||||
@ -231,5 +231,41 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
,
|
||||
"",
|
||||
);
|
||||
|
||||
// More stress on the liveness detection.
|
||||
case.addCompareOutput(
|
||||
\\export fn _start() noreturn {
|
||||
\\ add(3, 4);
|
||||
\\
|
||||
\\ exit();
|
||||
\\}
|
||||
\\
|
||||
\\fn add(a: u32, b: u32) void {
|
||||
\\ const c = a + b; // 7
|
||||
\\ const d = a + c; // 10
|
||||
\\ const e = d + b; // 14
|
||||
\\ const f = d + e; // 24
|
||||
\\ const g = e + f; // 38
|
||||
\\ const h = f + g; // 62
|
||||
\\ const i = g + h; // 100
|
||||
\\ assert(i == 100);
|
||||
\\}
|
||||
\\
|
||||
\\pub fn assert(ok: bool) void {
|
||||
\\ if (!ok) unreachable; // assertion failure
|
||||
\\}
|
||||
\\
|
||||
\\fn exit() noreturn {
|
||||
\\ asm volatile ("syscall"
|
||||
\\ :
|
||||
\\ : [number] "{rax}" (231),
|
||||
\\ [arg1] "{rdi}" (0)
|
||||
\\ : "rcx", "r11", "memory"
|
||||
\\ );
|
||||
\\ unreachable;
|
||||
\\}
|
||||
,
|
||||
"",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user