Unverified Commit aacaf3d5 authored by Florian Hahn's avatar Florian Hahn
Browse files

[VPlan] Simplify VPDerivedIV truncation handling (NFCI).

Address post-commit simplification suggestion for 8a56179b: Replace
IsTruncated by conditionally setting TruncResultTy only if truncation
is required.
parent 16888689
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -9488,10 +9488,11 @@ void VPDerivedIVRecipe::execute(VPTransformState &State) {
                                          getStartValue()->getLiveInIRValue(),
                                          Step, Kind, BinOp);
  DerivedIV->setName("offset.idx");
  if (ResultTy != DerivedIV->getType()) {
    assert(IsTruncated && Step->getType()->isIntegerTy() &&
  if (TruncResultTy) {
    assert(TruncResultTy != DerivedIV->getType() &&
           Step->getType()->isIntegerTy() &&
           "Truncation requires an integer step");
    DerivedIV = State.Builder.CreateTrunc(DerivedIV, ResultTy);
    DerivedIV = State.Builder.CreateTrunc(DerivedIV, TruncResultTy);
  }
  assert(DerivedIV != CanonicalIV && "IV didn't need transforming?");

+7 −10
Original line number Diff line number Diff line
@@ -2139,24 +2139,21 @@ public:
/// an IV with different start and step values, using Start + CanonicalIV *
/// Step.
class VPDerivedIVRecipe : public VPRecipeBase, public VPValue {
  /// The type of the result value. It may be smaller than the type of the
  /// induction and in this case it will get truncated to ResultTy.
  Type *ResultTy;

  bool IsTruncated;
  /// If not nullptr, the result of the induction will get truncated to
  /// TruncResultTy.
  Type *TruncResultTy;

  /// Induction descriptor for the induction the canonical IV is transformed to.
  /// Kind and binary operator of the induction.
  const InductionDescriptor::InductionKind Kind;
  const BinaryOperator *BinOp;

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

  ~VPDerivedIVRecipe() override = default;

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

  if (IsTruncated)
    O << " (truncated to " << *ResultTy << ")";
  if (TruncResultTy)
    O << " (truncated to " << *TruncResultTy << ")";
}
#endif

+2 −1
Original line number Diff line number Diff line
@@ -511,7 +511,8 @@ static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
  VPValue *BaseIV = CanonicalIV;
  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
    BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step, TruncTy);
    BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
                                   TruncI ? TruncI->getType() : nullptr);
    HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
  }