[flang-commits] [clang-tools-extra] [libclc] [libcxxabi] [clang] [lld] [lldb] [flang] [libc] [llvm] [libcxx] [compiler-rt] [VPlan] Add new VPUniformPerUFRecipe, use for step truncation. (PR #78113)

via flang-commits flang-commits at lists.llvm.org
Wed Jan 24 15:08:55 PST 2024


================
@@ -498,10 +498,34 @@ static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
   Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
   VPValue *BaseIV = CanonicalIV;
----------------
ayalz wrote:

Can we first check if Start and Step are canonical, regardless of types, in order to introduce a VPDerivedIVRecipe, i.e., remove the last Type parameter from isCanonical():

```
  VPSingleDefRecipe *BaseIV = CanonicalIV;

  // If the induction needs transforming besides truncating, create a
  // VPDerivedIVRecipe.
  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
    BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
    HeaderVPBB->insert(BaseIV, IP);
  }
```

then check if BaseIV needs to be truncated:

```
  VPTypeAnalysis TypeInfo(SE.getContext());
  Type *BaseIVTy = TypeInfo.inferScalarType(BaseIV);
  if (TruncI && TruncI->getType() != BaseIVTy) {
    Type *TruncTy = TruncI->getType();
    assert(BaseIVTy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits() &&
             BaseIVTy->isIntegerTy() && "Truncation requires an integer step");
    BaseIV = new VPScalarCastRecipe(Instruction::Trunc, BaseIV, TruncTy);
    BaseIVTy = TruncTy;
    HeaderVPBB->insert(BaseIV, IP);
  }
```
  
and finally check if Step needs to be truncated:

```
  Type *StepTy = TypeInfo.inferScalarType(Step);
  if (BaseIVTy != StepTy) {
    assert(StepTy->getScalarSizeInBits() > BaseIVTy->getScalarSizeInBits() &&
           StepTy->isIntegerTy() && "Not truncating.");
    Step = new VPScalarCastRecipe(Instruction::Trunc, Step, BaseIVTy);
    auto *VecPreheader =
        cast<VPBasicBlock>(Plan.getVectorLoopRegion()->getSinglePredecessor());
    VecPreheader->appendRecipe(Step->getDefiningRecipe());
  }
```
before creating, inserting and returning `Steps`? Is `IVTy` needed?

https://github.com/llvm/llvm-project/pull/78113


More information about the flang-commits mailing list