serge-sans-paille updated this revision to Diff 245606. serge-sans-paille added a comment. Herald added subscribers: llvm-commits, hiraditya. Herald added a project: LLVM.
Other approach to the problem: modify `Value::SetNameImpl` Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D74871/new/ https://reviews.llvm.org/D74871 Files: clang/test/CodeGen/discard_value_names.ll llvm/lib/IR/Value.cpp Index: llvm/lib/IR/Value.cpp =================================================================== --- llvm/lib/IR/Value.cpp +++ llvm/lib/IR/Value.cpp @@ -228,7 +228,10 @@ void Value::setNameImpl(const Twine &NewName) { // Fast-path: LLVMContext can be set to strip out non-GlobalValue names if (getContext().shouldDiscardValueNames() && !isa<GlobalValue>(this)) - return; + // Unless the name of the variable was set previously and we're trying to + // eras it. + if (!(hasName() && NewName.isTriviallyEmpty())) + return; // Fast path for common IRBuilder case of setName("") when there is no name. if (NewName.isTriviallyEmpty() && !hasName()) Index: clang/test/CodeGen/discard_value_names.ll =================================================================== --- /dev/null +++ clang/test/CodeGen/discard_value_names.ll @@ -0,0 +1,13 @@ +; Check compatibility between clang parsing IR and discard-value-names +; RUN: %clang -fdiscard-value-names -S %s -o/dev/null 2>&1 +; RUN: %clang_cc1 -discard-value-names -S %s -o/dev/null + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64--linux-gnu" + +define linkonce_odr float @sin_f32(float %x) #0 { + ret float 0. +} + +attributes #0 = { alwaysinline } +
Index: llvm/lib/IR/Value.cpp =================================================================== --- llvm/lib/IR/Value.cpp +++ llvm/lib/IR/Value.cpp @@ -228,7 +228,10 @@ void Value::setNameImpl(const Twine &NewName) { // Fast-path: LLVMContext can be set to strip out non-GlobalValue names if (getContext().shouldDiscardValueNames() && !isa<GlobalValue>(this)) - return; + // Unless the name of the variable was set previously and we're trying to + // eras it. + if (!(hasName() && NewName.isTriviallyEmpty())) + return; // Fast path for common IRBuilder case of setName("") when there is no name. if (NewName.isTriviallyEmpty() && !hasName()) Index: clang/test/CodeGen/discard_value_names.ll =================================================================== --- /dev/null +++ clang/test/CodeGen/discard_value_names.ll @@ -0,0 +1,13 @@ +; Check compatibility between clang parsing IR and discard-value-names +; RUN: %clang -fdiscard-value-names -S %s -o/dev/null 2>&1 +; RUN: %clang_cc1 -discard-value-names -S %s -o/dev/null + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64--linux-gnu" + +define linkonce_odr float @sin_f32(float %x) #0 { + ret float 0. +} + +attributes #0 = { alwaysinline } +
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits