From 53eff8970a5785aa5cee588d4264cccf27c63378 Mon Sep 17 00:00:00 2001 From: Sieds Lykles <93992551+S-Lykles@users.noreply.github.com> Date: Wed, 3 Sep 2025 07:07:54 +0200 Subject: [PATCH] add Ops.GEP to _min_max (#11976) --- test/unit/test_uop_vmin_vmax.py | 9 +++++++++ tinygrad/uop/ops.py | 1 + 2 files changed, 10 insertions(+) diff --git a/test/unit/test_uop_vmin_vmax.py b/test/unit/test_uop_vmin_vmax.py index 044a8fa13b..a639860b3b 100644 --- a/test/unit/test_uop_vmin_vmax.py +++ b/test/unit/test_uop_vmin_vmax.py @@ -251,6 +251,15 @@ class TestVminVmaxVConst(unittest.TestCase): self.assertIs(uop.vmin, False) self.assertIs(uop.vmax, True) + def test_vmin_vmax_vector_with_gep(self): + # vmin and vmax for a vector constant of bool values + d1 = UOp(Ops.DEFINE_GLOBAL, dtypes.int.ptr(), (), 1) + idx = UOp.const(dtypes.int, 0) + val = UOp(Ops.LOAD, dtypes.int.vec(2), (d1.index(idx),)) + uop = (val // 32).gep(0) + self.assertEqual(uop.vmin, -67108864) + self.assertEqual(uop.vmax, 67108863) + class TestConstFactor(unittest.TestCase): def test_const_factor_constant(self): # const_factor for a constant diff --git a/tinygrad/uop/ops.py b/tinygrad/uop/ops.py index 2729e8b465..09f76e97b7 100644 --- a/tinygrad/uop/ops.py +++ b/tinygrad/uop/ops.py @@ -565,6 +565,7 @@ class UOp(MathTrait, metaclass=UOpMetaClass): if self.op is Ops.SPECIAL: return 0, self.arg[1]-1 if isinstance(self.arg[1], int) else self.arg[1].vmax-1 if self.op is Ops.CONST: return self.arg, self.arg if self.op is Ops.VCONST: return (min(self.arg), max(self.arg)) + if self.op is Ops.GEP: return self.src[0]._min_max # TODO: CAST to bool/unsigned is not monotone, still some case can be simplified if self.op is Ops.CAST and self.dtype in (dtypes.floats+dtypes.sints): return max(dtypes.min(self.dtype), self.src[0].vmin), min(self.src[0].vmax, dtypes.max(self.dtype))