[cfe-commits] r152193 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGenCXX/const-init-cxx11.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Tue Mar 6 17:58:44 PST 2012
Author: rsmith
Date: Tue Mar 6 19:58:44 2012
New Revision: 152193
URL: http://llvm.org/viewvc/llvm-project?rev=152193&view=rev
Log:
Don't even try to directly emit the value of a DeclRefExpr if that declaration
is not usable in a constant expression. ~2.5% speedup on 403.gcc / combine.c.
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=152193&r1=152192&r2=152193&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Mar 6 19:58:44 2012
@@ -214,6 +214,14 @@
// l-values.
Value *VisitDeclRefExpr(DeclRefExpr *E) {
+ VarDecl *VD = dyn_cast<VarDecl>(E->getDecl());
+ if (!VD && !isa<EnumConstantDecl>(E->getDecl()))
+ return EmitLoadOfLValue(E);
+ if (VD && !VD->isUsableInConstantExpressions())
+ return EmitLoadOfLValue(E);
+
+ // This is an enumerator or a variable which is usable in constant
+ // expressions. Try to emit its value instead.
Expr::EvalResult Result;
bool IsReferenceConstant = false;
QualType EvalTy = E->getType();
@@ -232,10 +240,11 @@
llvm::Constant *C = CGF.CGM.EmitConstantValue(Result.Val, EvalTy, &CGF);
// Make sure we emit a debug reference to the global variable.
- if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) {
+ if (VD) {
if (!CGF.getContext().DeclMustBeEmitted(VD))
CGF.EmitDeclRefExprDbgValue(E, C);
- } else if (isa<EnumConstantDecl>(E->getDecl())) {
+ } else {
+ assert(isa<EnumConstantDecl>(E->getDecl()));
CGF.EmitDeclRefExprDbgValue(E, C);
}
Modified: cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp?rev=152193&r1=152192&r2=152193&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp Tue Mar 6 19:58:44 2012
@@ -370,7 +370,7 @@
const bool b = true;
const int n = 5;
- const double d = 4.3;
+ constexpr double d = 4.3;
struct S { int n = 7; S *p = 0; };
constexpr S s = S();
More information about the cfe-commits
mailing list