From cb9e7d15bf2a23d551702504ef4610883cf70c9b Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 20 Nov 2015 22:15:03 +0800 Subject: [PATCH] compiler.iodelay: subtraction certainly shouldn't be commutative. --- artiq/compiler/iodelay.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/artiq/compiler/iodelay.py b/artiq/compiler/iodelay.py index ec9a73729..47e04472a 100644 --- a/artiq/compiler/iodelay.py +++ b/artiq/compiler/iodelay.py @@ -158,18 +158,23 @@ class Add(BinOpFixpoint): _op = lambda a, b: a + b _fixpoint = 0 -class Sub(BinOpFixpoint): - _priority = 2 - _symbol = "-" - _op = lambda a, b: a - b - _fixpoint = 0 - class Mul(BinOpFixpoint): _priority = 1 _symbol = "*" _op = lambda a, b: a * b _fixpoint = 1 +class Sub(BinOp): + _priority = 2 + _symbol = "-" + _op = lambda a, b: a - b + + def _fold_binop(self, lhs, rhs): + if isinstance(rhs, Const) and rhs.value == 0: + return lhs + else: + return super()._fold_binop(lhs, rhs) + class Div(BinOp): def _fold_binop(self, lhs, rhs): if isinstance(rhs, Const) and rhs.value == 1: