diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-04-08 18:21:11 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-04-08 18:21:11 +0000 |
commit | 87b9e1b727550f5186c1fe6145f3585c191babbc (patch) | |
tree | 38ae458660a08eb7a0c16cfd935367f2f36929a5 /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | 5155edc6583aee9264a94abf2c43dca936669d0c (diff) | |
download | bcm5719-llvm-87b9e1b727550f5186c1fe6145f3585c191babbc.tar.gz bcm5719-llvm-87b9e1b727550f5186c1fe6145f3585c191babbc.zip |
Propagate Undef in llvm.cos Intrinsic
Summary:
The llvm cos intrinsic currently does not propagate undef's. This change
transforms cos(undef) to null value or 0.
There are 2 test cases added as well.
Patch by Anna Thomas!
Reviewers: sanjoy
Subscribers: majnemer, llvm-commits
Differential Revision: http://reviews.llvm.org/D18863
llvm-svn: 265825
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 017d897def7..d87a0800262 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -1443,6 +1443,11 @@ Constant *ConstantFoldScalarCall(StringRef Name, unsigned IntrinsicID, Type *Ty, ArrayRef<Constant *> Operands, const TargetLibraryInfo *TLI) { if (Operands.size() == 1) { + if (isa<UndefValue>(Operands[0])) { + // cosine(arg) is between -1 and 1. cosine(invalid arg) is NaN + if (IntrinsicID == Intrinsic::cos) + return Constant::getNullValue(Ty); + } if (ConstantFP *Op = dyn_cast<ConstantFP>(Operands[0])) { if (IntrinsicID == Intrinsic::convert_to_fp16) { APFloat Val(Op->getValueAPF()); |