+ } else {
+ // Known to be an unsigned division.
+ if (Instruction *RHSI = dyn_cast<Instruction>(I.getOperand(1))) {
+ // Turn A / (C1 << N), where C1 is "1<<C2" into A >> (N+C2) [udiv only].
+ if (RHSI->getOpcode() == Instruction::Shl &&
+ isa<ConstantUInt>(RHSI->getOperand(0))) {
+ unsigned C1 = cast<ConstantUInt>(RHSI->getOperand(0))->getRawValue();
+ if (isPowerOf2_64(C1)) {
+ unsigned C2 = Log2_64(C1);
+ Value *Add = RHSI->getOperand(1);
+ if (C2) {
+ Constant *C2V = ConstantUInt::get(Add->getType(), C2);
+ Add = InsertNewInstBefore(BinaryOperator::createAdd(Add, C2V,
+ "tmp"), I);
+ }
+ return new ShiftInst(Instruction::Shr, Op0, Add);
+ }
+ }
+ }