After further investigation, it appears that that is not the case and the actual problem is the additional cases of .replacement being set makes a long chain of .replacement point to each other, which leads to a long chain of memref_referenced_p calling each other recursively.
I don't understand why the issue I mentioned in the previous email cannot happen, however. I will continue looking into the code. Thanks.