Date: Fri, 30 Aug 2013 18:29:26 +0000 (UTC) From: Dimitry Andric <dim@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r255076 - head/contrib/llvm/lib/Transforms/InstCombine Message-ID: <201308301829.r7UITQwX021816@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dim Date: Fri Aug 30 18:29:25 2013 New Revision: 255076 URL: http://svnweb.freebsd.org/changeset/base/255076 Log: Pull in r189672 from upstream llvm trunk: InstCombine: Check for zero shift amounts before subtracting one causing integer overflow. PR17026. Also avoid undefined shifts and shift amounts larger than 64 bits (those are always undef because we can't represent integer types that large). This should fix assertion failures when building the emulators/xmame port. Reported by: bapt Modified: head/contrib/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp Modified: head/contrib/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp ============================================================================== --- head/contrib/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp Fri Aug 30 17:47:53 2013 (r255075) +++ head/contrib/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp Fri Aug 30 18:29:25 2013 (r255076) @@ -845,21 +845,26 @@ Value *InstCombiner::SimplifyDemandedUse Value *InstCombiner::SimplifyShrShlDemandedBits(Instruction *Shr, Instruction *Shl, APInt DemandedMask, APInt &KnownZero, APInt &KnownOne) { - unsigned ShlAmt = cast<ConstantInt>(Shl->getOperand(1))->getZExtValue(); - unsigned ShrAmt = cast<ConstantInt>(Shr->getOperand(1))->getZExtValue(); + const APInt &ShlOp1 = cast<ConstantInt>(Shl->getOperand(1))->getValue(); + const APInt &ShrOp1 = cast<ConstantInt>(Shr->getOperand(1))->getValue(); + if (!ShlOp1 || !ShrOp1) + return 0; // Noop. + + Value *VarX = Shr->getOperand(0); + Type *Ty = VarX->getType(); + unsigned BitWidth = Ty->getIntegerBitWidth(); + if (ShlOp1.uge(BitWidth) || ShrOp1.uge(BitWidth)) + return 0; // Undef. + + unsigned ShlAmt = ShlOp1.getZExtValue(); + unsigned ShrAmt = ShrOp1.getZExtValue(); KnownOne.clearAllBits(); KnownZero = APInt::getBitsSet(KnownZero.getBitWidth(), 0, ShlAmt-1); KnownZero &= DemandedMask; - if (ShlAmt == 0 || ShrAmt == 0) - return 0; - - Value *VarX = Shr->getOperand(0); - Type *Ty = VarX->getType(); - - APInt BitMask1(APInt::getAllOnesValue(Ty->getIntegerBitWidth())); - APInt BitMask2(APInt::getAllOnesValue(Ty->getIntegerBitWidth())); + APInt BitMask1(APInt::getAllOnesValue(BitWidth)); + APInt BitMask2(APInt::getAllOnesValue(BitWidth)); bool isLshr = (Shr->getOpcode() == Instruction::LShr); BitMask1 = isLshr ? (BitMask1.lshr(ShrAmt) << ShlAmt) :
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308301829.r7UITQwX021816>