This is an archive of the discontinued LLVM Phabricator instance.

[LoopDeletion] Update exits correctly when multiple duplicate edges from an exiting block
ClosedPublic

Authored by anna on Jun 22 2017, 9:27 AM.

Details

Summary

Currently, we incorrectly update exit blocks of loops when there are multiple
edges from a single exiting block to the exit block. This can happen when we
have switches as the terminator of the exiting blocks.
The fix here is to correctly update the phi nodes in the exit block, and remove
all incoming values *except* for one which is from the preheader.

Note: Currently, this error can manifest only while deleting non-executed loops. However, it
is possible to trigger this error in invariant loops, once we enhance the logic
around the exit conditions for the loop check.

Diff Detail

Repository
rL LLVM

Event Timeline

anna created this revision.Jun 22 2017, 9:27 AM
efriedma added inline comments.Jun 22 2017, 12:27 PM
lib/Transforms/Scalar/LoopDeletion.cpp
250 ↗(On Diff #103586)

Do you need to call setIncomingValue() in the case where LoopIsNeverExecuted is false?

253 ↗(On Diff #103586)

There is no variable named ExitingBlock.

anna added inline comments.Jun 22 2017, 12:46 PM
lib/Transforms/Scalar/LoopDeletion.cpp
250 ↗(On Diff #103586)

We don't need to. When LoopIsNeverExecuted is false, all the exiting blocks have the same 'value', which gets moved to the preheader. This is also the reason why in the original implementation (before this patch), we keep just one exiting block and remove all others.

As a follow-on NFC, I'm going to move this undef value setting into a prepass before calling this function deleteDeadLoop.

253 ↗(On Diff #103586)

Oops, stale comment. I'll remove the mention of ExitingBlock.

efriedma accepted this revision.Jun 22 2017, 12:56 PM

LGTM with the comment fixed.

lib/Transforms/Scalar/LoopDeletion.cpp
250 ↗(On Diff #103586)

Okay, that makes sense.

This revision is now accepted and ready to land.Jun 22 2017, 12:56 PM
This revision was automatically updated to reflect the committed changes.
anna marked an inline comment as done.Jun 22 2017, 1:23 PM