This is an archive of the discontinued LLVM Phabricator instance.

Fix PR25372 - teach replaceCongruentPHIs to handle cases where SE evaluates a PHI to a SCEVConstant
ClosedPublic

Authored by sbaranga on Nov 2 2015, 5:34 AM.

Details

Summary

Since now Scalar Evolution can create non-add rec expressions for PHI
nodes, it can also create SCEVConstant expressions. This will confuse
replaceCongruentPHIs, which previously relied on the fact that SCEV
could not produce constants in this case.

We will now replace the node with a constant in these cases - or avoid
processing the Phi in case of a type mismatch.

Diff Detail

Repository
rL LLVM

Event Timeline

sbaranga updated this revision to Diff 38903.Nov 2 2015, 5:34 AM
sbaranga retitled this revision from to Fix PR25372 - teach replaceCongruentPHIs to handle cases where SE evaluates a PHI to a SCEVConstant.
sbaranga updated this object.
sbaranga added a reviewer: sanjoy.
sbaranga added subscribers: majnemer, llvm-commits.
sanjoy accepted this revision.Nov 2 2015, 6:39 PM
sanjoy edited edge metadata.

lgtm with comments addressed

lib/Analysis/ScalarEvolutionExpander.cpp
1740 ↗(On Diff #38903)

This is optional to fix -- it might be clearer to restructure this as

auto SimplifyPHINode = [&](PHINode *PN) {
  // see if SimplifyInstruction or SE is able to simplify PN, if so return the simplified Value* else return nullptr
}

if (Value *V = SimplifyPHIToConstant(Phi))
  // the logic that is currently guarded by `if (V)`
1742 ↗(On Diff #38903)

Instead of having a standalone decl for Const, why not

if (SE.isSCEVable ...) {
 if (auto *SC = dyn_cast<SCEVConstant>(SE.getSCEV(...
   // use SC
This revision is now accepted and ready to land.Nov 2 2015, 6:39 PM
sbaranga updated this revision to Diff 39072.Nov 3 2015, 8:28 AM
sbaranga edited edge metadata.

Added a lambda to handle all PHI simplifications (which should address all comments).

This revision was automatically updated to reflect the committed changes.

Committed in r251938, thanks!

-Silviu