[llvm] [IR] Do not track metadata uses of ConstantData (PR #223303)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 13 23:49:34 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)) {
----------------
MaskRay wrote:
Apologies. My reply is about when `To` is a ConstantData.
When `From` is a ConstantData, I believe there is no such use case in tree. In #76969 (2024), @jasilvanus added `TEST_F(ValueAsMetadataTest, handleRAUWWithTypeChange) {`, which is the only test in tree where `From` is a ConstantData. I am not sure such a RAUW is useful. Unless @jasilvanus comes up with a real use case, I'd delete this unittest.
https://github.com/llvm/llvm-project/pull/223303
More information about the llvm-commits
mailing list