UOp vmin/vmax on ADD (#5689)

This commit is contained in:
chenyu 2024-07-24 19:09:42 -04:00 committed by GitHub
parent e2e70bd90b
commit 8648fb2636
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View File

@ -183,7 +183,6 @@ class TestSymbolic(unittest.TestCase):
self.helper_test_variable(Variable("a", 0, 7) // -2, -4, 0, "((((a*-1)+8)//2)+-4)")
self.helper_test_variable(Variable("a", 0, 6) // -2, -3, 0, "((((a*-1)+6)//2)+-3)")
@unittest.expectedFailure
def test_sum_div_remove(self):
self.helper_test_variable(Node.sum([Variable("a", 0, 7), Variable("b", 0, 3)]) // 20, 0, 0, "0")

View File

@ -112,6 +112,8 @@ class UOp:
if self.op is UOps.ALU:
if self.arg is UnaryOps.NEG and self.dtype != dtypes.bool and not dtypes.is_unsigned(cast(DType, self.dtype)):
return self.const(-self.src[0].vmax.arg), self.const(-self.src[0].vmin.arg)
if self.arg is BinaryOps.ADD:
return self.const(self.src[0].vmin.arg+self.src[1].vmin.arg), self.const(self.src[0].vmax.arg+self.src[1].vmax.arg)
return None, None
class UPat: