This is an archive of the discontinued LLVM Phabricator instance.

LICM: Don't crash when an instruction is used by an unreachable BB
ClosedPublic

Authored by majnemer on Sep 2 2014, 1:11 AM.

Details

Summary

BBs might contain non-LCSSA'd values after the LCSSA pass is run if they
are unreachable from the entry block.

Normally, the users of the instruction would be PHIs but the unreachable
BBs have normal users; rewrite their uses to be undef values.

An alternative fix could involve fixing this at LCSSA but that would
require this invariant to hold after subsequent transforms. If a BB
created an unreachable block, they would be in violation of this.

This fixes PR19798.

Diff Detail

Event Timeline

majnemer updated this revision to Diff 13154.Sep 2 2014, 1:11 AM
majnemer retitled this revision from to LICM: Don't crash when an instruction is used by an unreachable BB.
majnemer updated this object.
majnemer added a reviewer: chandlerc.
majnemer added a subscriber: Unknown Object (MLST).
chandlerc accepted this revision.Sep 2 2014, 1:49 AM
chandlerc edited edge metadata.

Minor code tweak. Otherwise looks good.

lib/Transforms/Scalar/LICM.cpp
601

I think this would be more clear as:

if (!DT->isReachableFromEntry(User->getParent())) {
  User->replaceUsesOfWith(...);
  continue;
}

That localizes the unreachable -> undef logic and reduces the indent for the rest.

This revision is now accepted and ready to land.Sep 2 2014, 1:49 AM
majnemer closed this revision.Sep 2 2014, 9:31 AM
majnemer updated this revision to Diff 13165.

Closed by commit rL216911 (authored by @majnemer).