bool AllowEvenDivisorOptimization = true);
APInt Magic; ///< magic number
bool IsAdd; ///< add indicator
- unsigned ShiftAmount; ///< shift amount
+ unsigned PostShift; ///< post-shift amount
unsigned PreShift; ///< pre-shift amount
};
Magic = std::move(magics.Magic);
- if (!magics.IsAdd) {
- assert(magics.ShiftAmount < Divisor.getBitWidth() &&
- "We shouldn't generate an undefined shift!");
- PostShift = magics.ShiftAmount;
- PreShift = magics.PreShift;
- } else {
- assert(magics.PreShift == 0 && "Unexpected pre-shift");
- PostShift = magics.ShiftAmount - 1;
- SelNPQ = true;
- }
+ assert(magics.PreShift < Divisor.getBitWidth() &&
+ "We shouldn't generate an undefined shift!");
+ assert(magics.PostShift < Divisor.getBitWidth() &&
+ "We shouldn't generate an undefined shift!");
+ assert((!magics.IsAdd || magics.PreShift == 0) && "Unexpected pre-shift");
+ PreShift = magics.PreShift;
+ PostShift = magics.PostShift;
+ SelNPQ = magics.IsAdd;
}
PreShifts.push_back(
Magic = std::move(magics.Magic);
- if (!magics.IsAdd) {
- assert(magics.ShiftAmount < Divisor.getBitWidth() &&
- "We shouldn't generate an undefined shift!");
- PostShift = magics.ShiftAmount;
- PreShift = magics.PreShift;
- } else {
- assert(magics.PreShift == 0 && "Unexpected pre-shift");
- PostShift = magics.ShiftAmount - 1;
- SelNPQ = true;
- }
+ assert(magics.PreShift < Divisor.getBitWidth() &&
+ "We shouldn't generate an undefined shift!");
+ assert(magics.PostShift < Divisor.getBitWidth() &&
+ "We shouldn't generate an undefined shift!");
+ assert((!magics.IsAdd || magics.PreShift == 0) &&
+ "Unexpected pre-shift");
+ PreShift = magics.PreShift;
+ PostShift = magics.PostShift;
+ SelNPQ = magics.IsAdd;
}
PreShifts.push_back(DAG.getConstant(PreShift, dl, ShSVT));
Retval.Magic = std::move(Q2); // resulting magic number
++Retval.Magic;
- Retval.ShiftAmount = P - D.getBitWidth(); // resulting shift
+ Retval.PostShift = P - D.getBitWidth(); // resulting shift
+ // Reduce shift amount for IsAdd.
+ if (Retval.IsAdd) {
+ assert(Retval.PostShift > 0 && "Unexpected shift");
+ Retval.PostShift -= 1;
+ }
Retval.PreShift = 0;
return Retval;
}
}
}
- unsigned PreShift = 0;
- unsigned PostShift = 0;
- bool UseNPQ = false;
- if (!Magics.IsAdd) {
- assert(Magics.ShiftAmount < Divisor.getBitWidth() &&
- "We shouldn't generate an undefined shift!");
- PreShift = Magics.PreShift;
- PostShift = Magics.ShiftAmount;
- UseNPQ = false;
- } else {
- assert(Magics.PreShift == 0 && "Unexpected pre-shift");
- PostShift = Magics.ShiftAmount - 1;
- assert(PostShift < Divisor.getBitWidth() &&
- "We shouldn't generate an undefined shift!");
- UseNPQ = true;
- }
+ assert(Magics.PreShift < Divisor.getBitWidth() &&
+ "We shouldn't generate an undefined shift!");
+ assert(Magics.PostShift < Divisor.getBitWidth() &&
+ "We shouldn't generate an undefined shift!");
+ assert((!Magics.IsAdd || Magics.PreShift == 0) && "Unexpected pre-shift");
+ unsigned PreShift = Magics.PreShift;
+ unsigned PostShift = Magics.PostShift;
+ bool UseNPQ = Magics.IsAdd;
APInt NPQFactor =
UseNPQ ? APInt::getSignedMinValue(Bits) : APInt::getZero(Bits);