aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2016-04-04 23:50:46 +0000
committerTeresa Johnson <tejohnson@google.com>2016-04-04 23:50:46 +0000
commitf4cf1c3eb4937b10ae36de561ab9f730b9da9f05 (patch)
tree829f38417c54701c733903655932da7f23dfa6a2 /llvm/lib/IR/ConstantFold.cpp
parente3f558ba141941363f32f996ba6f2b7d7b4a2ffb (diff)
downloadllvm-f4cf1c3eb4937b10ae36de561ab9f730b9da9f05.zip
llvm-f4cf1c3eb4937b10ae36de561ab9f730b9da9f05.tar.gz
llvm-f4cf1c3eb4937b10ae36de561ab9f730b9da9f05.tar.bz2
Don't fold double constant to an integer if dest type not integral
Summary: I encountered this issue when constant folding during inlining tried to fold away a bitcast of a double to an x86_mmx, which is not an integral type. The test case exposes the same issue with a smaller code snippet during early CSE. Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D18528 llvm-svn: 265367
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 62a7f2e..824555c 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -191,6 +191,10 @@ static Constant *FoldBitCast(Constant *V, Type *DestTy) {
if (FP->getType()->isPPC_FP128Ty())
return nullptr;
+ // Make sure dest type is compatible with the folded integer constant.
+ if (!DestTy->isIntegerTy())
+ return nullptr;
+
return ConstantInt::get(FP->getContext(),
FP->getValueAPF().bitcastToAPInt());
}