diff options
author | Hal Finkel <hfinkel@anl.gov> | 2015-03-28 16:44:57 +0000 |
---|---|---|
committer | Hal Finkel <hfinkel@anl.gov> | 2015-03-28 16:44:57 +0000 |
commit | cd5553ed3912f4878ab0bbfffbf6f1d113d1521e (patch) | |
tree | 0e4e5e7647922974e7b37b59ae3e8e7bd05a8318 /llvm/lib/IR/ConstantFold.cpp | |
parent | 715007216cdfc498b7e37213489349956efcc15c (diff) | |
download | llvm-cd5553ed3912f4878ab0bbfffbf6f1d113d1521e.zip llvm-cd5553ed3912f4878ab0bbfffbf6f1d113d1521e.tar.gz llvm-cd5553ed3912f4878ab0bbfffbf6f1d113d1521e.tar.bz2 |
[ConstantFold] Don't fold ppc_fp128 <-> int bitcasts
PPC_FP128 is really the sum of two consecutive doubles, where the first double
is always stored first in memory, regardless of the target endianness. The
memory layout of i128, however, depends on the target endianness, and so we
can't fold this without target endianness information. As a result, we must not
do this folding in lib/IR/ConstantFold.cpp (it could be done instead in
Analysis/ConstantFolding.cpp, but that's not done now).
Fixes PR23026.
llvm-svn: 233481
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index d97d2c4..500696e 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -169,7 +169,8 @@ static Constant *FoldBitCast(Constant *V, Type *DestTy) { // be the same. Consequently, we just fold to V. return V; - if (DestTy->isFloatingPointTy()) + // See note below regarding the PPC_FP128 restriction. + if (DestTy->isFloatingPointTy() && !DestTy->isPPC_FP128Ty()) return ConstantFP::get(DestTy->getContext(), APFloat(DestTy->getFltSemantics(), CI->getValue())); @@ -179,9 +180,19 @@ static Constant *FoldBitCast(Constant *V, Type *DestTy) { } // Handle ConstantFP input: FP -> Integral. - if (ConstantFP *FP = dyn_cast<ConstantFP>(V)) + if (ConstantFP *FP = dyn_cast<ConstantFP>(V)) { + // PPC_FP128 is really the sum of two consecutive doubles, where the first + // double is always stored first in memory, regardless of the target + // endianness. The memory layout of i128, however, depends on the target + // endianness, and so we can't fold this without target endianness + // information. This should instead be handled by + // Analysis/ConstantFolding.cpp + if (FP->getType()->isPPC_FP128Ty()) + return nullptr; + return ConstantInt::get(FP->getContext(), FP->getValueAPF().bitcastToAPInt()); + } return nullptr; } |