From 31bbace478f4a74dbd0d14162679e551cac0279e Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Fri, 18 Oct 2019 16:16:36 +0000 Subject: [PATCH] [IR] Reimplement FPMathOperator::classof as a whitelist. Summary: This makes it much easier to verify that the implementation matches the documentation. It uncovered a bug in the unit tests where we were accidentally setting fast math flags on a load instruction. Reviewers: spatel, wristow, arsenm, hfinkel, aemerson, efriedma, cameron.mcinally, mcberg2017, jmolloy Subscribers: wdng, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69176 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375252 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Operator.h | 17 +++++++++++------ unittests/IR/IRBuilderTest.cpp | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/llvm/IR/Operator.h b/include/llvm/IR/Operator.h index 608f33c3ed5..037f5aed03e 100644 --- a/include/llvm/IR/Operator.h +++ b/include/llvm/IR/Operator.h @@ -379,6 +379,12 @@ public: return false; switch (Opcode) { + case Instruction::FNeg: + case Instruction::FAdd: + case Instruction::FSub: + case Instruction::FMul: + case Instruction::FDiv: + case Instruction::FRem: // FIXME: To clean up and correct the semantics of fast-math-flags, FCmp // should not be treated as a math op, but the other opcodes should. // This would make things consistent with Select/PHI (FP value type @@ -386,13 +392,12 @@ public: // having fast-math-flags). case Instruction::FCmp: return true; - // non math FP Operators (no FMF) - case Instruction::ExtractElement: - case Instruction::ShuffleVector: - case Instruction::InsertElement: - return false; - default: + case Instruction::PHI: + case Instruction::Select: + case Instruction::Call: return V->getType()->isFPOrFPVectorTy(); + default: + return false; } } }; diff --git a/unittests/IR/IRBuilderTest.cpp b/unittests/IR/IRBuilderTest.cpp index 8fb5337a291..3c9dbc7f19d 100644 --- a/unittests/IR/IRBuilderTest.cpp +++ b/unittests/IR/IRBuilderTest.cpp @@ -376,7 +376,7 @@ TEST_F(IRBuilderTest, UnaryOperators) { ASSERT_FALSE(isa(U)); // Test CreateFNegFMF(X) - Instruction *I = cast(V); + Instruction *I = cast(U); I->setHasNoSignedZeros(true); I->setHasNoNaNs(true); Value *VFMF = Builder.CreateFNegFMF(V, I); -- 2.40.0