diff options
Diffstat (limited to 'llvm/unittests')
| -rw-r--r-- | llvm/unittests/IR/PatternMatch.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp index e380fb90ad7..de47975e7c6 100644 --- a/llvm/unittests/IR/PatternMatch.cpp +++ b/llvm/unittests/IR/PatternMatch.cpp @@ -589,6 +589,35 @@ TEST_F(PatternMatchTest, VectorUndefFloat) { EXPECT_TRUE(match(VectorZeroUndef, m_AnyZeroFP())); } +TEST_F(PatternMatchTest, FloatingPointFNeg) { + Type *FltTy = IRB.getFloatTy(); + Value *One = ConstantFP::get(FltTy, 1.0); + Value *Z = ConstantFP::get(FltTy, 0.0); + Value *NZ = ConstantFP::get(FltTy, -0.0); + Value *V = IRB.CreateFNeg(One); + Value *V1 = IRB.CreateFSub(NZ, One); + Value *V2 = IRB.CreateFSub(Z, One); + Value *V3 = IRB.CreateFAdd(NZ, One); + Value *Match; + + // Test FNeg(1.0) + EXPECT_TRUE(match(V, m_FNeg(m_Value(Match)))); + EXPECT_EQ(One, Match); + + // Test FSub(-0.0, 1.0) + EXPECT_TRUE(match(V1, m_FNeg(m_Value(Match)))); + EXPECT_EQ(One, Match); + + // Test FSub(0.0, 1.0) + EXPECT_FALSE(match(V2, m_FNeg(m_Value(Match)))); + cast<Instruction>(V2)->setHasNoSignedZeros(true); + EXPECT_TRUE(match(V2, m_FNeg(m_Value(Match)))); + EXPECT_EQ(One, Match); + + // Test FAdd(-0.0, 1.0) + EXPECT_FALSE(match(V3, m_FNeg(m_Value(Match)))); +} + template <typename T> struct MutableConstTest : PatternMatchTest { }; typedef ::testing::Types<std::tuple<Value*, Instruction*>, |

