25 #define DEBUG_TYPE "integer-division" 41 assert(BitWidth == 32 &&
"Unexpected bit width");
67 if (
Instruction *URemInst = dyn_cast<Instruction>(URem))
92 if (
Instruction *UDiv = dyn_cast<Instruction>(Quotient))
110 if (BitWidth == 64) {
113 assert(BitWidth == 32 &&
"Unexpected bit width");
141 if (
Instruction *UDiv = dyn_cast<Instruction>(Q_Mag))
165 if (BitWidth == 64) {
171 assert(BitWidth == 32 &&
"Unexpected bit width");
218 SpecialCases->
setName(
Twine(SpecialCases->getName(),
"_udiv-special-cases"));
222 "udiv-loop-exit",
F, End);
224 "udiv-do-while",
F, End);
226 "udiv-preheader",
F, End);
377 Rem->
getOpcode() == Instruction::URem) &&
378 "Trying to expand remainder from a non-remainder function");
385 "Div of bitwidth other than 32 or 64 not supported");
388 if (Rem->
getOpcode() == Instruction::SRem) {
418 assert(UDiv->getOpcode() == Instruction::UDiv &&
"Non-udiv in expansion?");
435 Div->
getOpcode() == Instruction::UDiv) &&
436 "Trying to expand division from a non-division function");
443 "Div of bitwidth other than 32 or 64 not supported");
446 if (Div->
getOpcode() == Instruction::SDiv) {
487 Rem->
getOpcode() == Instruction::URem) &&
488 "Trying to expand remainder from a non-remainder function");
495 assert(RemTyBitWidth <= 32 &&
496 "Div of bitwidth greater than 32 not supported");
498 if (RemTyBitWidth == 32)
511 if (Rem->
getOpcode() == Instruction::SRem) {
514 ExtRem = Builder.
CreateSRem(ExtDividend, ExtDivisor);
518 ExtRem = Builder.
CreateURem(ExtDividend, ExtDivisor);
536 Rem->
getOpcode() == Instruction::URem) &&
537 "Trying to expand remainder from a non-remainder function");
544 assert(RemTyBitWidth <= 64 &&
"Div of bitwidth greater than 64 not supported");
546 if (RemTyBitWidth == 64)
559 if (Rem->
getOpcode() == Instruction::SRem) {
562 ExtRem = Builder.
CreateSRem(ExtDividend, ExtDivisor);
566 ExtRem = Builder.
CreateURem(ExtDividend, ExtDivisor);
585 Div->
getOpcode() == Instruction::UDiv) &&
586 "Trying to expand division from a non-division function");
593 assert(DivTyBitWidth <= 32 &&
"Div of bitwidth greater than 32 not supported");
595 if (DivTyBitWidth == 32)
608 if (Div->
getOpcode() == Instruction::SDiv) {
611 ExtDiv = Builder.
CreateSDiv(ExtDividend, ExtDivisor);
615 ExtDiv = Builder.
CreateUDiv(ExtDividend, ExtDivisor);
633 Div->
getOpcode() == Instruction::UDiv) &&
634 "Trying to expand division from a non-division function");
641 assert(DivTyBitWidth <= 64 &&
642 "Div of bitwidth greater than 64 not supported");
644 if (DivTyBitWidth == 64)
657 if (Div->
getOpcode() == Instruction::SDiv) {
660 ExtDiv = Builder.
CreateSDiv(ExtDividend, ExtDivisor);
664 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.
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)