authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-17 17:03:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-20 13:12:20-07:00
loga8065a05a5bc3df4036f1d7abe0928901cf7f5df
tree1135e2d227b9695c0c4ce87781caf569dc5f8e94
parent896472c20e33c81a010b21a6f900e721a2cf0839

stage2: fix implementation of liveness operandDies()


3 files changed, 39 insertions(+), 1 deletions(-)

src-self-hosted/codegen.zig+2
......@@ -407,6 +407,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
407407 for (body.instructions) |inst| {
408408 const new_inst = try self.genFuncInst(inst);
409409 try inst_table.putNoClobber(self.gpa, inst, new_inst);
410 // TODO process operand deaths
410411 }
411412 }
412413
......@@ -1194,6 +1195,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
11941195 while (true) {
11951196 i -= 1;
11961197 if (self.branch_stack.items[i].inst_table.get(inst)) |mcv| {
1198 assert(mcv != .dead);
11971199 return mcv;
11981200 }
11991201 }
src-self-hosted/ir.zig+1-1
......@@ -38,7 +38,7 @@ pub const Inst = struct {
3838
3939 pub fn operandDies(self: Inst, index: DeathsBitIndex) bool {
4040 assert(index < deaths_bits);
41 return @truncate(u1, self.deaths << index) != 0;
41 return @truncate(u1, self.deaths >> index) != 0;
4242 }
4343
4444 pub fn specialOperandDeaths(self: Inst) bool {
test/stage2/compare_output.zig+36
......@@ -231,5 +231,41 @@ pub fn addCases(ctx: *TestContext) !void {
231231 ,
232232 "",
233233 );
234
235 // More stress on the liveness detection.
236 case.addCompareOutput(
237 \\export fn _start() noreturn {
238 \\ add(3, 4);
239 \\
240 \\ exit();
241 \\}
242 \\
243 \\fn add(a: u32, b: u32) void {
244 \\ const c = a + b; // 7
245 \\ const d = a + c; // 10
246 \\ const e = d + b; // 14
247 \\ const f = d + e; // 24
248 \\ const g = e + f; // 38
249 \\ const h = f + g; // 62
250 \\ const i = g + h; // 100
251 \\ assert(i == 100);
252 \\}
253 \\
254 \\pub fn assert(ok: bool) void {
255 \\ if (!ok) unreachable; // assertion failure
256 \\}
257 \\
258 \\fn exit() noreturn {
259 \\ asm volatile ("syscall"
260 \\ :
261 \\ : [number] "{rax}" (231),
262 \\ [arg1] "{rdi}" (0)
263 \\ : "rcx", "r11", "memory"
264 \\ );
265 \\ unreachable;
266 \\}
267 ,
268 "",
269 );
234270 }
235271}