|
@@ -205,9 +205,9 @@ unsigned ReassociatePass::getRank(Value *V) {
|
|
|
for (unsigned i = 0, e = I->getNumOperands(); i != e && Rank != MaxRank; ++i)
|
|
|
Rank = std::max(Rank, getRank(I->getOperand(i)));
|
|
|
|
|
|
- // If this is a not or neg instruction, do not count it for rank. This
|
|
|
+ // If this is a 'not' or 'neg' instruction, do not count it for rank. This
|
|
|
// assures us that X and ~X will have the same rank.
|
|
|
- if (!BinaryOperator::isNot(I) && !BinaryOperator::isNeg(I) &&
|
|
|
+ if (!match(I, m_Not(m_Value())) && !match(I, m_Neg(m_Value())) &&
|
|
|
!BinaryOperator::isFNeg(I))
|
|
|
++Rank;
|
|
|
|
|
@@ -574,7 +574,7 @@ static bool LinearizeExprTree(BinaryOperator *I,
|
|
|
// If this is a multiply expression, turn any internal negations into
|
|
|
// multiplies by -1 so they can be reassociated.
|
|
|
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Op))
|
|
|
- if ((Opcode == Instruction::Mul && BinaryOperator::isNeg(BO)) ||
|
|
|
+ if ((Opcode == Instruction::Mul && match(BO, m_Neg(m_Value()))) ||
|
|
|
(Opcode == Instruction::FMul && BinaryOperator::isFNeg(BO))) {
|
|
|
LLVM_DEBUG(dbgs()
|
|
|
<< "MORPH LEAF: " << *Op << " (" << Weight << ") TO ");
|
|
@@ -855,7 +855,7 @@ static Value *NegateValue(Value *V, Instruction *BI,
|
|
|
// Okay, we need to materialize a negated version of V with an instruction.
|
|
|
// Scan the use lists of V to see if we have one already.
|
|
|
for (User *U : V->users()) {
|
|
|
- if (!BinaryOperator::isNeg(U) && !BinaryOperator::isFNeg(U))
|
|
|
+ if (!match(U, m_Neg(m_Value())) && !BinaryOperator::isFNeg(U))
|
|
|
continue;
|
|
|
|
|
|
// We found one! Now we have to make sure that the definition dominates
|
|
@@ -900,7 +900,7 @@ static Value *NegateValue(Value *V, Instruction *BI,
|
|
|
/// Return true if we should break up this subtract of X-Y into (X + -Y).
|
|
|
static bool ShouldBreakUpSubtract(Instruction *Sub) {
|
|
|
// If this is a negation, we can't split it up!
|
|
|
- if (BinaryOperator::isNeg(Sub) || BinaryOperator::isFNeg(Sub))
|
|
|
+ if (match(Sub, m_Neg(m_Value())) || BinaryOperator::isFNeg(Sub))
|
|
|
return false;
|
|
|
|
|
|
// Don't breakup X - undef.
|
|
@@ -1114,8 +1114,8 @@ static Value *OptimizeAndOrXor(unsigned Opcode,
|
|
|
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
|
|
|
// First, check for X and ~X in the operand list.
|
|
|
assert(i < Ops.size());
|
|
|
- if (BinaryOperator::isNot(Ops[i].Op)) { // Cannot occur for ^.
|
|
|
- Value *X = BinaryOperator::getNotArgument(Ops[i].Op);
|
|
|
+ Value *X;
|
|
|
+ if (match(Ops[i].Op, m_Not(m_Value(X)))) { // Cannot occur for ^.
|
|
|
unsigned FoundX = FindInOperandList(Ops, i, X);
|
|
|
if (FoundX != i) {
|
|
|
if (Opcode == Instruction::And) // ...&X&~X = 0
|
|
@@ -1461,15 +1461,13 @@ Value *ReassociatePass::OptimizeAdd(Instruction *I,
|
|
|
}
|
|
|
|
|
|
// Check for X and -X or X and ~X in the operand list.
|
|
|
- if (!BinaryOperator::isNeg(TheOp) && !BinaryOperator::isFNeg(TheOp) &&
|
|
|
- !BinaryOperator::isNot(TheOp))
|
|
|
+ Value *X;
|
|
|
+ if (!match(TheOp, m_Neg(m_Value(X))) && !match(TheOp, m_Not(m_Value(X))) &&
|
|
|
+ !BinaryOperator::isFNeg(TheOp))
|
|
|
continue;
|
|
|
|
|
|
- Value *X = nullptr;
|
|
|
- if (BinaryOperator::isNeg(TheOp) || BinaryOperator::isFNeg(TheOp))
|
|
|
- X = BinaryOperator::getNegArgument(TheOp);
|
|
|
- else if (BinaryOperator::isNot(TheOp))
|
|
|
- X = BinaryOperator::getNotArgument(TheOp);
|
|
|
+ if (BinaryOperator::isFNeg(TheOp))
|
|
|
+ X = BinaryOperator::getFNegArgument(TheOp);
|
|
|
|
|
|
unsigned FoundX = FindInOperandList(Ops, i, X);
|
|
|
if (FoundX == i)
|
|
@@ -1477,11 +1475,11 @@ Value *ReassociatePass::OptimizeAdd(Instruction *I,
|
|
|
|
|
|
// Remove X and -X from the operand list.
|
|
|
if (Ops.size() == 2 &&
|
|
|
- (BinaryOperator::isNeg(TheOp) || BinaryOperator::isFNeg(TheOp)))
|
|
|
+ (match(TheOp, m_Neg(m_Value())) || BinaryOperator::isFNeg(TheOp)))
|
|
|
return Constant::getNullValue(X->getType());
|
|
|
|
|
|
// Remove X and ~X from the operand list.
|
|
|
- if (Ops.size() == 2 && BinaryOperator::isNot(TheOp))
|
|
|
+ if (Ops.size() == 2 && match(TheOp, m_Not(m_Value())))
|
|
|
return Constant::getAllOnesValue(X->getType());
|
|
|
|
|
|
Ops.erase(Ops.begin()+i);
|
|
@@ -1495,7 +1493,7 @@ Value *ReassociatePass::OptimizeAdd(Instruction *I,
|
|
|
e -= 2; // Removed two elements.
|
|
|
|
|
|
// if X and ~X we append -1 to the operand list.
|
|
|
- if (BinaryOperator::isNot(TheOp)) {
|
|
|
+ if (match(TheOp, m_Not(m_Value()))) {
|
|
|
Value *V = Constant::getAllOnesValue(X->getType());
|
|
|
Ops.insert(Ops.end(), ValueEntry(getRank(V), V));
|
|
|
e += 1;
|
|
@@ -2059,7 +2057,7 @@ void ReassociatePass::OptimizeInst(Instruction *I) {
|
|
|
RedoInsts.insert(I);
|
|
|
MadeChange = true;
|
|
|
I = NI;
|
|
|
- } else if (BinaryOperator::isNeg(I)) {
|
|
|
+ } else if (match(I, m_Neg(m_Value()))) {
|
|
|
// Otherwise, this is a negation. See if the operand is a multiply tree
|
|
|
// and if this is not an inner node of a multiply tree.
|
|
|
if (isReassociableOp(I->getOperand(1), Instruction::Mul) &&
|