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); }
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); }
bool Scalarizer::visitCastInst(CastInst &CI) { VectorType *VT = dyn_cast<VectorType>(CI.getDestTy()); if (!VT) return false; unsigned NumElems = VT->getNumElements(); IRBuilder<> Builder(CI.getParent(), &CI); Scatterer Op0 = scatter(&CI, CI.getOperand(0)); assert(Op0.size() == NumElems && "Mismatched cast"); ValueVector Res; Res.resize(NumElems); for (unsigned I = 0; I < NumElems; ++I) Res[I] = Builder.CreateCast(CI.getOpcode(), Op0[I], VT->getElementType(), CI.getName() + ".i" + Twine(I)); gather(&CI, Res); return true; }