aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-03-07 01:58:44 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-03-07 01:58:44 +0000
commit946e2726f91c17574d248f9c4b3eeea41e892a22 (patch)
treedba90d0b7abc17149dcc6ee9dab9357542a332a7 /lib/CodeGen
parentbef35c91b594f66216f4aab303b71a6c5ab7abcf (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152193 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGExprScalar.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index d5ef402d22..8ed36aac5f 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -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);
}