@@ -972,37 +972,36 @@ static Instruction *foldUDivShl(Value *Op0, Value *Op1, const BinaryOperator &I,
972
972
// instruction, seeing through select instructions, to determine if we can
973
973
// replace the udiv with something simpler. If we find that an operand is not
974
974
// able to simplify the udiv, we abort the entire transformation.
975
- static size_t visitUDivOperand (Value *Op0, Value *Op1 , const BinaryOperator &I,
975
+ static size_t visitUDivOperand (Value *Op , const BinaryOperator &I,
976
976
SmallVectorImpl<UDivFoldAction> &Actions,
977
977
unsigned Depth = 0 ) {
978
978
// FIXME: assert that Op1 isn't/doesn't contain undef.
979
979
980
980
// Check to see if this is an unsigned division with an exact power of 2,
981
981
// if so, convert to a right shift.
982
- if (match (Op1 , m_Power2 ())) {
983
- Actions.push_back (UDivFoldAction (foldUDivPow2Cst, Op1 ));
982
+ if (match (Op , m_Power2 ())) {
983
+ Actions.push_back (UDivFoldAction (foldUDivPow2Cst, Op ));
984
984
return Actions.size ();
985
985
}
986
986
987
987
// X udiv (C1 << N), where C1 is "1<<C2" --> X >> (N+C2)
988
- if (match (Op1 , m_Shl (m_Power2 (), m_Value ())) ||
989
- match (Op1 , m_ZExt (m_Shl (m_Power2 (), m_Value ())))) {
990
- Actions.push_back (UDivFoldAction (foldUDivShl, Op1 ));
988
+ if (match (Op , m_Shl (m_Power2 (), m_Value ())) ||
989
+ match (Op , m_ZExt (m_Shl (m_Power2 (), m_Value ())))) {
990
+ Actions.push_back (UDivFoldAction (foldUDivShl, Op ));
991
991
return Actions.size ();
992
992
}
993
993
994
994
// The remaining tests are all recursive, so bail out if we hit the limit.
995
995
if (Depth++ == MaxDepth)
996
996
return 0 ;
997
997
998
- if (SelectInst *SI = dyn_cast<SelectInst>(Op1 ))
998
+ if (SelectInst *SI = dyn_cast<SelectInst>(Op ))
999
999
// FIXME: missed optimization: if one of the hands of select is/contains
1000
1000
// undef, just directly pick the other one.
1001
1001
// FIXME: can both hands contain undef?
1002
- if (size_t LHSIdx =
1003
- visitUDivOperand (Op0, SI->getOperand (1 ), I, Actions, Depth))
1004
- if (visitUDivOperand (Op0, SI->getOperand (2 ), I, Actions, Depth)) {
1005
- Actions.push_back (UDivFoldAction (nullptr , Op1, LHSIdx - 1 ));
1002
+ if (size_t LHSIdx = visitUDivOperand (SI->getOperand (1 ), I, Actions, Depth))
1003
+ if (visitUDivOperand (SI->getOperand (2 ), I, Actions, Depth)) {
1004
+ Actions.push_back (UDivFoldAction (nullptr , Op, LHSIdx - 1 ));
1006
1005
return Actions.size ();
1007
1006
}
1008
1007
@@ -1108,7 +1107,7 @@ Instruction *InstCombinerImpl::visitUDiv(BinaryOperator &I) {
1108
1107
1109
1108
// (LHS udiv (select (select (...)))) -> (LHS >> (select (select (...))))
1110
1109
SmallVector<UDivFoldAction, 6 > UDivActions;
1111
- if (visitUDivOperand (Op0, Op1, I, UDivActions))
1110
+ if (visitUDivOperand (Op1, I, UDivActions))
1112
1111
for (unsigned i = 0 , e = UDivActions.size (); i != e; ++i) {
1113
1112
FoldUDivOperandCb Action = UDivActions[i].FoldAction ;
1114
1113
Value *ActionOp1 = UDivActions[i].OperandToFold ;
0 commit comments