From 5e9726946dcb9248dbd34ded1bdd4f7af8dc2d31 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Sun, 18 Dec 2022 17:35:19 +0100 Subject: new UNDEF Ref Crashing loads of uninitialized memory proved to be a problem when implementing unions using qbe. This patch introduces a new UNDEF Ref to represent data that is known to be uninitialized. Optimization passes can make use of it to eliminate some code. In the last compilation stages, UNDEF is treated as the constant 0xdeaddead. --- fold.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'fold.c') diff --git a/fold.c b/fold.c index f992b3a..3ff0bc7 100644 --- a/fold.c +++ b/fold.c @@ -1,8 +1,8 @@ #include "all.h" enum { - Bot = -2, /* lattice bottom */ - Top = -1, /* lattice top */ + Bot = -1, /* lattice bottom */ + Top = 0, /* lattice top (matches UNDEF) */ }; typedef struct Edge Edge; @@ -126,7 +126,6 @@ visitjmp(Blk *b, int n, Fn *fn) switch (b->jmp.type) { case Jjnz: l = latval(b->jmp.arg); - assert(l != Top && "ssa invariant broken"); if (l == Bot) { edge[n][1].work = flowrk; edge[n][0].work = &edge[n][1]; @@ -174,7 +173,6 @@ renref(Ref *r) if (rtype(*r) == RTmp) if ((l=val[r->val]) != Bot) { - assert(l != Top && "ssa invariant broken"); *r = CON(l); return 1; } @@ -294,9 +292,13 @@ fold(Fn *fn) for (i=b->ins; i<&b->ins[b->nins]; i++) if (renref(&i->to)) *i = (Ins){.op = Onop}; - else + else { for (n=0; n<2; n++) renref(&i->arg[n]); + if (isstore(i->op)) + if (req(i->arg[0], UNDEF)) + *i = (Ins){.op = Onop}; + } renref(&b->jmp.arg); if (b->jmp.type == Jjnz && rtype(b->jmp.arg) == RCon) { if (iscon(&fn->con[b->jmp.arg.val], 0, 0)) { -- cgit v1.2.3