forked from OSchip/llvm-project
Fixed version of optimized integer divide is now fixed. Calculate the
quotient, not the remainder. Also, make sure to remove the old div operand from the ExprMap and let SelectExpr insert the new one. llvm-svn: 21111
This commit is contained in:
parent
c0e9adf3cc
commit
39ef2f1d43
|
@ -551,7 +551,7 @@ static unsigned getImmediateForOpcode(SDOperand N, unsigned Opcode,
|
||||||
if (v <= -2 || v >= 2) { return 4; }
|
if (v <= -2 || v >= 2) { return 4; }
|
||||||
break;
|
break;
|
||||||
case ISD::UDIV:
|
case ISD::UDIV:
|
||||||
if (v != 0) { return 4; }
|
if (v > 1) { return 4; }
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -711,10 +711,7 @@ SDOperand ISel::BuildSDIVSequence(SDOperand N) {
|
||||||
// Extract the sign bit and add it to the quotient
|
// Extract the sign bit and add it to the quotient
|
||||||
SDOperand T =
|
SDOperand T =
|
||||||
ISelDAG->getNode(ISD::SRL, MVT::i32, Q, ISelDAG->getConstant(31, MVT::i32));
|
ISelDAG->getNode(ISD::SRL, MVT::i32, Q, ISelDAG->getConstant(31, MVT::i32));
|
||||||
Q = ISelDAG->getNode(ISD::ADD, MVT::i32, Q, T);
|
return ISelDAG->getNode(ISD::ADD, MVT::i32, Q, T);
|
||||||
// Compute the remainder
|
|
||||||
T = ISelDAG->getNode(ISD::MUL, MVT::i32, Q, N.getOperand(1));
|
|
||||||
return ISelDAG->getNode(ISD::SUB, MVT::i32, N.getOperand(0), T);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// BuildUDIVSequence - Given an ISD::UDIV node expressing a divide by constant,
|
/// BuildUDIVSequence - Given an ISD::UDIV node expressing a divide by constant,
|
||||||
|
@ -739,9 +736,7 @@ SDOperand ISel::BuildUDIVSequence(SDOperand N) {
|
||||||
Q = ISelDAG->getNode(ISD::SRL, MVT::i32, NPQ,
|
Q = ISelDAG->getNode(ISD::SRL, MVT::i32, NPQ,
|
||||||
ISelDAG->getConstant(magics.s-1, MVT::i32));
|
ISelDAG->getConstant(magics.s-1, MVT::i32));
|
||||||
}
|
}
|
||||||
// Compute the remainder
|
return Q;
|
||||||
SDOperand T = ISelDAG->getNode(ISD::MUL, MVT::i32, Q, N.getOperand(1));
|
|
||||||
return ISelDAG->getNode(ISD::SUB, MVT::i32, N.getOperand(0), T);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getGlobalBaseReg - Output the instructions required to put the
|
/// getGlobalBaseReg - Output the instructions required to put the
|
||||||
|
@ -1601,11 +1596,12 @@ unsigned ISel::SelectExpr(SDOperand N) {
|
||||||
return Result;
|
return Result;
|
||||||
// If this is a divide by constant, we can emit code using some magic
|
// If this is a divide by constant, we can emit code using some magic
|
||||||
// constants to implement it as a multiply instead.
|
// constants to implement it as a multiply instead.
|
||||||
//case 4:
|
case 4:
|
||||||
// if (opcode == ISD::SDIV)
|
ExprMap.erase(N);
|
||||||
// return SelectExpr(BuildSDIVSequence(N));
|
if (opcode == ISD::SDIV)
|
||||||
// else
|
return SelectExpr(BuildSDIVSequence(N));
|
||||||
// return SelectExpr(BuildUDIVSequence(N));
|
else
|
||||||
|
return SelectExpr(BuildUDIVSequence(N));
|
||||||
}
|
}
|
||||||
Tmp1 = SelectExpr(N.getOperand(0));
|
Tmp1 = SelectExpr(N.getOperand(0));
|
||||||
Tmp2 = SelectExpr(N.getOperand(1));
|
Tmp2 = SelectExpr(N.getOperand(1));
|
||||||
|
|
Loading…
Reference in New Issue