Fixed a problem for sub-loops

When we do dfs from a phi, it's possible that we will encounter
other loops that not start from the phi we started with.