const SCEV *visitUnknown(const SCEVUnknown *E) { // If a value mapping was given try if the underlying value is remapped. Value *NewVal = VMap ? VMap->lookup(E->getValue()) : nullptr; if (NewVal) { auto *NewE = SE.getSCEV(NewVal); // While the mapped value might be different the SCEV representation might // not be. To this end we will check before we go into recursion here. if (E != NewE) return visit(NewE); } Instruction *Inst = dyn_cast<Instruction>(E->getValue()); Instruction *IP; if (Inst && !R.contains(Inst)) IP = Inst; else if (Inst && RTCBB->getParent() == Inst->getFunction()) IP = RTCBB->getTerminator(); else IP = RTCBB->getParent()->getEntryBlock().getTerminator(); if (!Inst || (Inst->getOpcode() != Instruction::SRem && Inst->getOpcode() != Instruction::SDiv)) return visitGenericInst(E, Inst, IP); const SCEV *LHSScev = SE.getSCEV(Inst->getOperand(0)); const SCEV *RHSScev = SE.getSCEV(Inst->getOperand(1)); if (!SE.isKnownNonZero(RHSScev)) RHSScev = SE.getUMaxExpr(RHSScev, SE.getConstant(E->getType(), 1)); Value *LHS = expandCodeFor(LHSScev, E->getType(), IP); Value *RHS = expandCodeFor(RHSScev, E->getType(), IP); Inst = BinaryOperator::Create((Instruction::BinaryOps)Inst->getOpcode(), LHS, RHS, Inst->getName() + Name, IP); return SE.getSCEV(Inst); }