Affine scalar replacement (and other affine passes, though not fixed here) don't properly handle operations with nested regions. This patch fixes the pass and two affine utilities to function properly given a non-affine internal region.
This patch prevents the pass from throwing an internal compiler error when running on the added test case.