https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/237133
If we already have a global variable created for the apvalue lvalue base expression, just get the pointer to the existing global instead of evaluating the expression again. >From 1b1c6d7f0e956bd52ace122c8b187280c5e5580b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Fri, 30 Oct 2026 08:51:35 +0100 Subject: [PATCH] [clang][bytecode][NFC] Avoid re-evaluating APValue base expressions If we already have a global variable created for the apvalue lvalue base expression, just get the pointer to the existing global instead of evaluating the expression again. --- clang/lib/AST/ByteCode/Compiler.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 164dd155debd4..079c24344f21a 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -5994,8 +5994,15 @@ bool Compiler<Emitter>::visitAPValue(const APValue &Val, PrimType ValType, APValue::LValueBase Base = Val.getLValueBase(); QualType EntryType; if (const Expr *BaseExpr = Base.dyn_cast<const Expr *>()) { - if (!this->visit(BaseExpr)) - return false; + // Try to avoid evaluating the BaseExpr multiple times. + if (UnsignedOrNone GlobalIndex = P.getGlobal(BaseExpr); + GlobalIndex && P.isGlobalInitialized(*GlobalIndex)) { + if (!this->emitGetPtrGlobal(*GlobalIndex, Info)) + return false; + } else { + if (!this->visit(BaseExpr)) + return false; + } EntryType = BaseExpr->getType(); } else if (const auto *VD = Base.dyn_cast<const ValueDecl *>()) { if (!this->visitDeclRef(VD, Info.asExpr())) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
