This is an archive of the discontinued LLVM Phabricator instance.

[LoopPeel] Reduce peel count for chains of invariant phis.
AbandonedPublic

Authored by caojoshua on May 31 2023, 11:30 PM.

Details

Summary

If a Phi takes a previous phi in the same block as input, the phi
becomes loop invariant in the same iteration as the input.

For example, both %a and %b become loop invariant on the second
iteration:

for (...) {
  %a = phi(0, %invariant)
  %b = phi(1, %a)
}

The peeling with size limit test is modified to test its intended use
case.

Diff Detail

Event Timeline

caojoshua created this revision.May 31 2023, 11:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2023, 11:30 PM
caojoshua edited the summary of this revision. (Show Details)

Update commit msg

rename variable

Add another test case

caojoshua published this revision for review.May 31 2023, 11:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2023, 11:52 PM
nikic requested changes to this revision.Jun 1 2023, 12:12 AM

This is not how phis work. The %a in phi(1, %a) refers to the previous loop iteration.

This revision now requires changes to proceed.Jun 1 2023, 12:12 AM
fhahn added a subscriber: fhahn.Jun 1 2023, 12:17 AM
fhahn added inline comments.
llvm/lib/Transforms/Utils/LoopPeel.cpp
233

The current patch doesn't apply cleanly on main so I cannot check, but is this covered by a test?

236

nit: redundant ()

llvm/test/Transforms/LoopUnroll/peel-loop-not-forced.ll
387

Can the new tests/this change be done separately?

caojoshua abandoned this revision.Jun 1 2023, 12:23 AM

This is not how phis work. The %a in phi(1, %a) refers to the previous loop iteration.

oops. Thanks.