26 #define DEBUG_TYPE "integer-division" 42 assert(BitWidth == 32 &&
"Unexpected bit width");
68 if (
Instruction *URemInst = dyn_cast<Instruction>(URem))
93 if (
Instruction *UDiv = dyn_cast<Instruction>(Quotient))
111 if (BitWidth == 64) {
114 assert(BitWidth == 32 &&
"Unexpected bit width");
142 if (
Instruction *UDiv = dyn_cast<Instruction>(Q_Mag))
166 if (BitWidth == 64) {
172 assert(BitWidth == 32 &&
"Unexpected bit width");
219 SpecialCases->
setName(
Twine(SpecialCases->getName(),
"_udiv-special-cases"));
223 "udiv-loop-exit",
F, End);
225 "udiv-do-while",
F, End);
227 "udiv-preheader",
F, End);
378 Rem->
getOpcode() == Instruction::URem) &&
379 "Trying to expand remainder from a non-remainder function");
386 "Div of bitwidth other than 32 or 64 not supported");
389 if (Rem->
getOpcode() == Instruction::SRem) {
419 assert(UDiv->getOpcode() == Instruction::UDiv &&
"Non-udiv in expansion?");
436 Div->
getOpcode() == Instruction::UDiv) &&
437 "Trying to expand division from a non-division function");
444 "Div of bitwidth other than 32 or 64 not supported");
447 if (Div->
getOpcode() == Instruction::SDiv) {
488 Rem->
getOpcode() == Instruction::URem) &&
489 "Trying to expand remainder from a non-remainder function");
496 assert(RemTyBitWidth <= 32 &&
497 "Div of bitwidth greater than 32 not supported");
499 if (RemTyBitWidth == 32)
512 if (Rem->
getOpcode() == Instruction::SRem) {
515 ExtRem = Builder.
CreateSRem(ExtDividend, ExtDivisor);
519 ExtRem = Builder.
CreateURem(ExtDividend, ExtDivisor);
537 Rem->
getOpcode() == Instruction::URem) &&
538 "Trying to expand remainder from a non-remainder function");
545 assert(RemTyBitWidth <= 64 &&
"Div of bitwidth greater than 64 not supported");
547 if (RemTyBitWidth == 64)
560 if (Rem->
getOpcode() == Instruction::SRem) {
563 ExtRem = Builder.
CreateSRem(ExtDividend, ExtDivisor);
567 ExtRem = Builder.
CreateURem(ExtDividend, ExtDivisor);
586 Div->
getOpcode() == Instruction::UDiv) &&
587 "Trying to expand division from a non-division function");
594 assert(DivTyBitWidth <= 32 &&
"Div of bitwidth greater than 32 not supported");
596 if (DivTyBitWidth == 32)
609 if (Div->
getOpcode() == Instruction::SDiv) {
612 ExtDiv = Builder.
CreateSDiv(ExtDividend, ExtDivisor);
616 ExtDiv = Builder.
CreateUDiv(ExtDividend, ExtDivisor);
634 Div->
getOpcode() == Instruction::UDiv) &&
635 "Trying to expand division from a non-division function");
642 assert(DivTyBitWidth <= 64 &&
643 "Div of bitwidth greater than 64 not supported");
645 if (DivTyBitWidth == 64)
658 if (Div->
getOpcode() == Instruction::SDiv) {
661 ExtDiv = Builder.
CreateSDiv(ExtDividend, ExtDivisor);
665 ExtDiv = Builder.
CreateUDiv(ExtDividend, ExtDivisor);
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
LLVMContext & getContext() const
void dropAllReferences()
Drop all references to operands.
This class represents lattice values for constants.
BinaryOps getOpcode() const
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
bool expandRemainderUpTo64Bits(BinaryOperator *Rem)
Generate code to calculate the remainder of two integers, replacing Rem with the generated code...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
bool isVectorTy() const
True if this is an instance of VectorType.
iterator begin()
Instruction iterator methods.
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
void setName(const Twine &Name)
Change the name of the value.
Type * getType() const
All values are typed, get the type of this value.
Value * CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name="")
BasicBlock * GetInsertBlock() const
bool expandRemainderUpTo32Bits(BinaryOperator *Rem)
Generate code to calculate the remainder of two integers, replacing Rem with the generated code...
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
bool expandRemainder(BinaryOperator *Rem)
Generate code to calculate the remainder of two integers, replacing Rem with the generated code...
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
Value * getOperand(unsigned i) const
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
static Value * generateSignedDivisionCode(Value *Dividend, Value *Divisor, IRBuilder<> &Builder)
Generate code to divide two signed integers.
bool expandDivisionUpTo32Bits(BinaryOperator *Div)
Generate code to divide two integers, replacing Div with the generated code.
Value * CreateAShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
ConstantInt * getTrue()
Get the constant value for i1 true.
bool expandDivision(BinaryOperator *Div)
Generate code to divide two integers, replacing Div with the generated code.
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
bool expandDivisionUpTo64Bits(BinaryOperator *Div)
Generate code to divide two integers, replacing Div with the generated code.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
self_iterator getIterator()
Class to represent integer types.
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
static Value * generatedUnsignedRemainderCode(Value *Dividend, Value *Divisor, IRBuilder<> &Builder)
Generate code to compute the remainder of two unsigned integers.
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
This is the shared class of boolean and integer constants.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
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 * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
unsigned getIntegerBitWidth() const
const Function * getParent() const
Return the enclosing method, or null if none.
static Value * generateUnsignedDivisionCode(Value *Dividend, Value *Divisor, IRBuilder<> &Builder)
Generates code to divide two unsigned scalar 32-bit or 64-bit integers.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
static Value * generateSignedRemainderCode(Value *Dividend, Value *Divisor, IRBuilder<> &Builder)
Generate code to compute the remainder of two signed integers.
BasicBlock::iterator GetInsertPoint() const
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)