17 #define DEBUG_TYPE "integer-division"
55 if (
Instruction *URemInst = dyn_cast<Instruction>(URem))
78 if (
Instruction *UDiv = dyn_cast<Instruction>(Quotient))
116 if (
Instruction *UDiv = dyn_cast<Instruction>(Q_Mag))
178 SpecialCases->
setName(
Twine(SpecialCases->getName(),
"_udiv-special-cases"));
182 "udiv-loop-exit",
F, End);
184 "udiv-do-while",
F, End);
186 "udiv-preheader",
F, End);
335 assert((Rem->
getOpcode() == Instruction::SRem ||
336 Rem->
getOpcode() == Instruction::URem) &&
337 "Trying to expand remainder from a non-remainder function");
342 if (Rem->
getOpcode() == Instruction::SRem) {
352 if (!BO || BO->
getOpcode() != Instruction::URem)
368 assert(UDiv->getOpcode() == Instruction::UDiv &&
"Non-udiv in expansion?");
385 assert((Div->
getOpcode() == Instruction::SDiv ||
386 Div->
getOpcode() == Instruction::UDiv) &&
387 "Trying to expand division from a non-division function");
395 if (Div->
getOpcode() == Instruction::SDiv) {
405 if (!BO || BO->
getOpcode() != Instruction::UDiv)
430 assert((Rem->
getOpcode() == Instruction::SRem ||
431 Rem->
getOpcode() == Instruction::URem) &&
432 "Trying to expand remainder from a non-remainder function");
440 if (RemTyBitWidth > 32)
443 if (RemTyBitWidth == 32)
456 if (Rem->
getOpcode() == Instruction::SRem) {
459 ExtRem = Builder.
CreateSRem(ExtDividend, ExtDivisor);
463 ExtRem = Builder.
CreateURem(ExtDividend, ExtDivisor);
482 assert((Div->
getOpcode() == Instruction::SDiv ||
483 Div->
getOpcode() == Instruction::UDiv) &&
484 "Trying to expand division from a non-division function");
492 if (DivTyBitWidth > 32)
495 if (DivTyBitWidth == 32)
508 if (Div->
getOpcode() == Instruction::SDiv) {
511 ExtDiv = Builder.
CreateSDiv(ExtDividend, ExtDivisor);
515 ExtDiv = Builder.
CreateUDiv(ExtDividend, ExtDivisor);
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
BasicBlock::iterator GetInsertPoint() const
void addIncoming(Value *V, BasicBlock *BB)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
const Function * getParent() const
Return the enclosing method, or null if none.
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
#define llvm_unreachable(msg)
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=0)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
void setName(const Twine &Name)
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
bool expandRemainderUpTo32Bits(BinaryOperator *Rem)
Replace Rem with generated code.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
void replaceAllUsesWith(Value *V)
bool expandRemainder(BinaryOperator *Rem)
Replace Rem with generated code.
Value * CreateAShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
static Value * generateSignedDivisionCode(Value *Dividend, Value *Divisor, IRBuilder<> &Builder)
bool expandDivisionUpTo32Bits(BinaryOperator *Div)
Replace Rem with generated code.
LLVM Basic Block Representation.
ConstantInt * getTrue()
Get the constant value for i1 true.
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
bool expandDivision(BinaryOperator *Div)
Replace Div with generated code.
Value * getOperand(unsigned i) const
Integer representation type.
LLVMContext & getContext() const
static Value * generatedUnsignedRemainderCode(Value *Dividend, Value *Divisor, IRBuilder<> &Builder)
BinaryOps getOpcode() const
unsigned getIntegerBitWidth() const
Class for constant integers.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
BasicBlock * GetInsertBlock() const
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Get a ConstantInt for a specific signed value.
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateSDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="")
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
static Value * generateUnsignedDivisionCode(Value *Dividend, Value *Divisor, IRBuilder<> &Builder)
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=0, BasicBlock *InsertBefore=0)
Creates a new BasicBlock.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
CallInst * CreateCall2(Value *Callee, Value *Arg1, Value *Arg2, const Twine &Name="")
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
LLVM Value Representation.
static Value * generateSignedRemainderCode(Value *Dividend, Value *Divisor, IRBuilder<> &Builder)
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
Value * CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name="")