bool CallAnalyzer::visitCastInst(CastInst &I) { // Propagate constants through ptrtoint. if (Constant *COp = dyn_cast<Constant>(I.getOperand(0))) if (Constant *C = ConstantExpr::getCast(I.getOpcode(), COp, I.getType())) { SimplifiedValues[&I] = C; return true; } // Disable SROA in the face of arbitrary casts we don't whitelist elsewhere. disableSROA(I.getOperand(0)); // No-op casts don't have any cost. if (I.isLosslessCast()) return true; // trunc to a native type is free (assuming the target has compare and // shift-right of the same width). if (TD && isa<TruncInst>(I) && TD->isLegalInteger(TD->getTypeSizeInBits(I.getType()))) return true; // Result of a cmp instruction is often extended (to be used by other // cmp instructions, logical or return instructions). These are usually // no-ops on most sane targets. if (isa<CmpInst>(I.getOperand(0))) return true; // Assume the rest of the casts require work. return false; }
/// Try to simplify cast instruction. bool UnrolledInstAnalyzer::visitCastInst(CastInst &I) { // Propagate constants through casts. Constant *COp = dyn_cast<Constant>(I.getOperand(0)); if (!COp) COp = SimplifiedValues.lookup(I.getOperand(0)); // If we know a simplified value for this operand and cast is valid, save the // result to SimplifiedValues. // The cast can be invalid, because SimplifiedValues contains results of SCEV // analysis, which operates on integers (and, e.g., might convert i8* null to // i32 0). if (COp && CastInst::castIsValid(I.getOpcode(), COp, I.getType())) { if (Constant *C = ConstantExpr::getCast(I.getOpcode(), COp, I.getType())) { SimplifiedValues[&I] = C; return true; } } return Base::visitCastInst(I); }
/// If a value has only one user that is a CastInst, return it. Value *llvm::getUniqueCastUse(Value *Ptr, Loop *Lp, Type *Ty) { Value *UniqueCast = nullptr; for (User *U : Ptr->users()) { CastInst *CI = dyn_cast<CastInst>(U); if (CI && CI->getType() == Ty) { if (!UniqueCast) UniqueCast = CI; else return nullptr; } } return UniqueCast; }
bool CallAnalyzer::visitCastInst(CastInst &I) { // Propagate constants through ptrtoint. if (Constant *COp = dyn_cast<Constant>(I.getOperand(0))) if (Constant *C = ConstantExpr::getCast(I.getOpcode(), COp, I.getType())) { SimplifiedValues[&I] = C; return true; } // Disable SROA in the face of arbitrary casts we don't whitelist elsewhere. disableSROA(I.getOperand(0)); return isInstructionFree(&I, TD); }
/// Try to simplify cast instruction. bool UnrolledInstAnalyzer::visitCastInst(CastInst &I) { // Propagate constants through casts. Constant *COp = dyn_cast<Constant>(I.getOperand(0)); if (!COp) COp = SimplifiedValues.lookup(I.getOperand(0)); if (COp) if (Constant *C = ConstantExpr::getCast(I.getOpcode(), COp, I.getType())) { SimplifiedValues[&I] = C; return true; } return Base::visitCastInst(I); }
bool CallAnalyzer::visitCastInst(CastInst &I) { // Propagate constants through ptrtoint. Constant *COp = dyn_cast<Constant>(I.getOperand(0)); if (!COp) COp = SimplifiedValues.lookup(I.getOperand(0)); if (COp) if (Constant *C = ConstantExpr::getCast(I.getOpcode(), COp, I.getType())) { SimplifiedValues[&I] = C; return true; } // Disable SROA in the face of arbitrary casts we don't whitelist elsewhere. disableSROA(I.getOperand(0)); return TargetTransformInfo::TCC_Free == TTI.getUserCost(&I); }
void Interpreter::visitCastInst(CastInst &I) { ExecutionContext &SF = ECStack.back(); SetValue(&I, executeCastOperation(I.getOperand(0), I.getType(), SF), SF); }