This is an archive of the discontinued LLVM Phabricator instance.

[SimpleLoopUnswitch] Update DefaultExit condition to check unreachable is not empty.
ClosedPublic

Authored by asbirlea on Apr 16 2020, 12:45 AM.

Details

Summary

Update the check for the default exit block to not only check that the
terminator is not unreachable, but also check that unreachable block has
*only* the unreachable instruction.

Diff Detail

Event Timeline

asbirlea created this revision.Apr 16 2020, 12:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 16 2020, 12:45 AM
Herald added a subscriber: hiraditya. · View Herald Transcript

Gentle ping.

chandlerc added inline comments.May 4 2020, 7:42 PM
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
601

Rather than trying to name after the implementation, how about naming after the usage? IsTriviallyUnswitchableExitBlock?

I'd also use a reference here, but that's a pretty minor point.

602–609

I'd rewrite this to use early exit rather than combining flags, and add some comments about the non-obvious part (IMO, the non-empty unreachable).

Something like:

if (L.contains(BBToCheck))
  return false;
if (!areLoopExitPHIsLoopInvariant(L, *ParentBB, *BBToCheck))
  return false;
....
asbirlea updated this revision to Diff 262238.May 5 2020, 3:30 PM
asbirlea marked 2 inline comments as done.

Address comments.

efriedma added inline comments.
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
614

Need to skip debug info

chandlerc accepted this revision.May 5 2020, 9:09 PM

LGTM with the addition of skipping debug info as Eli suggests.

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
614

I hadn't expected that to matter as the thing we care most about here are the empty-but-unreachable blocks *created* by this same pass (and those would never have debug info).

But I suppose you're right that we still need to skip debug info because then the frontend adding it could suddenly enable (pointless) unswitching.

Ugh, but good catch.

This revision is now accepted and ready to land.May 5 2020, 9:09 PM
asbirlea marked an inline comment as done.May 6 2020, 3:39 PM
asbirlea added inline comments.
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
614

Just to clarify, when TI is an unreachable, the check should instead traverse BBToCheck and verify that if any instructions beside TI exists, they are an IntrinsicInstr and I->getIntrinsicID() is one of: Intrinsic::dbg_addr, Intrinsic::dbg_declare, Intrinsic::dbg_label or Intrinsic::dbg_value.
Is this right, or is there a simpler way to add this check?

Thanks for the input!

efriedma added inline comments.May 6 2020, 5:50 PM
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
614

BBToCheck()->getFirstNonPHIOrDbg() != TI?

asbirlea updated this revision to Diff 262746.May 7 2020, 1:38 PM
asbirlea marked 3 inline comments as done.

Address comment.
Thank you for the clarifications!

This revision was automatically updated to reflect the committed changes.