[inductor] Fix ModularIndexing assumptions (#152993)

Fixes https://github.com/pytorch/pytorch/issues/151198.

Since the result of ModularIndexing can be zero due to the modulo
operation, we should not make any assumption about ModularIndexing
being positive

Pull Request resolved: https://github.com/pytorch/pytorch/pull/152993
Approved by: https://github.com/yf225
This commit is contained in:
Isuru Fernando 2025-05-06 21:16:00 +00:00 committed by PyTorch MergeBot
parent d900c68ea6
commit e5f869999c
2 changed files with 7 additions and 4 deletions

View File

@ -205,6 +205,13 @@ class TestIndexingSimplification(InductorTestCase):
self.assertEqual(expr2, actual)
self.assertNotEqual(ModularIndexing(x, 1, b), actual)
def test_modular_indexing_positive(self):
x = sympy.Symbol("x", integer=True, positive=True)
expr = ModularIndexing(x, 1, 1024) - 1
expr2 = abs(expr)
self.assertNotEqual(expr2, expr)
def test_expand_floor_div_skipped(self):
sizevars = SizeVarAllocator()
x = sympy.Symbol("x", integer=True, positive=True)

View File

@ -363,10 +363,6 @@ class ModularIndexing(sympy.Function):
p, q = self.args[:2]
return fuzzy_eq(p.is_nonnegative, q.is_nonnegative) # type: ignore[attr-defined]
def _eval_is_positive(self) -> Optional[bool]:
p, q = self.args[:2]
return fuzzy_eq(p.is_positive, q.is_positive) # type: ignore[attr-defined]
class Where(sympy.Function):
"""