Index: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp +++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp @@ -205,9 +205,9 @@ 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 @@ // If this is a multiply expression, turn any internal negations into // multiplies by -1 so they can be reassociated. if (BinaryOperator *BO = dyn_cast(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 @@ // 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 @@ /// 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 @@ 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 @@ } // 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 @@ // 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 @@ 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 @@ 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) && Index: llvm/trunk/test/Transforms/Reassociate/inverses.ll =================================================================== --- llvm/trunk/test/Transforms/Reassociate/inverses.ll +++ llvm/trunk/test/Transforms/Reassociate/inverses.ll @@ -14,10 +14,7 @@ define <2 x i32> @not_op_vec_undef(<2 x i32> %a, <2 x i32> %b) { ; CHECK-LABEL: @not_op_vec_undef( -; CHECK-NEXT: [[T2:%.*]] = and <2 x i32> [[B:%.*]], [[A:%.*]] -; CHECK-NEXT: [[T4:%.*]] = xor <2 x i32> [[A]], -; CHECK-NEXT: [[T5:%.*]] = and <2 x i32> [[T2]], [[T4]] -; CHECK-NEXT: ret <2 x i32> [[T5]] +; CHECK-NEXT: ret <2 x i32> zeroinitializer ; %t2 = and <2 x i32> %b, %a %t4 = xor <2 x i32> %a, Index: llvm/trunk/test/Transforms/Reassociate/negation.ll =================================================================== --- llvm/trunk/test/Transforms/Reassociate/negation.ll +++ llvm/trunk/test/Transforms/Reassociate/negation.ll @@ -33,9 +33,8 @@ define <2 x i32> @negate_vec_undefs(<2 x i32> %a, <2 x i32> %b, <2 x i32> %z) { ; CHECK-LABEL: @negate_vec_undefs( -; CHECK-NEXT: [[TMP1:%.*]] = mul <2 x i32> [[Z:%.*]], -; CHECK-NEXT: [[E:%.*]] = mul <2 x i32> [[TMP1]], [[A:%.*]] -; CHECK-NEXT: [[F:%.*]] = sub <2 x i32> , [[E]] +; CHECK-NEXT: [[E:%.*]] = mul <2 x i32> [[A:%.*]], +; CHECK-NEXT: [[F:%.*]] = mul <2 x i32> [[E]], [[Z:%.*]] ; CHECK-NEXT: ret <2 x i32> [[F]] ; %d = mul <2 x i32> %z,