diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 9c6ff8acc57ae10f95cd6df2065b660182d69752..e4ddecf756314faa0614d020575aec9469dbe5f8 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2934,20 +2934,9 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) { if (Value *LHSNeg = dyn_castNegVal(Op0)) { if (ConstantInt *CI = dyn_cast(LHSNeg)) { ConstantInt *RHSNeg = cast(ConstantExpr::getNeg(RHS)); - APInt RHSNegAPI(RHSNeg->getValue()); - - APInt NegOne = -APInt(RHSNeg->getBitWidth(), 1, true); - APInt TwoToExp(RHSNeg->getBitWidth(), 1 << (RHSNeg->getBitWidth() - 1)); - - if ((RHS->getValue().isNegative() && - RHSNegAPI.slt(TwoToExp - 1)) || - (RHS->getValue().isNonNegative() && - RHSNegAPI.sgt(TwoToExp * NegOne))) { + if (RHS != RHSNeg) { ConstantInt *CINeg = cast(ConstantExpr::getNeg(CI)); - APInt CINegAPI(CINeg->getValue()); - - if ((CI->getValue().isNegative() && CINegAPI.slt(TwoToExp - 1)) || - (CI->getValue().isNonNegative() && CINegAPI.sgt(TwoToExp*NegOne))) + if (CI != CINeg) return BinaryOperator::CreateSDiv(LHSNeg, ConstantExpr::getNeg(RHS)); }