| author | |
| committer | |
| log | a8065a05a5bc3df4036f1d7abe0928901cf7f5df |
| tree | 1135e2d227b9695c0c4ce87781caf569dc5f8e94 |
| parent | 896472c20e33c81a010b21a6f900e721a2cf0839 |
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 { |
| 407 | 407 | for (body.instructions) |inst| { |
| 408 | 408 | const new_inst = try self.genFuncInst(inst); |
| 409 | 409 | try inst_table.putNoClobber(self.gpa, inst, new_inst); |
| 410 | // TODO process operand deaths | |
| 410 | 411 | } |
| 411 | 412 | } |
| 412 | 413 | |
| ... | ... | @@ -1194,6 +1195,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 1194 | 1195 | while (true) { |
| 1195 | 1196 | i -= 1; |
| 1196 | 1197 | if (self.branch_stack.items[i].inst_table.get(inst)) |mcv| { |
| 1198 | assert(mcv != .dead); | |
| 1197 | 1199 | return mcv; |
| 1198 | 1200 | } |
| 1199 | 1201 | } |
src-self-hosted/ir.zig+1-1| ... | ... | @@ -38,7 +38,7 @@ pub const Inst = struct { |
| 38 | 38 | |
| 39 | 39 | pub fn operandDies(self: Inst, index: DeathsBitIndex) bool { |
| 40 | 40 | assert(index < deaths_bits); |
| 41 | return @truncate(u1, self.deaths << index) != 0; | |
| 41 | return @truncate(u1, self.deaths >> index) != 0; | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | pub fn specialOperandDeaths(self: Inst) bool { |
test/stage2/compare_output.zig+36| ... | ... | @@ -231,5 +231,41 @@ pub fn addCases(ctx: *TestContext) !void { |
| 231 | 231 | , |
| 232 | 232 | "", |
| 233 | 233 | ); |
| 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 | ); | |
| 234 | 270 | } |
| 235 | 271 | } |