refactor: Accept IR in `optimize` (#28318)