38 cl::desc(
"fp convert instructions on integers with "
39 "more than <N> bits are expanded."));
97 unsigned FPMantissaWidth = FloatVal->getType()->getFPMantissaWidth() - 1;
102 if (FloatVal->getType()->isHalfTy()) {
103 if (FPToI->
getOpcode() == Instruction::FPToUI) {
118 FPMantissaWidth = FPMantissaWidth == 63 ? 112 : FPMantissaWidth;
119 unsigned FloatWidth =
120 PowerOf2Ceil(FloatVal->getType()->getScalarSizeInBits());
121 unsigned ExponentWidth = FloatWidth - FPMantissaWidth - 1;
122 unsigned ExponentBias = (1 << (ExponentWidth - 1)) - 1;
125 Value *SignificandMask =
135 Entry->setName(
Twine(Entry->getName(),
"fp-to-i-entry"));
137 Entry->splitBasicBlock(Builder.
GetInsertPoint(),
"fp-to-i-cleanup");
149 Entry->getTerminator()->eraseFromParent();
153 Value *FloatVal0 = FloatVal;
156 if (FloatVal->getType()->isX86_FP80Ty())
180 IntTy, -
static_cast<int64_t
>(ExponentBias +
BitWidth)));
209 IntTy, -
static_cast<int64_t
>(ExponentBias + FPMantissaWidth)));
313 IntegerType *IntTy = cast<IntegerType>(IntVal->getType());
315 unsigned BitWidth = IntVal->getType()->getIntegerBitWidth();
319 FPMantissaWidth = FPMantissaWidth == 63 ? 112 : FPMantissaWidth;
322 FPMantissaWidth = FPMantissaWidth == 10 ? 23 : FPMantissaWidth;
323 FPMantissaWidth = FPMantissaWidth == 7 ? 23 : FPMantissaWidth;
325 bool IsSigned = IToFP->
getOpcode() == Instruction::SIToFP;
327 assert(
BitWidth > FloatWidth &&
"Unexpected conversion. expandIToFP() "
328 "assumes integer width is larger than fp.");
336 Entry->setName(
Twine(Entry->getName(),
"itofp-entry"));
356 Entry->getTerminator()->eraseFromParent();
373 Value *Call = Builder.
CreateCall(CTLZ, {IsSigned ? Sub : IntVal, True});
375 int BitWidthNew = FloatWidth == 128 ?
BitWidth : 32;
377 FloatWidth == 128 ? Call : Cast);
379 FloatWidth == 128 ? Call : Cast);
381 Sub1, Builder.
getIntN(BitWidthNew, FPMantissaWidth + 1));
387 SI->addCase(Builder.
getIntN(BitWidthNew, FPMantissaWidth + 2), SwBB);
388 SI->addCase(Builder.
getIntN(BitWidthNew, FPMantissaWidth + 3), SwEpilog);
400 FloatWidth == 128 ? Call : Cast);
403 FloatWidth == 128 ? Sub5 : ShProm);
405 Builder.
CreateAdd(FloatWidth == 128 ? Call : Cast,
406 Builder.
getIntN(BitWidthNew, FPMantissaWidth + 3));
409 FloatWidth == 128 ? Sub8 : ShProm9);
420 AAddr0->
addIncoming(IsSigned ? Sub : IntVal, IfThen4);
428 Value *Shr18 =
nullptr;
437 Value *ExtractT64 =
nullptr;
446 Value *Shr21 =
nullptr;
453 Value *ExtractT62 =
nullptr;
463 FloatWidth == 128 ? Call : Cast,
465 -(
BitWidth - FPMantissaWidth - 1)));
468 FloatWidth == 128 ? Sub24 : ShProm25);
471 Value *ExtractT66 =
nullptr;
484 PHINode *AAddr1Off32 =
nullptr;
485 if (FloatWidth > 32) {
493 if (FloatWidth <= 80) {
499 Value *And29 =
nullptr;
500 if (FloatWidth > 80) {
503 And29 = Builder.
CreateAnd(Shr, Temp2,
"and29");
509 unsigned TempMod = FPMantissaWidth % 32;
510 Value *And34 =
nullptr;
511 Value *Shl30 =
nullptr;
512 if (FloatWidth > 80) {
517 Builder.
getIntN(64, ((1ull << (62ull - TempMod)) - 1ull) << TempMod));
522 Add, Builder.
getIntN(32, ((1 << (30 - TempMod)) - 1) << TempMod));
523 And34 = Builder.
CreateAnd(FloatWidth > 32 ? AAddr1Off32 : AAddr1Off0,
524 Builder.
getIntN(32, (1 << TempMod) - 1));
526 Value *Or35 =
nullptr;
527 if (FloatWidth > 80) {
532 Builder.
getIntN(128, FPMantissaWidth));
538 Or35 = Builder.
CreateOr(IsSigned ? Or31 : And34, Shl30);
574 VectorType *VTy = cast<FixedVectorType>(
I->getType());
578 unsigned NumElements = VTy->getElementCount().getFixedValue();
580 for (
unsigned Idx = 0;
Idx < NumElements; ++
Idx) {
583 I->getType()->getScalarType());
585 if (isa<Instruction>(Cast))
586 Replace.
push_back(cast<Instruction>(Cast));
588 I->replaceAllUsesWith(Result);
589 I->dropAllReferences();
590 I->eraseFromParent();
598 unsigned MaxLegalFpConvertBitWidth =
607 switch (
I.getOpcode()) {
608 case Instruction::FPToUI:
609 case Instruction::FPToSI: {
611 if (
I.getOperand(0)->getType()->isScalableTy())
614 auto *IntTy = cast<IntegerType>(
I.getType()->getScalarType());
615 if (IntTy->getIntegerBitWidth() <= MaxLegalFpConvertBitWidth)
618 if (
I.getOperand(0)->getType()->isVectorTy())
625 case Instruction::UIToFP:
626 case Instruction::SIToFP: {
628 if (
I.getOperand(0)->getType()->isScalableTy())
632 cast<IntegerType>(
I.getOperand(0)->getType()->getScalarType());
633 if (IntTy->getIntegerBitWidth() <= MaxLegalFpConvertBitWidth)
636 if (
I.getOperand(0)->getType()->isVectorTy())
648 while (!ReplaceVector.
empty()) {
656 while (!Replace.
empty()) {
658 if (
I->getOpcode() == Instruction::FPToUI ||
659 I->getOpcode() == Instruction::FPToSI) {
670class ExpandLargeFpConvertLegacyPass :
public FunctionPass {
681 auto *TLI =
TM->getSubtargetImpl(
F)->getTargetLowering();
700char ExpandLargeFpConvertLegacyPass::ID = 0;
702 "Expand large fp convert",
false,
false)
707 return new ExpandLargeFpConvertLegacyPass();
Expand Atomic instructions
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static bool runImpl(Function &F, const TargetLowering &TLI)
static void expandIToFP(Instruction *IToFP)
Generate code to convert a fp number to integer, replacing S(U)IToFP with the generated code.
static void expandFPToI(Instruction *FPToI)
Generate code to convert a fp number to integer, replacing FPToS(U)I with the generated code.
static void scalarize(Instruction *I, SmallVectorImpl< Instruction * > &Replace)
static cl::opt< unsigned > ExpandFpConvertBits("expand-fp-convert-bits", cl::Hidden, cl::init(llvm::IntegerType::MAX_INT_BITS), cl::desc("fp convert instructions on integers with " "more than <N> bits are expanded."))
static bool runImpl(Function &F, const TargetLowering &TLI)
static Expected< BitVector > expand(StringRef S, StringRef Original)
This is the interface for a simple mod/ref and alias analysis over globals.
FunctionAnalysisManager FAM
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
This file describes how to lower LLVM code to machine code.
Target-Independent Code Generator Pass Configuration Options pass.
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static Constant * getZero(Type *Ty, bool Negative=false)
This is the shared class of boolean and integer constants.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
FunctionPass class - This class is used to implement most global optimizations.
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
Legacy wrapper pass to provide the GlobalsAAResult object.
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
Value * CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name="")
ConstantInt * getTrue()
Get the constant value for i1 true.
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
Value * CreateFPToUI(Value *V, Type *DestTy, const Twine &Name="")
BasicBlock::iterator GetInsertPoint() const
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
BasicBlock * GetInsertBlock() const
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
SwitchInst * CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases=10, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a switch instruction with the specified value, default dest, and with a hint for the number of...
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
ConstantInt * getIntN(unsigned N, uint64_t C)
Get a constant N-bit value, zero extended or truncated from a 64-bit value.
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
LLVMContext & getContext() const
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateAShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateFPToSI(Value *V, Type *DestTy, const Twine &Name="")
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Class to represent integer types.
@ MAX_INT_BITS
Maximum number of bits that can be specified.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
unsigned getMaxLargeFPConvertBitWidthSupported() const
Returns the size in bits of the maximum larget fp convert the backend supports.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Primary interface to the complete machine description for the target machine.
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
Target-Independent Code Generator Pass Configuration Options.
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetLowering * getTargetLowering() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
unsigned getIntegerBitWidth() const
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
static Type * getFP128Ty(LLVMContext &C)
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
int getFPMantissaWidth() const
Return the width of the mantissa of this type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
static Type * getFloatTy(LLVMContext &C)
void dropAllReferences()
Drop all references to operands.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
FunctionPass * createExpandLargeFpConvertPass()
void initializeExpandLargeFpConvertLegacyPassPass(PassRegistry &)
@ Or
Bitwise or logical OR of integers.
@ Xor
Bitwise or logical XOR of integers.
@ And
Bitwise or logical AND of integers.
constexpr unsigned BitWidth