[RemoveDIs][DebugInfo] Handle RAUW from dead constants #80837
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently when a constant value dies, all
ValueAsMetadata
uses of that constant will be replaced withnullptr
. For debug info intrinsics, thisRAUW
operation ends up being passed toMetadataAsValue
, which canonicalizes thenullptr
argument, replacing it with an emptyMDNode
,!{}
(this is one of the only ways that anMDNode
can be the first argument of a debug intrinsic). Since DPValues don't useMetadataAsValue
, this is skipped and we end up with just anullptr
; currently this doesn't cause any problems because for most operations we use a wrapper that translates nullness, but will cause problems when we start printing DPValues, and should be considered an invalid state.There are no tests for this change because currently any
nullptr
argument in a DPValue will be replaced with!{}
when we convert it back to a debug intrinsic before printing, meaning this change is "NFC" for now. Instead, this patch adds an assert before converting back to debug intrinsics, which will cause the following tests to fail without the functional change:Hopefully this also paves the way to eliminating instances of empty
MDNodes
appearing in DPValues at any time as well, but there may be other cases that introduce them as well (@OCHyams may be familiar?).