This is an archive of the discontinued LLVM Phabricator instance.

[runtime-unroll] Prune early exits when unrolling multiple exit loops
AbandonedPublic

Authored by reames on Nov 16 2021, 3:54 PM.

Details

Summary

When we unroll a multiple exit loop, we can chose to pick our split point such that we know *all* the exits (not just latch) become dead on Count-1 iterations of the unrolled loop. Doing this trades a bit more upfront cost (e.g. computing the whole trip count expression) for reduced code size and runtime cost in the main loop.

Reviewers, while the purpose of this patch is sound, I really really dislike the structure of it. I've spent a bunch of time trying to message SCEV into eliminating the checks while only changing the loop entry condition (i.e. the split point), but all of my attempts have failed. Suggestions on how to structure this more cleanly are very very welcome.

FYI, this patch only includes the epilogue case. If we move forward with this structure, I'll post a following review to do the same thing when unrolling with a prolog.

Diff Detail

Event Timeline

reames created this revision.Nov 16 2021, 3:54 PM
reames requested review of this revision.Nov 16 2021, 3:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 16 2021, 3:54 PM
mkazantsev added inline comments.Nov 21 2021, 8:24 PM
llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
33

What's that needed for?

650

How can it be not integer type?

682

What if it will overflow (BECountSC = UINT_MAX)?

reames added inline comments.Nov 22 2021, 4:16 PM
llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
33

Stray change, will remove.

650

I believe we've fixed the case where we returned a pointer cmp, but I'm matching the existing code here because I don't remember the exact status of that.

682

Handled delicately in the existing code, behavior unchanged.

reames planned changes to this revision.Jan 5 2022, 12:00 PM

Not planning on refreshing this in the near future. Rebased failed, and not high priority at moment.

lebedev.ri resigned from this revision.Jan 12 2023, 4:57 PM

This review may be stuck/dead, consider abandoning if no longer relevant.
Removing myself as reviewer in attempt to clean dashboard.

Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 4:57 PM
Herald added a subscriber: StephenFan. · View Herald Transcript
reames abandoned this revision.Sun, Nov 26, 11:51 AM

Closing stale phabricator review. No longer actively working on this, if someone wants to pick it up, feel free.