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.

llvm-svn: 152193
This commit is contained in:
Richard Smith 2012-03-07 01:58:44 +00:00
parent 4a280ff48f
commit 8c029611a6
2 changed files with 12 additions and 3 deletions

View File

@ -214,6 +214,14 @@ public:
// 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 @@ public:
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);
}

View File

@ -370,7 +370,7 @@ namespace InitFromConst {
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();