<div dir="ltr"><div>Hi all,</div><div><br></div><div>I encountered a problem where an optimization that uses BasicAA is very fragile due to BasicAA's "weak" reliance on the PhiValues analysis.</div><div><br></div><div>The whole story is this: our team is in the process of upgrading to the newest version of LLVM, and I discovered that on the newest LLVM, Global Value Numbering doesn't apply an important optimization anymore.</div><div><br></div><div>A little bit of background: GVN depends on Basic Alias Analysis, and BasicAA depends on PhiValues. However, the dependence between GVN and AA is "strong":</div><div><br></div><div>   getAnalysis<AAResultsWrapperPass>().getAAResults()</div><div><br></div><div>Whereas between BasicAA and PhiValues it is "weak" (note "IfAvailable"):</div><div><br></div><div><span class="gmail-keyword">   auto</span> *PVWP = getAnalysisIfAvailable<PhiValuesWrapperPass>();</div><div><br></div><div>So, in the old LLVM, BasicAA that runs before GVN, happens to find cached PhiValues analysis, gives good results to GVN, and GVN applies the optimization. But on the new LLVM, BasicAA doesn't have PhiValues, gives poor results to GVN, and GVN gives up. It looks to me that whether BasicAA gets its hands on PhiValues is almost entirely up to chance, which makes the clients of BasicAA very fragile, meaning that it's hard to be sure if an optimization you need will get applied.</div><div><br></div><div>I see the discussion in <a href="https://reviews.llvm.org/D44564">https://reviews.llvm.org/D44564</a> but I'm pretty much out of my depth there and I'm not sure if a solution to the problem above has been mentioned.</div><div><br></div><div>Maybe the new pass manager has this problem solved?</div><div><br></div><div>Anyhow, I would appreciate any input, thank you in advance.</div><div><br></div><div>Best,</div><div>Alex<br></div><div><br></div><div><br></div></div>