This is an archive of the discontinued LLVM Phabricator instance.

[LoopUnrollAnalyzer] Try to simplify address computation outside of loop.
Needs ReviewPublic

Authored by fhahn on Sep 16 2019, 5:15 AM.

Details

Summary

The analyzer tries to simplify address computations inside the loop
body, but not outside the loop. This means we currently fail to
recognize some pointer compares as free.

This patch adds machinery to simplify address computations outside the
loop. We use it directly in visitCmpInst, because it do not visit the
instructions outside the loop currently.

This helps with cost modelling of loops like the on in PR43305.

Event Timeline

fhahn created this revision.Sep 16 2019, 5:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 16 2019, 5:16 AM
fhahn added a comment.Dec 12 2019, 1:49 PM

ping.

This improves cost modeling for loops with exit conditions with pointer arithmetic.

Not exactly a comment on this patch specifically, but should unrolled loop analysis have some sort of special case for the loop exit? If a compare is only used by the loop exit branch, it will be dead after full unroll, so it doesn't make sense to include its cost. (I mean, in theory, if SCEV can compute the trip count of a loop, UnrolledInstAnalyzer should be able to as well, but realistically it might not be worthwhile to reach parity.)

llvm/lib/Analysis/LoopUnrollAnalyzer.cpp
76

Requiring the base to be a SCEVUnknown seems too restrictive to me... but I guess it's an existing restriction, so I guess it's okay for now.