https://github.com/arsenm approved this pull request. LGTM but I think this should try to use ValueMap and/or WeakTrackingVH and replacements. This approach seems more complicated than necessary to keep values updated https://github.com/llvm/llvm-project/pull/98985