From: Chris Lattner Date: Fri, 20 Jul 2007 22:09:02 +0000 (+0000) Subject: zext(undef) = 0 and sext(undef) = 0, not undef. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d2f09965e6ba462c4728ff4d5c79b0d0d20ec47f;p=oota-llvm.git 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 --- diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 53e5c691361..da4efcdaade 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(V)) + if (isa(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.