diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2018-03-02 18:36:08 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2018-03-02 18:36:08 +0000 |
| commit | 46b083ef4a3424b1e0e6b488d390ce759759f8e9 (patch) | |
| tree | 52e928e9d56f6af78273d4466ada7bbae57485ec /llvm/lib/IR | |
| parent | f608812bdef3f4c09857beb2ca20269387fe61c7 (diff) | |
| download | bcm5719-llvm-46b083ef4a3424b1e0e6b488d390ce759759f8e9.tar.gz bcm5719-llvm-46b083ef4a3424b1e0e6b488d390ce759759f8e9.zip | |
[PatternMatch, InstSimplify] fix m_NaN to work with vector constants and use it
This is NFC for the moment (and independent of any potential NaN semantic
controversy). Besides making the code in InstSimplify easier to read, the
motivation is to eventually allow undef elements in vector constants to
match too. A proposal to add the base logic for that is in D43792.
llvm-svn: 326600
Diffstat (limited to 'llvm/lib/IR')
| -rw-r--r-- | llvm/lib/IR/Constants.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 8b375bcff76..ad3dc174fe3 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -241,6 +241,19 @@ bool Constant::hasExactInverseFP() const { return true; } +bool Constant::isNaN() const { + if (auto *CFP = dyn_cast<ConstantFP>(this)) + return CFP->isNaN(); + if (!getType()->isVectorTy()) + return false; + for (unsigned i = 0, e = getType()->getVectorNumElements(); i != e; ++i) { + auto *CFP = dyn_cast_or_null<ConstantFP>(this->getAggregateElement(i)); + if (!CFP || !CFP->isNaN()) + return false; + } + return true; +} + /// Constructor to create a '0' constant of arbitrary type. Constant *Constant::getNullValue(Type *Ty) { switch (Ty->getTypeID()) { |

