From daf4eef5c3b99cdbc894f6bee40b4d047c5e6553 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Fri, 20 Jan 2017 18:38:36 +0000 Subject: ReadExpr::create() was missing an opportunity to constant fold when handling constant arrays. --- lib/Expr/Expr.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/Expr') diff --git a/lib/Expr/Expr.cpp b/lib/Expr/Expr.cpp index 15f52184..ac50dda2 100644 --- a/lib/Expr/Expr.cpp +++ b/lib/Expr/Expr.cpp @@ -529,6 +529,7 @@ ref ReadExpr::create(const UpdateList &ul, ref index) { // a smart UpdateList so it is not worth rescanning. const UpdateNode *un = ul.head; + bool updateListHasSymbolicWrites = false; for (; un; un=un->next) { ref cond = EqExpr::create(index, un->index); @@ -536,10 +537,22 @@ ref ReadExpr::create(const UpdateList &ul, ref index) { if (CE->isTrue()) return un->value; } else { + updateListHasSymbolicWrites = true; break; } } + if (ul.root->isConstantArray() && !updateListHasSymbolicWrites) { + if (ConstantExpr *CE = dyn_cast(index)) { + assert(CE->getWidth() <= 64 && "Index too large"); + uint64_t concreteIndex = CE->getZExtValue(); + uint64_t size = ul.root->size; + if (concreteIndex < size) { + return ul.root->constantValues[concreteIndex]; + } + } + } + return ReadExpr::alloc(ul, index); } -- cgit 1.4.1