Page MenuHomePhabricator

[LoopVersioning] Annotate versioned loop with noalias metadata

Authored by anemet on Jan 28 2016, 11:28 PM.



If we decide to version a loop to benefit a transformation, it makes
sense to record the now non-aliasing accesses in the newly versioned
loop. This allows non-aliasing information to be used by subsequent

One example is 456.hmmer in SPECint2006 where after loop distribution,
we vectorize one of the newly distributed loops. To vectorize we
version this loop to fully disambiguate may-aliasing accesses. If we
add the noalias markers, we can use the same information in a later DSE
pass to eliminate some dead stores which amounts to ~25% of the
instructions of this hot memory-pipeline-bound loop. The overall
performance improves by 18% on our ARM64.

The scoped noalias annotation is added in LoopVersioning. The patch
then enables this for loop distribution. A follow-on patch will enable
it for the vectorizer. Eventually this should be run by default when
versioning the loop but first I'd like to get some feedback whether my
understanding and application of scoped noalias metadata is correct.

Essentially my approach was to have a separate alias domain for each
versioning of the loop. For example, if we first version in loop
distribution and then in vectorization of the distributed loops, we have
a different set of memchecks for each versioning. By keeping the scopes
in different domains they can conveniently be defined independently
since different alias domains don't affect each other.

As written, I also have a separate domain for each loop. This is not
necessary and we could save some metadata here by using the same domain
across the different loops. I don't think it's a big deal either way.

Probably the best is to review the tests first to see if I mapped this
problem correctly to scoped noalias markers. I have plenty of comments
in the tests.

Note that the interface is prepared for the vectorizer which needs the
annotateInstWithNoAlias API. The vectorizer does not use LoopVersioning
so we need a way to pass in the versioned instructions. This is also
why the maps have to become part of the object state.

Also currently, we only have an AA-aware DSE after the vectorizer if we
also run the LTO pipeline. Depending how widely this triggers we may
want to schedule a DSE toward the end of the regular pass pipeline.

Diff Detail


Event Timeline

anemet updated this revision to Diff 46358.Jan 28 2016, 11:28 PM
anemet retitled this revision from to [LoopVectorizer/LoopVersioning] Annotate versioned loop with noalias metadata.
anemet updated this object.
anemet added reviewers: hfinkel, nadav, ashutosh.nema.
anemet added subscribers: mcrosier, llvm-commits.
anemet updated this object.Jan 28 2016, 11:34 PM
anemet updated this revision to Diff 46682.Feb 2 2016, 11:18 AM
anemet retitled this revision from [LoopVectorizer/LoopVersioning] Annotate versioned loop with noalias metadata to [LoopVersioning] Annotate versioned loop with noalias metadata.
anemet updated this object.

More testing revealed that the vectorizer part of this patch is incorrect.

It annotated the loop *before* versioning so the scalar loop also carried
these annotations. This is incorrect because we bail to the scalar loop if
the memchecks fail.

So I will add LoopVectorizer support for this separately in a follow-on patch.
I will also include a testcase for the above bug.

Also updating the title and the description accordingly.

anemet updated this revision to Diff 47777.Feb 12 2016, 12:48 AM
anemet updated this object.

I implemented the LoopVectorizer part of this work under D17191. For the
vectorizer, the new annotation interface had to be tweaked. It now consists
of smaller functions which are probably easier to follow so I folded most of
those changes into this patch.

Gerolf added a subscriber: Gerolf.Feb 17 2016, 2:07 PM
hfinkel accepted this revision.Mar 14 2016, 5:05 PM
hfinkel edited edge metadata.

LGTM, thanks!

3 ↗(On Diff #47777)

generate -> generated

This revision is now accepted and ready to land.Mar 14 2016, 5:05 PM
This revision was automatically updated to reflect the committed changes.