Unverified Commit 8a56179b authored by Florian Hahn's avatar Florian Hahn
Browse files

[VPlan] Store induction kind & binop directly in VPDerviedIVRecipe(NFC)

Limit the information stored in VPDerivedIVRecipe to the ingredients
really needed.
parent dea33c80
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -2386,7 +2386,7 @@ static Value *
emitTransformedIndex(IRBuilderBase &B, Value *Index, Value *StartValue,
                     Value *Step,
                     InductionDescriptor::InductionKind InductionKind,
                     BinaryOperator *InductionBinOp) {
                     const BinaryOperator *InductionBinOp) {
  Type *StepTy = Step->getType();
  Value *CastedIndex = StepTy->isIntegerTy()
                           ? B.CreateSExtOrTrunc(Index, StepTy)
@@ -9479,19 +9479,17 @@ void VPDerivedIVRecipe::execute(VPTransformState &State) {

  // Fast-math-flags propagate from the original induction instruction.
  IRBuilder<>::FastMathFlagGuard FMFG(State.Builder);
  if (IndDesc.getInductionBinOp() &&
      isa<FPMathOperator>(IndDesc.getInductionBinOp()))
    State.Builder.setFastMathFlags(
        IndDesc.getInductionBinOp()->getFastMathFlags());
  if (BinOp && isa<FPMathOperator>(BinOp))
    State.Builder.setFastMathFlags(BinOp->getFastMathFlags());

  Value *Step = State.get(getStepValue(), VPIteration(0, 0));
  Value *CanonicalIV = State.get(getCanonicalIV(), VPIteration(0, 0));
  Value *DerivedIV = emitTransformedIndex(
      State.Builder, CanonicalIV, getStartValue()->getLiveInIRValue(), Step,
      IndDesc.getKind(), IndDesc.getInductionBinOp());
  Value *DerivedIV = emitTransformedIndex(State.Builder, CanonicalIV,
                                          getStartValue()->getLiveInIRValue(),
                                          Step, Kind, BinOp);
  DerivedIV->setName("offset.idx");
  if (ResultTy != DerivedIV->getType()) {
    assert(Step->getType()->isIntegerTy() &&
    assert(IsTruncated && Step->getType()->isIntegerTy() &&
           "Truncation requires an integer step");
    DerivedIV = State.Builder.CreateTrunc(DerivedIV, ResultTy);
  }
+7 −2
Original line number Diff line number Diff line
@@ -2143,15 +2143,20 @@ class VPDerivedIVRecipe : public VPRecipeBase, public VPValue {
  /// induction and in this case it will get truncated to ResultTy.
  Type *ResultTy;

  bool IsTruncated;

  /// Induction descriptor for the induction the canonical IV is transformed to.
  const InductionDescriptor &IndDesc;
  const InductionDescriptor::InductionKind Kind;
  const BinaryOperator *BinOp;

public:
  VPDerivedIVRecipe(const InductionDescriptor &IndDesc, VPValue *Start,
                    VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step,
                    Type *ResultTy)
      : VPRecipeBase(VPDef::VPDerivedIVSC, {Start, CanonicalIV, Step}),
        VPValue(this), ResultTy(ResultTy), IndDesc(IndDesc) {}
        VPValue(this), ResultTy(ResultTy),
        IsTruncated(IndDesc.getStep()->getType() != ResultTy),
        Kind(IndDesc.getKind()), BinOp(IndDesc.getInductionBinOp()) {}

  ~VPDerivedIVRecipe() override = default;

+1 −1
Original line number Diff line number Diff line
@@ -797,7 +797,7 @@ void VPDerivedIVRecipe::print(raw_ostream &O, const Twine &Indent,
  O << " * ";
  getStepValue()->printAsOperand(O, SlotTracker);

  if (IndDesc.getStep()->getType() != ResultTy)
  if (IsTruncated)
    O << " (truncated to " << *ResultTy << ")";
}
#endif