Lines Matching full:instruction
111 typedef SmallPtrSet<Instruction *, 16> SetOfInstrs;
117 typedef DenseMap<Instruction *, TypeIsSExt> InstrToOrigTy;
129 /// next instruction to optimize. Xforms that can invalidate this should
140 /// Keeps track of the type of the related instruction before their
172 bool OptimizeInst(Instruction *I, bool& ModifiedDT);
173 bool OptimizeMemoryInst(Instruction *I, Value *Addr, Type *AccessTy);
176 bool MoveExtToFormExtLoad(Instruction *&I);
177 bool OptimizeExtUses(Instruction *I);
180 bool OptimizeExtractElementInst(Instruction *Inst);
185 Instruction *&Inst,
186 const SmallVectorImpl<Instruction *> &Exts,
189 bool simplifyOffsetableRelocate(Instruction &I);
236 // into a single target instruction, push the mask and compare into branch
299 SmallVector<Instruction *, 2> Statepoints;
301 for (Instruction &I : BB)
361 // If the instruction before the branch (skipping debug info) isn't a phi
400 const Instruction *UI = cast<Instruction>(U);
409 Instruction *Insn = dyn_cast<Instruction>(UPN->getIncomingValue(I));
574 // Takes a RelocatedBase (base pointer relocation instruction) and Targets to
605 Instruction *ReplacementInst = cast<Instruction>(Replacement);
634 bool CodeGenPrepare::simplifyOffsetableRelocate(Instruction &I) {
639 if (isGCRelocate(dyn_cast<Instruction>(U)))
648 // RelocateInstMap is a mapping from the base relocate instruction to the
662 /// SinkCast - Sink the specified cast instruction into its user blocks
673 Instruction *User = cast<Instruction>(*UI);
713 /// OptimizeNoopCopyExpression - If the specified cast instruction is a noop
756 Instruction *AddI;
813 Instruction *User = cast<Instruction>(*UI);
865 /// be combined with shift instruction, which includes:
866 /// 1. Truncate instruction
867 /// 2. And instruction and the imm is a mask of the low bits:
869 static bool isExtractBitsCandidateUse(Instruction *User) {
871 if (User->getOpcode() != Instruction::And ||
883 /// SinkShiftAndTruncate - sink both shift and truncate instruction
886 SinkShiftAndTruncate(BinaryOperator *ShiftI, Instruction
899 Instruction *TruncUser = cast<Instruction>(*TruncUI);
932 if (ShiftI->getOpcode() == Instruction::AShr)
954 /// OptimizeExtractBits - sink the shift *right* instruction into user blocks if
955 /// the uses could potentially be combined with this shift instruction and
956 /// generate BitExtract instruction. It will only be applied if the architecture
957 /// supports BitExtract instruction. Here is an example:
969 /// instruction.
984 Instruction *User = cast<Instruction>(*UI);
998 // If the shift and truncate instruction are in the same BB. The use of
1001 // instruction to the BB of TruncUse.
1027 if (ShiftI->getOpcode() == Instruction::AShr)
1093 Instruction *InsertPt = CI;
1152 Instruction *OldBr = IfBlock->getTerminator();
1206 Instruction *InsertPt = CI;
1246 Instruction *OldBr = IfBlock->getTerminator();
1340 // If the iterator instruction was recursively deleted, start over at the
1457 // return is the first instruction in the block.
1517 // Make sure the call instruction is followed by an unconditional branch to
1614 /// The Instruction modified.
1615 Instruction *Inst;
1620 TypePromotionAction(Instruction *Inst) : Inst(Inst) {}
1639 /// \brief Utility to remember the position of an instruction.
1641 /// Position of an instruction.
1642 /// Either an instruction:
1646 Instruction *PrevInst;
1649 /// Remember whether or not the instruction had a previous instruction.
1654 InsertionHandler(Instruction *Inst) {
1664 void insert(Instruction *Inst) {
1670 Instruction *Position = Point.BB->getFirstInsertionPt();
1679 /// \brief Move an instruction before another.
1681 /// Original position of the instruction.
1686 InstructionMoveBefore(Instruction *Inst, Instruction *Before)
1692 /// \brief Move the instruction back to its original position.
1699 /// \brief Set the operand of an instruction with a new value.
1701 /// Original operand of the instruction.
1703 /// Index of the modified instruction.
1708 OperandSetter(Instruction *Inst, unsigned Idx, Value *NewVal)
1717 /// \brief Restore the original value of the instruction.
1726 /// \brief Hide the operands of an instruction.
1727 /// Do as if this instruction was not using any of its operands.
1734 OperandsHider(Instruction *Inst) : TypePromotionAction(Inst) {
1757 /// \brief Build a truncate instruction.
1761 /// \brief Build a truncate instruction of \p Opnd producing a \p Ty
1764 TruncBuilder(Instruction *Opnd, Type *Ty) : TypePromotionAction(Opnd) {
1773 /// \brief Remove the built instruction.
1776 if (Instruction *IVal = dyn_cast<Instruction>(Val))
1781 /// \brief Build a sign extension instruction.
1785 /// \brief Build a sign extension instruction of \p Opnd producing a \p Ty
1788 SExtBuilder(Instruction *InsertPt, Value *Opnd, Type *Ty)
1798 /// \brief Remove the built instruction.
1801 if (Instruction *IVal = dyn_cast<Instruction>(Val))
1806 /// \brief Build a zero extension instruction.
1810 /// \brief Build a zero extension instruction of \p Opnd producing a \p Ty
1813 ZExtBuilder(Instruction *InsertPt, Value *Opnd, Type *Ty)
1823 /// \brief Remove the built instruction.
1826 if (Instruction *IVal = dyn_cast<Instruction>(Val))
1831 /// \brief Mutate an instruction to another type.
1838 TypeMutator(Instruction *Inst, Type *NewTy)
1845 /// \brief Mutate the instruction back to its original type.
1853 /// \brief Replace the uses of an instruction by another instruction.
1857 /// The instruction using the instruction.
1858 Instruction *Inst;
1859 /// The index where this instruction is used for Inst.
1861 InstructionAndIdx(Instruction *Inst, unsigned Idx)
1865 /// Keep track of the original uses (pair Instruction, Index).
1871 UsesReplacer(Instruction *Inst, Value *New) : TypePromotionAction(Inst) {
1876 Instruction *UserI = cast<Instruction>(U.getUser());
1894 /// \brief Remove an instruction from the IR.
1896 /// Original position of the instruction.
1898 /// Helper structure to hide all the link to the instruction. In other
1899 /// words, this helps to do as if the instruction was removed.
1908 InstructionRemover(Instruction *Inst, Value *New = nullptr)
1919 /// \brief Really remove the instruction.
1922 /// \brief Resurrect the instruction and reassign it to the proper uses if
1947 /// Same as Instruction::setOperand.
1948 void setOperand(Instruction *Inst, unsigned Idx, Value *NewVal);
1949 /// Same as Instruction::eraseFromParent.
1950 void eraseInstruction(Instruction *Inst, Value *NewVal = nullptr);
1952 void replaceAllUsesWith(Instruction *Inst, Value *New);
1954 void mutateType(Instruction *Inst, Type *NewTy);
1956 Value *createTrunc(Instruction *Opnd, Type *Ty);
1958 Value *createSExt(Instruction *Inst, Value *Opnd, Type *Ty);
1960 Value *createZExt(Instruction *Inst, Value *Opnd, Type *Ty);
1961 /// Same as Instruction::moveBefore.
1962 void moveBefore(Instruction *Inst, Instruction *Before);
1971 void TypePromotionTransaction::setOperand(Instruction *Inst, unsigned Idx,
1977 void TypePromotionTransaction::eraseInstruction(Instruction *Inst,
1983 void TypePromotionTransaction::replaceAllUsesWith(Instruction *Inst,
1988 void TypePromotionTransaction::mutateType(Instruction *Inst, Type *NewTy) {
1992 Value *TypePromotionTransaction::createTrunc(Instruction *Opnd,
2000 Value *TypePromotionTransaction::createSExt(Instruction *Inst,
2008 Value *TypePromotionTransaction::createZExt(Instruction *Inst,
2016 void TypePromotionTransaction::moveBefore(Instruction *Inst,
2017 Instruction *Before) {
2046 SmallVectorImpl<Instruction*> &AddrModeInsts;
2051 /// the memory instruction that we're computing this address for.
2053 Instruction *MemoryInst;
2059 /// The truncate instruction inserted by other CodeGenPrepare optimizations.
2071 AddressingModeMatcher(SmallVectorImpl<Instruction *> &AMI,
2072 const TargetMachine &TM, Type *AT, Instruction *MI,
2088 /// \p InsertedTruncs The truncate instruction inserted by other
2094 Instruction *MemoryInst,
2095 SmallVectorImpl<Instruction*> &AddrModeInsts,
2113 bool IsProfitableToFoldIntoAddressingMode(Instruction *I,
2158 if (isa<Instruction>(ScaleReg) && // not a constant expr.
2164 // this instruction.
2166 AddrModeInsts.push_back(cast<Instruction>(ScaleReg));
2180 static bool MightBeFoldableInst(Instruction *I) {
2182 case Instruction::BitCast:
2183 case Instruction::AddrSpaceCast:
2188 case Instruction::PtrToInt:
2191 case Instruction::IntToPtr:
2194 case Instruction::Add:
2196 case Instruction::Mul:
2197 case Instruction::Shl:
2200 case Instruction::GetElementPtr:
2207 /// \brief Check whether or not \p Val is a legal instruction for \p TLI.
2212 Instruction *PromotedInst = dyn_cast<Instruction>(Val);
2219 // Otherwise, check if the promoted instruction is legal or not.
2237 static bool canGetThrough(const Instruction *Inst, Type *ConsideredExtType,
2242 static bool shouldExtOperand(const Instruction
2258 Instruction *Ext, TypePromotionTransaction &TPT,
2260 SmallVectorImpl<Instruction *> *Exts,
2261 SmallVectorImpl<Instruction *> *Truncs, const TargetLowering &TLI);
2272 static Value *promoteOperandForOther(Instruction *Ext,
2276 SmallVectorImpl<Instruction *> *Exts,
2277 SmallVectorImpl<Instruction *> *Truncs,
2282 Instruction *Ext, TypePromotionTransaction &TPT,
2284 SmallVectorImpl<Instruction *> *Exts,
2285 SmallVectorImpl<Instruction *> *Truncs, const TargetLowering &TLI) {
2292 Instruction *Ext, TypePromotionTransaction &TPT,
2294 SmallVectorImpl<Instruction *> *Exts,
2295 SmallVectorImpl<Instruction *> *Truncs, const TargetLowering &TLI) {
2302 typedef Value *(*Action)(Instruction *Ext, TypePromotionTransaction &TPT,
2305 SmallVectorImpl<Instruction *> *Exts,
2306 SmallVectorImpl<Instruction *> *Truncs,
2308 /// \brief Given a sign/zero extend instruction \p Ext, return the approriate
2317 static Action getAction(Instruction *Ext, const SetOfInstrs &InsertedTruncs,
2322 bool TypePromotionHelper::canGetThrough(const Instruction *Inst,
2362 // If the operand of the truncate is not an instruction, we will not have
2365 Instruction *Opnd = dyn_cast<Instruction>(OpndVal);
2390 Instruction *Ext, const SetOfInstrs &InsertedTruncs,
2393 "Unexpected instruction type");
2394 Instruction *ExtOpnd = dyn_cast<Instruction>(Ext->getOperand(0));
2397 // If the operand of the extension is not an instruction, we cannot
2415 // Regular instruction.
2423 llvm::Instruction *SExt, TypePromotionTransaction &TPT,
2425 SmallVectorImpl<Instruction *> *Exts,
2426 SmallVectorImpl<Instruction *> *Truncs, const TargetLowering &TLI) {
2427 // By construction, the operand of SExt is an instruction. Otherwise we cannot
2429 Instruction *SExtOpnd = cast<Instruction>(SExt->getOperand(0));
2453 Instruction *ExtInst = dyn_cast<Instruction>(ExtVal);
2471 Instruction *Ext, TypePromotionTransaction &TPT,
2473 SmallVectorImpl<Instruction *> *Exts,
2474 SmallVectorImpl<Instruction *> *Truncs, const TargetLowering &TLI,
2476 // By construction, the operand of Ext is an instruction. Otherwise we cannot
2478 Instruction *ExtOpnd = cast<Instruction>(Ext->getOperand(0));
2486 if (Instruction *ITrunc = dyn_cast<Instruction>(Trunc)) {
2500 // Get through the Instruction:
2505 // Remember the original type of the instruction before promotion.
2507 PromotedInsts.insert(std::pair<Instruction *, TypeIsSExt>(
2514 Instruction *ExtForOpnd = Ext;
2549 if (!isa<Instruction>(ValForExtOpnd)) {
2553 ExtForOpnd = cast<Instruction>(ValForExtOpnd);
2573 /// IsPromotionProfitable - Check whether or not promoting an instruction
2594 // Check that we did not create an illegal instruction.
2598 /// MatchOperationAddr - Given an instruction or constant expr, see if we can
2620 case Instruction::PtrToInt:
2623 case Instruction::IntToPtr:
2629 case Instruction::BitCast:
2630 case Instruction::AddrSpaceCast:
2641 case Instruction::Add: {
2672 //case Instruction::Or:
2675 case Instruction::Mul:
2676 case Instruction::Shl: {
2682 if (Opcode == Instruction::Shl)
2687 case Instruction::GetElementPtr: {
2773 case Instruction::SExt:
2774 case Instruction::ZExt: {
2775 Instruction *Ext = dyn_cast<Instruction>(AddrInst);
2856 } else if (Instruction *I = dyn_cast<Instruction>(Addr)) {
2863 // This instruction may have been move away. If so, there is nothing
2944 /// memory use. If we find an obviously non-foldable instruction, return true.
2947 Instruction *I,
2948 SmallVectorImpl<std::pair<Instruction *, unsigned>> &MemoryUses,
2949 SmallPtrSetImpl<Instruction *> &ConsideredInsts, const TargetMachine &TM) {
2950 // If we already considered this instruction, we're done.
2954 // If this is an obviously unfoldable instruction, bail out.
2960 Instruction *UserI = cast<Instruction>(U.getUser());
2994 /// that we know are live at the instruction already.
3002 if (!isa<Instruction>(Val) && !isa<Argument>(Val)) return true;
3011 // Check to see if this value is already used in the memory instruction's
3018 /// mode of the machine to fold the specified instruction into a load or store
3019 /// that ultimately uses it. However, the specified instruction has multiple
3039 IsProfitableToFoldIntoAddressingMode(Instruction *I, ExtAddrMode &AMBefore,
3043 // AMBefore is the addressing mode before this instruction was folded into it,
3044 // and AMAfter is the addressing mode after the instruction was folded. Get
3055 // lifetime wasn't extended by adding this instruction.
3061 // If folding this instruction (and it's subexprs) didn't extend any live
3066 // If all uses of this instruction are ultimately load/store/inlineasm's,
3067 // check to see if their addressing modes will include this instruction. If
3070 SmallVector<std::pair<Instruction*,unsigned>, 16> MemoryUses;
3071 SmallPtrSet<Instruction*, 16> ConsideredInsts;
3075 // Now that we know that all uses of this instruction are part of a chain of
3078 // *actually* fold the instruction.
3079 SmallVector<Instruction*, 32> MatchedAddrModeInsts;
3081 Instruction *User = MemoryUses[i].first;
3093 // *actually* cover the shared instruction.
3125 if (Instruction *I = dyn_cast<Instruction>(V))
3132 /// instruction selection will try to get the load or store to do as much
3139 bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
3155 SmallVector<Instruction*, 16> AddrModeInsts;
3178 SmallVector<Instruction*, 16> NewAddrModeInsts;
3339 Instruction *I = dyn_cast_or_null<Instruction>(ResultIndex);
3415 Instruction *I = dyn_cast_or_null<Instruction>(Result);
3466 // If the iterator instruction was recursively deleted, start over at the
3506 static bool hasSameExtUse(Instruction *Inst, const TargetLowering &TLI) {
3508 const Instruction *FirstUser = cast<Instruction>(*Inst->user_begin());
3512 const Instruction *UI = cast<Instruction>(U);
3516 // Same input and output types: Same instruction after CSE.
3553 /// load instruction.
3577 LoadInst *&LI, Instruction *&Inst,
3578 const SmallVectorImpl<Instruction *> &Exts,
3600 SmallVector<Instruction *, 4> NewExts;
3649 bool CodeGenPrepare::MoveExtToFormExtLoad(Instruction *&I) {
3655 SmallVector<Instruction *, 1> Exts;
3659 Instruction *OldExt = I;
3662 assert(!HasPromoted && !LI && "If we did not match any load instruction "
3710 bool CodeGenPrepare::OptimizeExtUses(Instruction *I) {
3725 if (!isa<Instruction>(Src) || DefBB != cast<Instruction>(Src)->getParent())
3730 Instruction *UI = cast<Instruction>(U);
3743 Instruction *UI = cast<Instruction>(U);
3753 DenseMap<BasicBlock*, Instruction*> InsertedTruncs;
3757 Instruction *User = cast<Instruction>(U.getUser());
3764 Instruction *&InsertedTrunc = InsertedTruncs[UserBB];
3829 // We have efficient codegen support for the select instruction.
3898 DenseMap<BasicBlock*, Instruction*> InsertedShuffles;
3902 Instruction *UI = cast<Instruction>(U);
3908 instruction.
3913 Instruction *&InsertedShuffle = InsertedShuffles[UserBB];
3959 Instruction *Transition;
3961 SmallVector<Instruction *, 4> InstsToBePromoted;
3964 /// Instruction that will be combined with the transition.
3965 Instruction *CombineInst;
3967 /// \brief The instruction that represents the current end of the transition.
3970 Instruction *getEndOfTransition() const {
4009 void promoteImpl(Instruction *ToBePromoted);
4098 static bool canCauseUndefinedBehavior(const Instruction *Use,
4101 // the right hand side of a division-like instruction.
4107 case Instruction::SDiv:
4108 case Instruction::UDiv:
4109 case Instruction::SRem:
4110 case Instruction::URem:
4112 case Instruction::FDiv:
4113 case Instruction::FRem:
4121 Instruction *Transition, unsigned CombineCost)
4128 bool canPromote(const Instruction *ToBePromoted) const {
4135 bool shouldPromote(const Instruction *ToBePromoted) const {
4164 bool canCombine(const Instruction *Use) { return isa<StoreInst>(Use); }
4167 void enqueueForPromotion(Instruction *ToBePromoted) {
4171 /// \brief Set the instruction that will be combined with the transition.
4172 void recordCombineInstruction(Instruction *ToBeCombined) {
4173 assert(canCombine(ToBeCombined) && "Unsupported instruction to combine");
4200 void VectorPromoteHelper::promoteImpl(Instruction *ToBePromoted) {
4242 /// Some targets can do store(extractelement) with one instruction.
4245 bool CodeGenPrepare::OptimizeExtractElementInst(Instruction *Inst) {
4266 Instruction *ToBePromoted = cast<Instruction>(*Inst->user_begin());
4270 DEBUG(dbgs() << "Instruction to promote is in a different block ("
4297 bool CodeGenPrepare::OptimizeInst(Instruction *I, bool& ModifiedDT) {
4359 if (BinOp && (BinOp->getOpcode() == Instruction::AShr ||
4360 BinOp->getOpcode() == Instruction::LShr)) {
4371 Instruction *NC = new BitCastInst(GEPI->getOperand(0), GEPI->getType(),
4421 Instruction *PrevNonDbgInst = nullptr;
4423 Instruction *Insn = BI++;
4435 Instruction *VI = dyn_cast_or_null<Instruction>(DVI->getValue());
4452 // against zero that can be combined into a single instruction, and the
4453 // target supports folding these into a single instruction, sink the
4479 Instruction *And = dyn_cast<Instruction>(Cmp->getOperand(0));
4480 if (!And || And->getOpcode() != Instruction::And || And->getParent() != BB)
4565 /// This usually allows instruction selection to do even further optimizations
4566 /// and combine the compare with the branch instruction. Currently this is
4578 // %cond1 = icmp|fcmp|binary instruction ...
4579 // %cond2 = icmp|fcmp|binary instruction ...
4591 Opc = Instruction::And;
4594 Opc = Instruction::Or;
4612 // branch instruction and removing the no longer needed and/or instruction.
4618 // successor of the original branch instruction.
4619 if (Opc == Instruction::And)
4626 if (auto *I = dyn_cast<Instruction>(Cond2)) {
4639 // instruction (or any other instruction).
4640 if (Opc == Instruction::Or)
4664 if (Opc == Instruction::Or) {