This patch currently isn't ready to commitCurrently in aliasPHI we give up if we have a PHI as an incoming value to a PHI, but posting it as a possible alternative approach to D44160.
Currently we only look at the incoming values to a PHI node to determine if it actually only has one possible value,to avoid having O(m x n) calls to aliasCheck. but actually we should be looking at the entire graph rooted at that node as this lets us handle more cases.
This is specifically being done in order to improve alias analysis within GVN,This patch relaxes that slightly to allow looking through PHIs if we only end up with one value as a result. as alias analysis uses GetUnderlyingObject which uses SimplifyInstructionThis should be fine, and GVN introduces phi graphs that SimplifyInstruction currently can't simplify (or ratheras in the worst case we look through n blocks to find this single value, it can only handle them by iteratively simplifying each individual PHI node).
This patch currently has several test failures
LLVM :: CodeGen/AMDGPU/nested-loop-conditions.ll
LLVM :: CodeGen/PowerPC/expand-contiguous-isel.ll
LLVM :: CodeGen/X86/ragreedy-hoist-spill.ll
LLVM :: Transforms/CodeGenPrepare/X86/sink-addrmode-base.ll
LLVM :: Transforms/CodeGenPrepare/X86/sink-addrmode-two-phi.ll
LLVM :: Transforms/IndVarSimplify/2011-11-17-selfphi.ll
LLVM :: Transforms/IndVarSimplify/no-iv-rewrite.llthen look through n blocks again if the value we're comparing against is also a PHI, giving O(n) where n is bounded by MaxLookupSearchDepth which we already allow GetUnderlyingObject to do.
Some of these are tests that use phi nodes in too simple a way that now gets optimised away (as are several tests that this patch adjusts) but the IndVarSimplify failures are much harder to resolve. What's happening is:
* LoopSimplify calls SimplifyInstruction only on PHI nodes in the loop header
* Currently this does nothing in these testsThis is specifically being done in order to improve alias analysis within GVN, but now we eliminate the PHI but that leaves an unsimplified PHI node in the loop body
* IndVarSimplify now does nothing because it sees no induction variable
* So we are left with the unsimplified PHI that we didn't previously haveas GVN can introduce PHI graphs of this kind where there's only one underlying value.
I'm not sure how to fix this. Making LoopSimplify simplify all of the PHI nodes in the loop fixes this test failure, but causes ~20 more.