Skip to content

Commit a162817

Browse files
committed
[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 llvm-svn: 375252
1 parent aa3806b commit a162817

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

llvm/include/llvm/IR/Operator.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,20 +379,25 @@ class FPMathOperator : public Operator {
379379
return false;
380380

381381
switch (Opcode) {
382+
case Instruction::FNeg:
383+
case Instruction::FAdd:
384+
case Instruction::FSub:
385+
case Instruction::FMul:
386+
case Instruction::FDiv:
387+
case Instruction::FRem:
382388
// FIXME: To clean up and correct the semantics of fast-math-flags, FCmp
383389
// should not be treated as a math op, but the other opcodes should.
384390
// This would make things consistent with Select/PHI (FP value type
385391
// determines whether they are math ops and, therefore, capable of
386392
// having fast-math-flags).
387393
case Instruction::FCmp:
388394
return true;
389-
// non math FP Operators (no FMF)
390-
case Instruction::ExtractElement:
391-
case Instruction::ShuffleVector:
392-
case Instruction::InsertElement:
393-
return false;
394-
default:
395+
case Instruction::PHI:
396+
case Instruction::Select:
397+
case Instruction::Call:
395398
return V->getType()->isFPOrFPVectorTy();
399+
default:
400+
return false;
396401
}
397402
}
398403
};

llvm/unittests/IR/IRBuilderTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ TEST_F(IRBuilderTest, UnaryOperators) {
376376
ASSERT_FALSE(isa<BinaryOperator>(U));
377377

378378
// Test CreateFNegFMF(X)
379-
Instruction *I = cast<Instruction>(V);
379+
Instruction *I = cast<Instruction>(U);
380380
I->setHasNoSignedZeros(true);
381381
I->setHasNoNaNs(true);
382382
Value *VFMF = Builder.CreateFNegFMF(V, I);

0 commit comments

Comments
 (0)