aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorManuel Jacob <me@manueljacob.de>2016-01-21 06:26:35 +0000
committerManuel Jacob <me@manueljacob.de>2016-01-21 06:26:35 +0000
commita61ca37b6dd94cf956d75356d8d1fe6a81a234ae (patch)
treecc7713b01d18be247488684745ef7bc4e959b19d /llvm/lib/Analysis/ConstantFolding.cpp
parent56ab5f0289489f2c18ec043fcdeeb74a8c7e64f3 (diff)
downloadllvm-a61ca37b6dd94cf956d75356d8d1fe6a81a234ae.zip
llvm-a61ca37b6dd94cf956d75356d8d1fe6a81a234ae.tar.gz
llvm-a61ca37b6dd94cf956d75356d8d1fe6a81a234ae.tar.bz2
Introduce ConstantFoldBinaryOpOperands function and migrate some callers of ConstantFoldInstOperands to use it. NFC.
Summary: Although this is a slight cleanup on its own, the main motivation is to refactor the constant folding API to ease migration to opaque pointers. This will be follow-up work. Reviewers: eddyb Subscribers: dblaikie, llvm-commits Differential Revision: http://reviews.llvm.org/D16378 llvm-svn: 258389
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 8ff018f..3ddc10a 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1010,14 +1010,8 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,
const DataLayout &DL,
const TargetLibraryInfo *TLI) {
// Handle easy binops first.
- if (Instruction::isBinaryOp(Opcode)) {
- if (isa<ConstantExpr>(Ops[0]) || isa<ConstantExpr>(Ops[1])) {
- if (Constant *C = SymbolicallyEvaluateBinop(Opcode, Ops[0], Ops[1], DL))
- return C;
- }
-
- return ConstantExpr::get(Opcode, Ops[0], Ops[1]);
- }
+ if (Instruction::isBinaryOp(Opcode))
+ return ConstantFoldBinaryOpOperands(Opcode, Ops[0], Ops[1], DL);
switch (Opcode) {
default: return nullptr;
@@ -1176,14 +1170,23 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate,
Predicate, CE0->getOperand(1), Ops1, DL, TLI);
unsigned OpC =
Predicate == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or;
- Constant *Ops[] = { LHS, RHS };
- return ConstantFoldInstOperands(OpC, LHS->getType(), Ops, DL, TLI);
+ return ConstantFoldBinaryOpOperands(OpC, LHS, RHS, DL);
}
}
return ConstantExpr::getCompare(Predicate, Ops0, Ops1);
}
+Constant *llvm::ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS,
+ Constant *RHS,
+ const DataLayout &DL) {
+ assert(Instruction::isBinaryOp(Opcode));
+ if (isa<ConstantExpr>(LHS) || isa<ConstantExpr>(RHS))
+ if (Constant *C = SymbolicallyEvaluateBinop(Opcode, LHS, RHS, DL))
+ return C;
+
+ return ConstantExpr::get(Opcode, LHS, RHS);
+}
/// Given a constant and a getelementptr constantexpr, return the constant value
/// being addressed by the constant expression, or null if something is funny