Good catch, in that case I’m not sure there is a clear alternative other than computing a mask and then reusing it for indexing (which would require more reads than the min/max approach anyway).
Is this a performance bottleneck in your application?