X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FInstructionSimplify.cpp;h=459fc92bce1a856a2d621b6aedc24c76c18c2d1a;hb=c5b413060c1775c134f934d38a766a0095284ed2;hp=6ac1ae8d5ed1783a66b035fcb5061f47f1c9b709;hpb=c84f22aac5390a6a60579f56e894bab7fec94382;p=oota-llvm.git diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index 6ac1ae8d5ed..459fc92bce1 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -676,6 +676,18 @@ static Value *SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, if (Op0 == Op1) return Constant::getNullValue(Op0->getType()); + // X - (0 - Y) -> X if the second sub is NUW. + // If Y != 0, 0 - Y is a poison value. + // If Y == 0, 0 - Y simplifies to 0. + if (BinaryOperator::isNeg(Op1)) { + if (const auto *BO = dyn_cast(Op1)) { + assert(BO->getOpcode() == Instruction::Sub && + "Expected a subtraction operator!"); + if (BO->hasNoUnsignedWrap()) + return Op0; + } + } + // (X + Y) - Z -> X + (Y - Z) or Y + (X - Z) if everything simplifies. // For example, (X + Y) - Y -> X; (Y + X) - Y -> X Value *X = nullptr, *Y = nullptr, *Z = Op1; @@ -1347,7 +1359,7 @@ static Value *SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact, return X; // Arithmetic shifting an all-sign-bit value is a no-op. - unsigned NumSignBits = ComputeNumSignBits(Op0); + unsigned NumSignBits = ComputeNumSignBits(Op0, Q.DL); if (NumSignBits == Op0->getType()->getScalarSizeInBits()) return Op0;