This is an archive of the discontinued LLVM Phabricator instance.

[LICM] Keep metadata on control equivalent hoists
ClosedPublic

Authored by sanjoy on Jan 27 2016, 7:16 PM.

Details

Summary

If the instruction we're hoisting out of a loop into its preheader is
guaranteed to have executed in the loop, then the metadata associated
with the instruction (e.g. !range or !dereferenceable) is valid in the
preheader. This is because once we're in the preheader, we know we're
eventually going to reach the location the metadata was valid at.

This change makes LICM smarter around this, and helps it recognize cases
like these:

do {
  int a = *ptr; !range !0
  ...
} while (i++ < N);

to

int a = *ptr; !range !0
do {
  ...
} while (i++ < N);

Earlier we'd drop the !range metadata after hoisting the load from
ptr.

Diff Detail

Repository
rL LLVM

Event Timeline

sanjoy updated this revision to Diff 46212.Jan 27 2016, 7:16 PM
sanjoy retitled this revision from to [LICM] Keep metadata on control equivalent hoists.
sanjoy updated this object.
sanjoy added a reviewer: igor-laevsky.
sanjoy added a subscriber: llvm-commits.
sanjoy updated this object.Jan 27 2016, 7:16 PM
igor-laevsky accepted this revision.Jan 28 2016, 6:23 AM
igor-laevsky edited edge metadata.

looks good

lib/Transforms/Scalar/LICM.cpp
736–739 ↗(On Diff #46212)

This could be moved under if (I.hasMetadataOtherThanDebugLoc()) condition. So that KeepMetadata variable is not required. But it looks good either way.

This revision is now accepted and ready to land.Jan 28 2016, 6:23 AM
This revision was automatically updated to reflect the committed changes.
sanjoy marked an inline comment as done.