[llvm] r375252 - [IR] Reimplement FPMathOperator::classof as a whitelist.

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 09:16:36 PDT 2019


Author: foad
Date: Fri Oct 18 09:16:36 2019
New Revision: 375252

URL: http://llvm.org/viewvc/llvm-project?rev=375252&view=rev
Log:
[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

Modified:
    llvm/trunk/include/llvm/IR/Operator.h
    llvm/trunk/unittests/IR/IRBuilderTest.cpp

Modified: llvm/trunk/include/llvm/IR/Operator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Operator.h?rev=375252&r1=375251&r2=375252&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Operator.h (original)
+++ llvm/trunk/include/llvm/IR/Operator.h Fri Oct 18 09:16:36 2019
@@ -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;
     }
   }
 };

Modified: llvm/trunk/unittests/IR/IRBuilderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/IRBuilderTest.cpp?rev=375252&r1=375251&r2=375252&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/IRBuilderTest.cpp (original)
+++ llvm/trunk/unittests/IR/IRBuilderTest.cpp Fri Oct 18 09:16:36 2019
@@ -376,7 +376,7 @@ TEST_F(IRBuilderTest, UnaryOperators) {
   ASSERT_FALSE(isa<BinaryOperator>(U));
 
   // Test CreateFNegFMF(X)
-  Instruction *I = cast<Instruction>(V);
+  Instruction *I = cast<Instruction>(U);
   I->setHasNoSignedZeros(true);
   I->setHasNoNaNs(true);
   Value *VFMF = Builder.CreateFNegFMF(V, I);




More information about the llvm-commits mailing list