Lines Matching defs:UseInst
88 Value *foldIVUser(Instruction *UseInst, Instruction *IVOperand);
90 bool eliminateIdentitySCEV(Instruction *UseInst, Instruction *IVOperand);
91 bool replaceIVUserWithLoopInvariant(Instruction *UseInst);
92 bool replaceFloatIVWithIntegerIV(Instruction *UseInst);
97 bool eliminateIVUser(Instruction *UseInst, Instruction *IVOperand);
129 /// IVOperand is guaranteed SCEVable, but UseInst may not be.
134 Value *SimplifyIndvar::foldIVUser(Instruction *UseInst, Instruction *IVOperand) {
139 switch (UseInst->getOpcode()) {
146 if (IVOperand != UseInst->getOperand(OperIdx) ||
147 !isa<ConstantInt>(UseInst->getOperand(1)))
160 ConstantInt *D = cast<ConstantInt>(UseInst->getOperand(1));
161 if (UseInst->getOpcode() == Instruction::LShr) {
163 uint32_t BitWidth = cast<IntegerType>(UseInst->getType())->getBitWidth();
167 D = ConstantInt::get(UseInst->getContext(),
175 if (UseInst->isExact() && LHS != SE->getMulExpr(FoldedExpr, RHS))
179 if (!SE->isSCEVable(UseInst->getType()))
183 if (SE->getSCEV(UseInst) != FoldedExpr)
187 << " -> " << *UseInst << '\n');
189 UseInst->setOperand(OperIdx, IVSrc);
190 assert(SE->getSCEV(UseInst) == FoldedExpr && "bad SCEV with folded oper");
193 UseInst->dropPoisonGeneratingFlags();
593 /// but UseInst may not be.
594 bool SimplifyIndvar::eliminateIVUser(Instruction *UseInst,
596 if (ICmpInst *ICmp = dyn_cast<ICmpInst>(UseInst)) {
600 if (BinaryOperator *Bin = dyn_cast<BinaryOperator>(UseInst)) {
611 if (auto *WO = dyn_cast<WithOverflowInst>(UseInst))
615 if (auto *SI = dyn_cast<SaturatingInst>(UseInst))
619 if (auto *TI = dyn_cast<TruncInst>(UseInst))
623 if (eliminateIdentitySCEV(UseInst, IVOperand))
636 /// Replace the UseInst with a loop invariant expression if it is safe.
682 bool SimplifyIndvar::replaceFloatIVWithIntegerIV(Instruction *UseInst) {
683 if (UseInst->getOpcode() != CastInst::SIToFP &&
684 UseInst->getOpcode() != CastInst::UIToFP)
687 Instruction *IVOperand = cast<Instruction>(UseInst->getOperand(0));
691 if (UseInst->getOpcode() == CastInst::SIToFP)
695 int DestNumSigBits = UseInst->getType()->getFPMantissaWidth();
697 for (User *U : UseInst->users()) {
717 UseInst->getOpcode() == CastInst::UIToFP) {
739 bool SimplifyIndvar::eliminateIdentitySCEV(Instruction *UseInst,
741 if (!SE->isSCEVable(UseInst->getType()) ||
742 UseInst->getType() != IVOperand->getType())
745 const SCEV *UseSCEV = SE->getSCEV(UseInst);
765 if (isa<PHINode>(UseInst))
766 // If UseInst is not a PHI node then we know that IVOperand dominates
767 // UseInst directly from the legality of SSA.
768 if (!DT || !DT->dominates(IVOperand, UseInst))
771 if (!LI->replacementPreservesLCSSAForm(UseInst, IVOperand))
775 if (!impliesPoison(IVOperand, UseInst)) {
784 LLVM_DEBUG(dbgs() << "INDVARS: Eliminated identity: " << *UseInst << '\n');
786 SE->forgetValue(UseInst);
787 UseInst->replaceAllUsesWith(IVOperand);
790 DeadInsts.emplace_back(UseInst);
929 Instruction *UseInst = UseOper.first;
935 if (isInstructionTriviallyDead(UseInst, /* TLI */ nullptr)) {
936 DeadInsts.emplace_back(UseInst);
941 if (UseInst == CurrIV) continue;
943 // Try to replace UseInst with a loop invariant before any other
945 if (replaceIVUserWithLoopInvariant(UseInst))
950 if ((isa<PtrToIntInst>(UseInst)) || (isa<TruncInst>(UseInst)))
951 for (Use &U : UseInst->uses()) {
962 Value *NewOper = foldIVUser(UseInst, IVOperand);
970 if (eliminateIVUser(UseInst, IVOperand)) {
975 if (BinaryOperator *BO = dyn_cast<BinaryOperator>(UseInst)) {
984 if (replaceFloatIVWithIntegerIV(UseInst)) {
990 CastInst *Cast = dyn_cast<CastInst>(UseInst);
995 if (isSimpleIVUser(UseInst, L, SE)) {
996 pushIVUsers(UseInst, Simplified, SimpleIVUsers);