aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-12-26 11:12:35 +0100
committerlemon <lsof@mailbox.org>2025-12-26 11:14:18 +0100
commitbf1a1c5aa83fe1e3d0a60e64199882efeb307116 (patch)
tree45a99ca1d7fb34950aa2f8927cf71079dd3aaa9a
parenta6c2f8a9177eeae64b83e4aeafe46dbe310b3861 (diff)
ir/builder: fix bug optiminzg x+x as x-x -> 0
-rw-r--r--ir/builder.c5
1 files changed, 3 insertions, 2 deletions
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 */