From bf1a1c5aa83fe1e3d0a60e64199882efeb307116 Mon Sep 17 00:00:00 2001 From: lemon Date: Fri, 26 Dec 2025 11:12:35 +0100 Subject: ir/builder: fix bug optiminzg x+x as x-x -> 0 --- ir/builder.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ir') diff --git a/ir/builder.c b/ir/builder.c index 951c8f4..1348fe1 100644 --- a/ir/builder.c +++ b/ir/builder.c @@ -14,10 +14,11 @@ irbinop(struct function *fn, enum op op, enum irclass k, union ref l, union ref switch (op) { case Oadd: if (l.bits == ZEROREF.bits) return r; /* 0 + x ==> x */ - /* fallthru */ + if (r.bits == ZEROREF.bits) return l; /* x + 0 ==> x */ + break; case Osub: if (r.bits == ZEROREF.bits) return l; /* x - 0 ==> x */ - if (kisint(k) && l.bits == r.bits) return ZEROREF; /* x - 0 ==> x */ + if (kisint(k) && l.bits == r.bits) return ZEROREF; /* x - x ==> 0 */ break; case Omul: if (isnumcon(l)) rswap(l, r); /* put const in rhs */ -- cgit v1.2.3