[llvm] [IR] Do not track metadata uses of ConstantData (PR #223303)
Jannik Silvanus via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 14 01:16:32 PDT 2026
================
@@ -551,56 +558,44 @@ void ValueAsMetadata::handleRAUW(Value *From, Value *To) {
assert(From != To && "Expected changed value");
assert(&From->getContext() == &To->getContext() && "Expected same context");
- LLVMContext &Context = From->getType()->getContext();
- auto &Store = Context.pImpl->ValuesAsMetadata;
+ auto &Store = From->getContext().pImpl->ValuesAsMetadata;
auto I = Store.find(From);
if (I == Store.end()) {
assert(!From->IsUsedByMD && "Expected From not to be used by metadata");
return;
}
- // Remove old entry from the map.
assert(From->IsUsedByMD && "Expected From to be used by metadata");
From->IsUsedByMD = false;
ValueAsMetadata *MD = I->second;
assert(MD && "Expected valid metadata");
assert(MD->getValue() == From && "Expected valid mapping");
Store.erase(I);
- if (isa<LocalAsMetadata>(MD)) {
- if (auto *C = dyn_cast<Constant>(To)) {
- // Local became a constant.
- MD->replaceAllUsesWith(ConstantAsMetadata::get(C));
- delete MD;
- return;
- }
- if (getLocalFunctionMetadata(From) && getLocalFunctionMetadata(To) &&
- getLocalFunctionMetadata(From) != getLocalFunctionMetadata(To)) {
- // DISubprogram changed.
- MD->replaceAllUsesWith(nullptr);
- delete MD;
- return;
- }
- } else if (!isa<Constant>(To)) {
- // Changed to function-local value.
- MD->replaceAllUsesWith(nullptr);
- delete MD;
+ // The uses of a ConstantData node are not tracked, so the node can only be
+ // retyped in place.
+ if (isa<ConstantData>(From)) {
----------------
jasilvanus wrote:
I think this is fine. It does break a downstream use case for us (no longer being able to `handleRAUW` with `From` being `ConstantData`), but it think we can just create new `ValueAsMetadata` nodes and replace metadata operands instead of updating existing `ValueAsMetadata` nodes.
As described in https://github.com/llvm/llvm-project/pull/76969, we use ConstantData `poison` metadata to indicate pointee type information in our graphics compiler, and in some cases need to change pointee type information, which corresponds to a change of the `ValueAsMetadata` node from one `ConstantData` poison value to a different one. At the time `ValueAsMetadata` could easily support `handleRAUW`, so it seemed better to use that (both faster and simpler), but if we can realize performance gains by not supporting this at all we can switch to a recreation path. We are iterating over all metadata in the module in that place anyways.
https://github.com/llvm/llvm-project/pull/223303
More information about the llvm-commits
mailing list