This is an archive of the discontinued LLVM Phabricator instance.

[CloneFunction] Constant fold terminators before checking single predecessor
ClosedPublic

Authored by uabelho on Aug 26 2018, 11:37 PM.

Details

Summary

This fixes PR31105.

There is code trying to delete dead code that does so by e.g. checking if
the single predecessor of a block is the block itself.

That check fails on a block like this
bb:

br i1 undef, label %bb, label %bb

since that has two (identical) predecessors.

However, after the check for dead blocks there is a call to
ConstantFoldTerminator on the basic block, and that call simplifies the
block to
bb:

br label %bb

Therefore we now do the call to ConstantFoldTerminator before the check if
the block is dead, so it can realize that it really is.

The original behavior lead to the block not being removed, but it was
simplified as above, and then we did a call to

Dest->replaceAllUsesWith(&*I);

with old and new being equal, and an assertion triggered.

Diff Detail

Repository
rL LLVM

Event Timeline

uabelho created this revision.Aug 26 2018, 11:37 PM
fhahn accepted this revision.Aug 28 2018, 2:21 AM

LGTM thanks!

test/Transforms/Inline/infinite-loop-two-predecessors.ll
3 ↗(On Diff #162616)

nit: I think the test could be simplified a bit

define void @f1() {
bb.0:
  br i1 false, label %bb.2, label %bb.1

bb.1:                                             ; preds = %bb.0
  br label %bb.2

bb.2:                                             ; preds = %bb.0, %bb.1
  %tmp0 = phi i1 [ true, %bb.1 ], [ false, %bb.0 ]
  br i1 %tmp0, label %bb.6, label %bb.5

bb.5:                                             ; preds = %bb.5, %bb.5
  br i1 undef, label %bb.5, label %bb.5

bb.6:                                             ; preds = %bb.2
  ret void
}
36 ↗(On Diff #162616)

CHECK-LABEL?

This revision is now accepted and ready to land.Aug 28 2018, 2:21 AM
uabelho updated this revision to Diff 162835.Aug 28 2018, 5:15 AM

Update testcase

uabelho marked an inline comment as done.Aug 28 2018, 5:17 AM
uabelho added inline comments.
test/Transforms/Inline/infinite-loop-two-predecessors.ll
3 ↗(On Diff #162616)

Indeed. Thanks!

36 ↗(On Diff #162616)

Ok. Out of curiosity, is anything really better with CHECK-LABEL compared to CHECK in this case?

This revision was automatically updated to reflect the committed changes.