This is an archive of the discontinued LLVM Phabricator instance.

[MemorySSA] Add previous def to cache when found, even if trivial.
ClosedPublic

Authored by asbirlea on Apr 12 2019, 1:52 PM.

Details

Summary

When inserting a new Def, MemorySSA may be have non-minimal number of Phis.
While inserting, the walk to find the previous definition may cleanup minimal Phis.
When the last definition is trivial to obtain, we do not cache it.

It is possible while getting the previous definition for a Def to get two different answers:

  • one that was straight-forward to find when walking the first path (a trivial phi in this case), and
  • another that follows a cleanup of the trivial phi, it determines it may need additional Phi nodes, it inserts them and returns a new phi in the same position as the former trivial one.

While the Phis added for the second path are all redundant, they are not complete (the walk is only done upwards), and they are not properly cleaned up afterwards.

A way to fix this problem is to cache the straight-forward answer we got on the first walk.
The caching is only kept for the duration of a getPreviousDef call, and for Phis we use TrackingVH, so removing the trivial phi will lead to replacing it with the next dominating phi in the cache.
Resolves PR40749.

Diff Detail

Repository
rL LLVM

Event Timeline

asbirlea created this revision.Apr 12 2019, 1:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 12 2019, 1:52 PM
Herald added subscribers: Prazek, jlebar. · View Herald Transcript

Thanks!

test/Analysis/MemorySSA/pr40749_2.ll
1 ↗(On Diff #194958)

; REQUIRES: asserts?

This revision is now accepted and ready to land.Apr 12 2019, 2:34 PM
asbirlea updated this revision to Diff 194965.Apr 12 2019, 2:47 PM

Thank you for the review!

This revision was automatically updated to reflect the committed changes.