This patch enhances the PtrReplacer as follows: 1. Users are now collected iteratively to be generous on the stack. In the case of PHIs with incoming values which have not yet been visited, they are pushed back into the stack for reconsideration. 2. Replace users of the pointer root in a reverse-postorder traversal, instead of a simple traversal over the collected users. This reordering ensures that the uses of an instruction are replaced before replacing the instruction itself. 3. During the replacement of PHI, use the same incoming value if it does not have a replacement. This patch specifically fixes the case when an incoming value of a PHI is addrspacecasted. This reland PR includes a fix for an assertion failure caused by https://github.com/llvm/llvm-project/pull/137215, which was reverted. The failing test involved a phi and gep depending on each other, in which case the PtrReplacer did not order them correctly for replacement. This patch fixes it by adding a check during the definition of `PostOrderWorklist`.
61 KiB
61 KiB