This is an archive of the discontinued LLVM Phabricator instance.

[LoopDeletion] Handle users in unreachable block
ClosedPublic

Authored by skatkov on Jan 11 2018, 3:19 AM.

Details

Summary

This is a fix for PR35884.

When we want to delete dead loop we must clean uses in unreachable blocks
otherwise we'll get an assert during deletion of instructions from the loop.

Diff Detail

Repository
rL LLVM

Event Timeline

skatkov created this revision.Jan 11 2018, 3:19 AM
lebedev.ri added inline comments.
lib/Transforms/Utils/LoopUtils.cpp
1370 ↗(On Diff #129422)

I think this can be simplified down to

for (Use &U : I.uses())
skatkov added inline comments.Jan 11 2018, 3:33 AM
lib/Transforms/Utils/LoopUtils.cpp
1370 ↗(On Diff #129422)

I'm not sure I can do it due to I modify Use in a loop.
I implemented it in this way to be similar to how Value::replace** routines do it.

lebedev.ri added inline comments.Jan 11 2018, 4:22 AM
lib/Transforms/Utils/LoopUtils.cpp
1370 ↗(On Diff #129422)

So if it is an invalid simplification, either this won't compile, or the testcase will fail, right?

anna accepted this revision.Jan 11 2018, 7:25 AM

LGTM w/ comments.

lib/Transforms/Utils/LoopUtils.cpp
1359 ↗(On Diff #129422)

I think this is more clearer: "Given LCSSA form is satisfied, we should not have users of instructions within the dead loop outside of the loop. However, LCSSA doesn't take unreachable uses into account. We handle them here".

1364 ↗(On Diff #129422)

Nit: only valid operation after dropping references, is deletion.

test/Transforms/LoopDeletion/use-in-unreachable.ll
10 ↗(On Diff #129422)

really, this isn't a badloop :)
It's an invariant loop that can be deleted. Perhaps rename to just loop?

This revision is now accepted and ready to land.Jan 11 2018, 7:25 AM
This revision was automatically updated to reflect the committed changes.