aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/ScalarEvolutionExpander.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2007-06-15 19:21:55 +0000
committerDan Gohman <gohman@apple.com>2007-06-15 19:21:55 +0000
commit0f0eb18addc94bf3d8179fbce162c8c4622b9866 (patch)
treeda6028eaf4d8a3860b1718635d558dfb863866f1 /lib/Analysis/ScalarEvolutionExpander.cpp
parentc2c28fc24cc0c7886da93939b0279d3f444b35dc (diff)
Fold a binary operator with constant operands when expanding code for a SCEV.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37602 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r--lib/Analysis/ScalarEvolutionExpander.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
index c8c683cb3f..3e590d68f5 100644
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -72,6 +72,11 @@ Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V,
/// of work to avoid inserting an obviously redundant operation.
Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode, Value *LHS,
Value *RHS, Instruction *&InsertPt) {
+ // Fold a binop with constant operands.
+ if (Constant *CLHS = dyn_cast<Constant>(LHS))
+ if (Constant *CRHS = dyn_cast<Constant>(RHS))
+ return ConstantExpr::get(Opcode, CLHS, CRHS);
+
// Do a quick scan to see if we have this binop nearby. If so, reuse it.
unsigned ScanLimit = 6;
for (BasicBlock::iterator IP = InsertPt, E = InsertPt->getParent()->begin();