The following miscompile was uncovered in GVN, to reproduce:
opt --passes=gvn gvntest.ll on gvntest.ll.txt
The miscompiled output is:
testafterbad.ll.txt
It appears that if the cache entry is cleared at MemoryDependenceAnalysis.cpp:1060 with NonLocalPointerDeps.erase(CacheKey); before the insert, the test is correct.
The resulting IR with this change:
testaftergood.ll.txt