stage2: fix implementation of liveness operandDies()

This commit is contained in:
Andrew Kelley 2020-07-17 17:03:24 -07:00
parent 896472c20e
commit a8065a05a5
3 changed files with 39 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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 {

View File

@ -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;
\\}
,
"",
);
}
}