llvm.org GIT mirror llvm / 31fda75
[FPEnv] Convert more BinaryOperator::isFNeg(...) to m_FNeg(...) This work is to avoid regressions when we seperate FNeg from the FSub IR instruction. Differential Revision: https://reviews.llvm.org/D53205 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345146 91177308-0d34-0410-b5e6-96231b3b80d8 Cameron McInally 10 months ago
3 changed file(s) with 34 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
658658 return BinaryOp_match(L, R);
659659 }
660660
661 template struct FNeg_match {
662 Op_t X;
663
664 FNeg_match(const Op_t &Op) : X(Op) {}
665 template bool match(OpTy *V) {
666 auto *FPMO = dyn_cast(V);
667 if (!FPMO || FPMO->getOpcode() != Instruction::FSub)
668 return false;
669 if (FPMO->hasNoSignedZeros()) {
670 // With 'nsz', any zero goes.
671 if (!cstfp_pred_ty().match(FPMO->getOperand(0)))
672 return false;
673 } else {
674 // Without 'nsz', we need fsub -0.0, X exactly.
675 if (!cstfp_pred_ty().match(FPMO->getOperand(0)))
676 return false;
677 }
678 return X.match(FPMO->getOperand(1));
679 }
680 };
681
661682 /// Match 'fneg X' as 'fsub -0.0, X'.
662 template
663 inline BinaryOp_match, RHS, Instruction::FSub>
664 m_FNeg(const RHS &X) {
665 return m_FSub(m_NegZeroFP(), X);
683 template
684 inline FNeg_match
685 m_FNeg(const OpTy &X) {
686 return FNeg_match(X);
666687 }
667688
668689 /// Match 'fneg X' as 'fsub +-0.0, X'.
207207 // If this is a 'not' or 'neg' instruction, do not count it for rank. This
208208 // assures us that X and ~X will have the same rank.
209209 if (!match(I, m_Not(m_Value())) && !match(I, m_Neg(m_Value())) &&
210 !BinaryOperator::isFNeg(I))
210 !match(I, m_FNeg(m_Value())))
211211 ++Rank;
212212
213213 LLVM_DEBUG(dbgs() << "Calculated Rank[" << V->getName() << "] = " << Rank
574574 // multiplies by -1 so they can be reassociated.
575575 if (BinaryOperator *BO = dyn_cast(Op))
576576 if ((Opcode == Instruction::Mul && match(BO, m_Neg(m_Value()))) ||
577 (Opcode == Instruction::FMul && BinaryOperator::isFNeg(BO))) {
577 (Opcode == Instruction::FMul && match(BO, m_FNeg(m_Value())))) {
578578 LLVM_DEBUG(dbgs()
579579 << "MORPH LEAF: " << *Op << " (" << Weight << ") TO ");
580580 BO = LowerNegateToMultiply(BO);
854854 // Okay, we need to materialize a negated version of V with an instruction.
855855 // Scan the use lists of V to see if we have one already.
856856 for (User *U : V->users()) {
857 if (!match(U, m_Neg(m_Value())) && !BinaryOperator::isFNeg(U))
857 if (!match(U, m_Neg(m_Value())) && !match(U, m_FNeg(m_Value())))
858858 continue;
859859
860860 // We found one! Now we have to make sure that the definition dominates
899899 /// Return true if we should break up this subtract of X-Y into (X + -Y).
900900 static bool ShouldBreakUpSubtract(Instruction *Sub) {
901901 // If this is a negation, we can't split it up!
902 if (match(Sub, m_Neg(m_Value())) || BinaryOperator::isFNeg(Sub))
902 if (match(Sub, m_Neg(m_Value())) || match(Sub, m_FNeg(m_Value())))
903903 return false;
904904
905905 // Don't breakup X - undef.
14621462 // Check for X and -X or X and ~X in the operand list.
14631463 Value *X;
14641464 if (!match(TheOp, m_Neg(m_Value(X))) && !match(TheOp, m_Not(m_Value(X))) &&
1465 !BinaryOperator::isFNeg(TheOp))
1465 !match(TheOp, m_FNeg(m_Value(X))))
14661466 continue;
1467
1468 if (BinaryOperator::isFNeg(TheOp))
1469 X = BinaryOperator::getFNegArgument(TheOp);
14701467
14711468 unsigned FoundX = FindInOperandList(Ops, i, X);
14721469 if (FoundX == i)
14741471
14751472 // Remove X and -X from the operand list.
14761473 if (Ops.size() == 2 &&
1477 (match(TheOp, m_Neg(m_Value())) || BinaryOperator::isFNeg(TheOp)))
1474 (match(TheOp, m_Neg(m_Value())) || match(TheOp, m_FNeg(m_Value()))))
14781475 return Constant::getNullValue(X->getType());
14791476
14801477 // Remove X and ~X from the operand list.
20802077 RedoInsts.insert(I);
20812078 MadeChange = true;
20822079 I = NI;
2083 } else if (BinaryOperator::isFNeg(I)) {
2080 } else if (match(I, m_FNeg(m_Value()))) {
20842081 // Otherwise, this is a negation. See if the operand is a multiply tree
20852082 // and if this is not an inner node of a multiply tree.
20862083 if (isReassociableOp(I->getOperand(1), Instruction::FMul) &&
33 define void @test1() {
44 ; CHECK-LABEL: @test1(
55 ; CHECK-NEXT: [[T1:%.*]] = tail call <4 x float> @blam()
6 ; CHECK-NEXT: [[T1_NEG:%.*]] = fsub fast <4 x float> , [[T1]]
7 ; CHECK-NEXT: [[T24:%.*]] = fadd fast <4 x float> [[T1_NEG]], undef
6 ; CHECK-NEXT: [[T23:%.*]] = fsub fast <4 x float> undef, [[T1]]
7 ; CHECK-NEXT: [[T24:%.*]] = fadd fast <4 x float> [[T23]], undef
88 ; CHECK-NEXT: tail call void @wombat(<4 x float> [[T24]])
99 ; CHECK-NEXT: ret void
1010 ;