This is an archive of the discontinued LLVM Phabricator instance.

[LoopBase] Strengthen isLoopExiting by requiring that BB must be inside the loop.
ClosedPublic

Authored by fhahn on Jun 28 2019, 12:01 PM.

Details

Summary

Currently isLoopExiting returns true for BBs that are not part of the
loop. To avoid hiding subtle bugs, this patch adds an assertion to make
sure the passed BB is inside the loop. Alternatively, we could return
false for BBs outside the loop, but I think it makes sense to restrict
it to BBs inside a loop.

Just one use in AMDGPUTTIImpl needed updating.

Diff Detail

Repository
rL LLVM

Event Timeline

fhahn created this revision.Jun 28 2019, 12:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2019, 12:01 PM

Adding @arsenm & @nhaehnle for the AMDGPU part.

I agree the change to the API makes sense.

llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
122 ↗(On Diff #207125)

This seems substantially different from the original logic. Probably it should be if (!L->contains(Succ0) || L->isLoopExiting(Succ0) || [...]... which would be effectively the same as the original logic in most cases. Given a loop in LoopSimplify form, the only case I can think of where it wouldn't be the same is if Succ0 or Succ1 has no successors (ends in a "ret" or "unreachable").

fhahn marked an inline comment as done.Jun 28 2019, 2:27 PM
fhahn added inline comments.
llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
122 ↗(On Diff #207125)

I originally thought the original check was intended to check for actual exiting blocks, but I can change it to check for exiting blocks or blocks outside the loop, if that is the intended behavior.

LGTM to the LoopInfo change only. The other portion should probably be done in a separate change as the set of reviewers are likely to be basically distinct. (I don't care which order.)

fhahn updated this revision to Diff 207233.Jun 30 2019, 1:15 PM

Split off AMDGPU part to D63980

fhahn added a comment.Jul 3 2019, 6:59 AM

The AMDGPU fix was committed, so this should be ready to go in :) @reames, it would be great if you could accept it on Phab

reames accepted this revision.Jul 3 2019, 9:30 AM

The AMDGPU fix was committed, so this should be ready to go in :) @reames, it would be great if you could accept it on Phab

Did so, but this is not required. Once an LGTM has been given, a patch is clear to land whether accepted in phab or not.

This revision is now accepted and ready to land.Jul 3 2019, 9:30 AM
This revision was automatically updated to reflect the committed changes.