This is an archive of the discontinued LLVM Phabricator instance.

[EarlyCSEwMemorySSA] Fix failure (w/ expensive checks). Need to resetOptimizeUses for replaced instructions.
AbandonedPublic

Authored by asbirlea on Sep 5 2018, 11:09 PM.

Details

Summary

Reset optimized uses of a replaced instruction in MemorySSA, in order to correctly update it.
Failure only triggers with EXPENSIVE_CHECKS, as we marked verifyClobberSanity as expensive. This may need to be reconsidered and added under the VerifyMemorySSA bool, so we can check such failures in tests.

TODO after this patch: Remove the special handling in removeMSSA, make it a part of MSSA->removeMemoryAccess(Inst).

Diff Detail

Event Timeline

asbirlea created this revision.Sep 5 2018, 11:09 PM
asbirlea updated this revision to Diff 164300.Sep 6 2018, 3:43 PM

Add test for second failure.

asbirlea updated this revision to Diff 164319.Sep 6 2018, 4:47 PM

Adding third test-case for new failure.

Thanks for this!

This may need to be reconsidered and added under the VerifyMemorySSA bool, so we can check such failures in tests

SGTM.

I don't fully understand the failure this is meant to fix; question inline.

lib/Transforms/Scalar/EarlyCSE.cpp
607

Are these part of the fix? :)

630

AFAICT, this removeMemoryAccess should be doing all of the cache invalidation that we need to do. It should boil down to "point all of the memory things pointing at WI (which, on the first iteration, is MA) to the closest dominating MemoryAccess".

This should implicitly reset all cached Def and Use optimizations. Uses, when we want to find the actual optimized access, will start walking from said closest dominating MemoryAccess. Defs will start walking from their defining access.

Is the reset causing problems (e.g. is it somehow causing a Use to be optimized over its actual clobber)? Or is the replacement not causing invalidation? Or am I missing something?

916

(Seeing this without a corresponding MSSA update is somewhat concerning, though I guess it's reasonable to assume that if the instruction is trivially simplified + isn't trivially dead, it's not a memory instruction?)

lib/Transforms/Scalar/EarlyCSE.cpp
607

(Oh, now I see the -verify-memoryssa in tests. Is there an easy way to mark the tests as unsupported if assertions aren't enabled? If we're relying on -verify-memoryssa to do everything, and -verify-memoryssa does nothing if assertions are off, ...)

asbirlea abandoned this revision.Sep 11 2018, 4:47 PM

Dropping this, since the issue is not resolvable in general AFAICT. Please see D51960.