problems when the llvm::ExtractCodeRegion updates the Phi nodes in successors ... is there a method to eliminate phi nodes ?

Hi,

I use the llvm::ExtractCodeRegion to extract each loop into a separate function, but I have a problem when I run this on the SPEC CPU 2006 on the 401.bzip2 benchmark. First I use clang -O3 to generate optimized llvm code and then I extract some loops from the module built from blocksort.c source file.

The problem is that the PHI nodes contained in the successors of the codeRepl include two or more incoming edges for different blocks contained in the loop. Therefore, when the loop is extracted in the new function, these incoming edges are updated to have an entry from the codeRepl block instead of the the original blocks. But in case there are incoming edges from more blocks belonging to the loop, this generates an invalid Phi node which contains multiple entries for the codeRepl block.

I use LLVM 2.8 and in the file CodeExtractor.cpp lines 730 - 745 when the Phi nodes in the successors are updated, there is a test to check that the Phi node does not contain an entry from the same BasicBlock from the loop. But there is no test to check if two different blocks of the loop reach the same phi node. (If I correctly understood this part of codeā€¦ )

Did I obtain an invalid loop or this kind of loops are not eligible for llvm::ExtractCodeRegion ?
Is there any other method to eliminate the PHI nodes except the reg2mem pass? I do not want to pollute the code with so many additional load instructions. Is it possible to dissolve the PHI nodes without reg2mem?

Thank you.
Alexandra