diff options
author | Chris Lattner <sabre@nondot.org> | 2007-07-20 22:09:02 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-07-20 22:09:02 +0000 |
commit | 871181f98eae954e201a136361c2060b5b824b01 (patch) | |
tree | 5fad7bc2be699ab18d7a6897cd439298a1d06ee9 | |
parent | e0f462d0bcdb4083510b447ec5c0aecef6af8e4a (diff) | |
download | external_llvm-871181f98eae954e201a136361c2060b5b824b01.tar.gz external_llvm-871181f98eae954e201a136361c2060b5b824b01.tar.bz2 external_llvm-871181f98eae954e201a136361c2060b5b824b01.zip |
zext(undef) = 0 and sext(undef) = 0, not undef.
This hopefully fixes a miscompilation of TargetData.cpp when self hosting.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40125 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 53e5c69136..da4efcdaad 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -140,8 +140,13 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, const Type *DestTy) { const Type *SrcTy = V->getType(); - if (isa<UndefValue>(V)) + if (isa<UndefValue>(V)) { + // zext(undef) = 0, because the top bits will be zero. + // sext(undef) = 0, because the top bits will all be the same. + if (opc == Instruction::ZExt || opc == Instruction::SExt) + return Constant::getNullValue(DestTy); return UndefValue::get(DestTy); + } // If the cast operand is a constant expression, there's a few things we can // do to try to simplify it. |