IR: Refactor GEP range checks, reuse them for other parts of folding