aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/InstructionSimplify.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/InstructionSimplify.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/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp97
1 files changed, 29 insertions, 68 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index ca12815..1f4c329 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -528,11 +528,8 @@ static Value *ThreadCmpOverPHI(CmpInst::Predicate Pred, Value *LHS, Value *RHS,
static Value *SimplifyAddInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
const Query &Q, unsigned MaxRecurse) {
if (Constant *CLHS = dyn_cast<Constant>(Op0)) {
- if (Constant *CRHS = dyn_cast<Constant>(Op1)) {
- Constant *Ops[] = { CLHS, CRHS };
- return ConstantFoldInstOperands(Instruction::Add, CLHS->getType(), Ops,
- Q.DL, Q.TLI);
- }
+ if (Constant *CRHS = dyn_cast<Constant>(Op1))
+ return ConstantFoldBinaryOpOperands(Instruction::Add, CLHS, CRHS, Q.DL);
// Canonicalize the constant to the RHS.
std::swap(Op0, Op1);
@@ -660,11 +657,8 @@ static Constant *computePointerDifference(const DataLayout &DL, Value *LHS,
static Value *SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
const Query &Q, unsigned MaxRecurse) {
if (Constant *CLHS = dyn_cast<Constant>(Op0))
- if (Constant *CRHS = dyn_cast<Constant>(Op1)) {
- Constant *Ops[] = { CLHS, CRHS };
- return ConstantFoldInstOperands(Instruction::Sub, CLHS->getType(),
- Ops, Q.DL, Q.TLI);
- }
+ if (Constant *CRHS = dyn_cast<Constant>(Op1))
+ return ConstantFoldBinaryOpOperands(Instruction::Sub, CLHS, CRHS, Q.DL);
// X - undef -> undef
// undef - X -> undef
@@ -787,11 +781,8 @@ Value *llvm::SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
static Value *SimplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
const Query &Q, unsigned MaxRecurse) {
if (Constant *CLHS = dyn_cast<Constant>(Op0)) {
- if (Constant *CRHS = dyn_cast<Constant>(Op1)) {
- Constant *Ops[] = { CLHS, CRHS };
- return ConstantFoldInstOperands(Instruction::FAdd, CLHS->getType(),
- Ops, Q.DL, Q.TLI);
- }
+ if (Constant *CRHS = dyn_cast<Constant>(Op1))
+ return ConstantFoldBinaryOpOperands(Instruction::FAdd, CLHS, CRHS, Q.DL);
// Canonicalize the constant to the RHS.
std::swap(Op0, Op1);
@@ -829,11 +820,8 @@ static Value *SimplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
static Value *SimplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF,
const Query &Q, unsigned MaxRecurse) {
if (Constant *CLHS = dyn_cast<Constant>(Op0)) {
- if (Constant *CRHS = dyn_cast<Constant>(Op1)) {
- Constant *Ops[] = { CLHS, CRHS };
- return ConstantFoldInstOperands(Instruction::FSub, CLHS->getType(),
- Ops, Q.DL, Q.TLI);
- }
+ if (Constant *CRHS = dyn_cast<Constant>(Op1))
+ return ConstantFoldBinaryOpOperands(Instruction::FSub, CLHS, CRHS, Q.DL);
}
// fsub X, 0 ==> X
@@ -867,11 +855,8 @@ static Value *SimplifyFMulInst(Value *Op0, Value *Op1,
const Query &Q,
unsigned MaxRecurse) {
if (Constant *CLHS = dyn_cast<Constant>(Op0)) {
- if (Constant *CRHS = dyn_cast<Constant>(Op1)) {
- Constant *Ops[] = { CLHS, CRHS };
- return ConstantFoldInstOperands(Instruction::FMul, CLHS->getType(),
- Ops, Q.DL, Q.TLI);
- }
+ if (Constant *CRHS = dyn_cast<Constant>(Op1))
+ return ConstantFoldBinaryOpOperands(Instruction::FMul, CLHS, CRHS, Q.DL);
// Canonicalize the constant to the RHS.
std::swap(Op0, Op1);
@@ -893,11 +878,8 @@ static Value *SimplifyFMulInst(Value *Op0, Value *Op1,
static Value *SimplifyMulInst(Value *Op0, Value *Op1, const Query &Q,
unsigned MaxRecurse) {
if (Constant *CLHS = dyn_cast<Constant>(Op0)) {
- if (Constant *CRHS = dyn_cast<Constant>(Op1)) {
- Constant *Ops[] = { CLHS, CRHS };
- return ConstantFoldInstOperands(Instruction::Mul, CLHS->getType(),
- Ops, Q.DL, Q.TLI);
- }
+ if (Constant *CRHS = dyn_cast<Constant>(Op1))
+ return ConstantFoldBinaryOpOperands(Instruction::Mul, CLHS, CRHS, Q.DL);
// Canonicalize the constant to the RHS.
std::swap(Op0, Op1);
@@ -992,12 +974,9 @@ Value *llvm::SimplifyMulInst(Value *Op0, Value *Op1, const DataLayout &DL,
/// If not, this returns null.
static Value *SimplifyDiv(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
const Query &Q, unsigned MaxRecurse) {
- if (Constant *C0 = dyn_cast<Constant>(Op0)) {
- if (Constant *C1 = dyn_cast<Constant>(Op1)) {
- Constant *Ops[] = { C0, C1 };
- return ConstantFoldInstOperands(Opcode, C0->getType(), Ops, Q.DL, Q.TLI);
- }
- }
+ if (Constant *C0 = dyn_cast<Constant>(Op0))
+ if (Constant *C1 = dyn_cast<Constant>(Op1))
+ return ConstantFoldBinaryOpOperands(Opcode, C0, C1, Q.DL);
bool isSigned = Opcode == Instruction::SDiv;
@@ -1157,12 +1136,9 @@ Value *llvm::SimplifyFDivInst(Value *Op0, Value *Op1, FastMathFlags FMF,
/// If not, this returns null.
static Value *SimplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
const Query &Q, unsigned MaxRecurse) {
- if (Constant *C0 = dyn_cast<Constant>(Op0)) {
- if (Constant *C1 = dyn_cast<Constant>(Op1)) {
- Constant *Ops[] = { C0, C1 };
- return ConstantFoldInstOperands(Opcode, C0->getType(), Ops, Q.DL, Q.TLI);
- }
- }
+ if (Constant *C0 = dyn_cast<Constant>(Op0))
+ if (Constant *C1 = dyn_cast<Constant>(Op1))
+ return ConstantFoldBinaryOpOperands(Opcode, C0, C1, Q.DL);
// X % undef -> undef
if (match(Op1, m_Undef()))
@@ -1309,12 +1285,9 @@ static bool isUndefShift(Value *Amount) {
/// If not, this returns null.
static Value *SimplifyShift(unsigned Opcode, Value *Op0, Value *Op1,
const Query &Q, unsigned MaxRecurse) {
- if (Constant *C0 = dyn_cast<Constant>(Op0)) {
- if (Constant *C1 = dyn_cast<Constant>(Op1)) {
- Constant *Ops[] = { C0, C1 };
- return ConstantFoldInstOperands(Opcode, C0->getType(), Ops, Q.DL, Q.TLI);
- }
- }
+ if (Constant *C0 = dyn_cast<Constant>(Op0))
+ if (Constant *C1 = dyn_cast<Constant>(Op1))
+ return ConstantFoldBinaryOpOperands(Opcode, C0, C1, Q.DL);
// 0 shift by X -> 0
if (match(Op0, m_Zero()))
@@ -1558,11 +1531,8 @@ static Value *SimplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1) {
static Value *SimplifyAndInst(Value *Op0, Value *Op1, const Query &Q,
unsigned MaxRecurse) {
if (Constant *CLHS = dyn_cast<Constant>(Op0)) {
- if (Constant *CRHS = dyn_cast<Constant>(Op1)) {
- Constant *Ops[] = { CLHS, CRHS };
- return ConstantFoldInstOperands(Instruction::And, CLHS->getType(),
- Ops, Q.DL, Q.TLI);
- }
+ if (Constant *CRHS = dyn_cast<Constant>(Op1))
+ return ConstantFoldBinaryOpOperands(Instruction::And, CLHS, CRHS, Q.DL);
// Canonicalize the constant to the RHS.
std::swap(Op0, Op1);
@@ -1717,11 +1687,8 @@ static Value *SimplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1) {
static Value *SimplifyOrInst(Value *Op0, Value *Op1, const Query &Q,
unsigned MaxRecurse) {
if (Constant *CLHS = dyn_cast<Constant>(Op0)) {
- if (Constant *CRHS = dyn_cast<Constant>(Op1)) {
- Constant *Ops[] = { CLHS, CRHS };
- return ConstantFoldInstOperands(Instruction::Or, CLHS->getType(),
- Ops, Q.DL, Q.TLI);
- }
+ if (Constant *CRHS = dyn_cast<Constant>(Op1))
+ return ConstantFoldBinaryOpOperands(Instruction::Or, CLHS, CRHS, Q.DL);
// Canonicalize the constant to the RHS.
std::swap(Op0, Op1);
@@ -1853,11 +1820,8 @@ Value *llvm::SimplifyOrInst(Value *Op0, Value *Op1, const DataLayout &DL,
static Value *SimplifyXorInst(Value *Op0, Value *Op1, const Query &Q,
unsigned MaxRecurse) {
if (Constant *CLHS = dyn_cast<Constant>(Op0)) {
- if (Constant *CRHS = dyn_cast<Constant>(Op1)) {
- Constant *Ops[] = { CLHS, CRHS };
- return ConstantFoldInstOperands(Instruction::Xor, CLHS->getType(),
- Ops, Q.DL, Q.TLI);
- }
+ if (Constant *CRHS = dyn_cast<Constant>(Op1))
+ return ConstantFoldBinaryOpOperands(Instruction::Xor, CLHS, CRHS, Q.DL);
// Canonicalize the constant to the RHS.
std::swap(Op0, Op1);
@@ -3730,11 +3694,8 @@ static Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
case Instruction::Xor: return SimplifyXorInst(LHS, RHS, Q, MaxRecurse);
default:
if (Constant *CLHS = dyn_cast<Constant>(LHS))
- if (Constant *CRHS = dyn_cast<Constant>(RHS)) {
- Constant *COps[] = {CLHS, CRHS};
- return ConstantFoldInstOperands(Opcode, LHS->getType(), COps, Q.DL,
- Q.TLI);
- }
+ if (Constant *CRHS = dyn_cast<Constant>(RHS))
+ return ConstantFoldBinaryOpOperands(Opcode, CLHS, CRHS, Q.DL);
// If the operation is associative, try some generic simplifications.
if (Instruction::isAssociative(Opcode))