From: Chris Lattner Date: Sun, 25 Mar 2007 05:47:04 +0000 (+0000) Subject: fold constantexprs more aggressively, fixing PR1265 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=2ef14d9f7c416105be650021c8010bcf47583065 fold constantexprs more aggressively, fixing PR1265 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35336 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index d7e51956e4d..46263060e57 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -519,10 +519,20 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, return Constant::getNullValue(CI->getType()); // X % 1 == 0 break; case Instruction::And: - if (const ConstantInt *CI = dyn_cast(C2)) + if (const ConstantInt *CI = dyn_cast(C2)) { + if (CI->isZero()) return const_cast(C2); // X & 0 == 0 if (CI->isAllOnesValue()) return const_cast(C1); // X & -1 == X - if (C2->isNullValue()) return const_cast(C2); // X & 0 == 0 + + // (zext i32 to i64) & 4294967295 -> (zext i32 to i64) + if (CE1->getOpcode() == Instruction::ZExt) { + APInt PossiblySetBits + = cast(CE1->getOperand(0)->getType())->getMask(); + PossiblySetBits.zext(C1->getType()->getPrimitiveSizeInBits()); + if ((PossiblySetBits & CI->getValue()) == PossiblySetBits) + return const_cast(C1); + } + } if (CE1->isCast() && isa(CE1->getOperand(0))) { GlobalValue *CPR = cast(CE1->getOperand(0)); @@ -543,6 +553,11 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, case Instruction::Xor: if (C2->isNullValue()) return const_cast(C1); // X ^ 0 == X break; + case Instruction::AShr: + if (CE1->getOpcode() == Instruction::ZExt) // Top bits known zero. + return ConstantExpr::getLShr(const_cast(C1), + const_cast(C2)); + break; } } } else if (isa(C2)) {