1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

Move pattern check outside of the if-then statement. This prevents us from fiddling with constants unless we have to.

llvm-svn: 60340
This commit is contained in:
Bill Wendling 2008-12-01 07:47:02 +00:00
parent 3b908483b7
commit 8e484e9556

View File

@ -2928,17 +2928,19 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
if (RHS->isAllOnesValue())
return BinaryOperator::CreateNeg(Op0);
ConstantInt *RHSNeg = cast<ConstantInt>(ConstantExpr::getNeg(RHS));
APInt RHSNegAPI(RHSNeg->getValue());
APInt NegOne = -APInt(RHSNeg->getBitWidth(), 1, true);
APInt TwoToExp(RHSNeg->getBitWidth(), 1 << (RHSNeg->getBitWidth() - 1));
// -X/C -> X/-C, if and only if negation doesn't overflow.
if ((RHS->getValue().isNegative() && RHSNegAPI.slt(TwoToExp - 1)) ||
(RHS->getValue().isNonNegative() && RHSNegAPI.sgt(TwoToExp * NegOne))) {
if (Value *LHSNeg = dyn_castNegVal(Op0)) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(LHSNeg)) {
if (Value *LHSNeg = dyn_castNegVal(Op0)) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(LHSNeg)) {
ConstantInt *RHSNeg = cast<ConstantInt>(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))) {
ConstantInt *CINeg = cast<ConstantInt>(ConstantExpr::getNeg(CI));
APInt CINegAPI(CINeg->getValue());