llvm.org GIT mirror llvm / 5cc88b4
Update PatternMatcher for FNeg Match both FNeg(X) and FSub(+-0.0, X) in FNeg_match Differential Revision: https://reviews.llvm.org/D61520 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359936 91177308-0d34-0410-b5e6-96231b3b80d8 Cameron McInally 1 year, 5 months ago
2 changed file(s) with 48 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
666666 FNeg_match(const Op_t &Op) : X(Op) {}
667667 template bool match(OpTy *V) {
668668 auto *FPMO = dyn_cast(V);
669 if (!FPMO || FPMO->getOpcode() != Instruction::FSub)
670 return false;
671 if (FPMO->hasNoSignedZeros()) {
672 // With 'nsz', any zero goes.
673 if (!cstfp_pred_ty().match(FPMO->getOperand(0)))
674 return false;
675 } else {
676 // Without 'nsz', we need fsub -0.0, X exactly.
677 if (!cstfp_pred_ty().match(FPMO->getOperand(0)))
678 return false;
669 if (!FPMO) return false;
670
671 if (FPMO->getOpcode() == Instruction::FNeg)
672 return X.match(FPMO->getOperand(0));
673
674 if (FPMO->getOpcode() == Instruction::FSub) {
675 if (FPMO->hasNoSignedZeros()) {
676 // With 'nsz', any zero goes.
677 if (!cstfp_pred_ty().match(FPMO->getOperand(0)))
678 return false;
679 } else {
680 // Without 'nsz', we need fsub -0.0, X exactly.
681 if (!cstfp_pred_ty().match(FPMO->getOperand(0)))
682 return false;
683 }
684
685 return X.match(FPMO->getOperand(1));
679686 }
680 return X.match(FPMO->getOperand(1));
687
688 return false;
681689 }
682690 };
683691
588588 EXPECT_TRUE(match(VectorZeroUndef, m_AnyZeroFP()));
589589 }
590590
591 TEST_F(PatternMatchTest, FloatingPointFNeg) {
592 Type *FltTy = IRB.getFloatTy();
593 Value *One = ConstantFP::get(FltTy, 1.0);
594 Value *Z = ConstantFP::get(FltTy, 0.0);
595 Value *NZ = ConstantFP::get(FltTy, -0.0);
596 Value *V = IRB.CreateFNeg(One);
597 Value *V1 = IRB.CreateFSub(NZ, One);
598 Value *V2 = IRB.CreateFSub(Z, One);
599 Value *V3 = IRB.CreateFAdd(NZ, One);
600 Value *Match;
601
602 // Test FNeg(1.0)
603 EXPECT_TRUE(match(V, m_FNeg(m_Value(Match))));
604 EXPECT_EQ(One, Match);
605
606 // Test FSub(-0.0, 1.0)
607 EXPECT_TRUE(match(V1, m_FNeg(m_Value(Match))));
608 EXPECT_EQ(One, Match);
609
610 // Test FSub(0.0, 1.0)
611 EXPECT_FALSE(match(V2, m_FNeg(m_Value(Match))));
612 cast(V2)->setHasNoSignedZeros(true);
613 EXPECT_TRUE(match(V2, m_FNeg(m_Value(Match))));
614 EXPECT_EQ(One, Match);
615
616 // Test FAdd(-0.0, 1.0)
617 EXPECT_FALSE(match(V3, m_FNeg(m_Value(Match))));
618 }
619
591620 template struct MutableConstTest : PatternMatchTest { };
592621
593622 typedef ::testing::Types,