diff options
author | Chris Lattner <sabre@nondot.org> | 2006-12-01 19:22:41 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-12-01 19:22:41 +0000 |
commit | 710ebaf377a32d3daaa6ec5baca25d300cf30917 (patch) | |
tree | 7bf5d1b61e3d44f3bee8044f8b36eccdf9facaf0 /llvm/lib/VMCore/ConstantFolding.cpp | |
parent | f16661c3c6d5f04935b193e6eb068493566cea09 (diff) | |
download | bcm5719-llvm-710ebaf377a32d3daaa6ec5baca25d300cf30917.tar.gz bcm5719-llvm-710ebaf377a32d3daaa6ec5baca25d300cf30917.zip |
this logic is broken for trunc to bool, replace the folding logic for trunc
completely, as it is trivial. We should probably do this for the rest of the
cast operations. This fixes ConstProp/2006-12-01-TruncBoolBug.ll.
llvm-svn: 32081
Diffstat (limited to 'llvm/lib/VMCore/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/VMCore/ConstantFolding.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/llvm/lib/VMCore/ConstantFolding.cpp b/llvm/lib/VMCore/ConstantFolding.cpp index 79f0f577420..48d84e5ac54 100644 --- a/llvm/lib/VMCore/ConstantFolding.cpp +++ b/llvm/lib/VMCore/ConstantFolding.cpp @@ -860,10 +860,10 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, // We actually have to do a cast now, but first, we might need to fix up // the value of the operand. switch (opc) { + case Instruction::PtrToInt: case Instruction::FPTrunc: - case Instruction::Trunc: case Instruction::FPExt: - break; // floating point input & output, no fixup needed + break; case Instruction::FPToUI: { ConstRules &Rules = ConstRules::get(V, V); V = Rules.castToULong(V); // make sure we get an unsigned value first @@ -891,9 +891,12 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, V = ConstantInt::get(SrcTy->getSignedVersion(), cast<ConstantIntegral>(V)->getSExtValue()); break; - - case Instruction::PtrToInt: - break; + case Instruction::Trunc: + // We just handle trunc directly here. The code below doesn't work for + // trunc to bool. + if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) + return ConstantIntegral::get(DestTy, CI->getZExtValue()); + return 0; case Instruction::BitCast: // Check to see if we are casting a pointer to an aggregate to a pointer to // the first element. If so, return the appropriate GEP instruction. |