[llvm] [LV] Avoid querying the cost of invalid operations (PR #89161)

Kolya Panchenko via llvm-commits llvm-commits at lists.llvm.org
Mon May 6 07:19:55 PDT 2024


================
@@ -7067,6 +7067,10 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, ElementCount VF,
         SrcVecTy = smallestIntegerVectorType(SrcVecTy, MinVecTy);
         VectorTy =
             largestIntegerVectorType(ToVectorTy(I->getType(), VF), MinVecTy);
----------------
nikolaypanchenko wrote:

Even if `canTruncateToMinimalBitwidth` is true, the destination type should be no smaller than source type for `TruncInst`. The other easiest way to verify that `SrcVecTy` and `VectorTy` should be swapped is by running existing littest with assert when  `SrcVecTy > VectorTy`: 
```
llvm/test/Transforms/LoopVectorize/trunc-reductions.ll:

opt -passes=loop-vectorize,dce,instcombine -force-vector-interleave=1 -force-vector-width=8

Trunc: SrcVecTy = <8 x i1>      VectorTy = <8 x i16>
```
If predicate is reversed, there is not going to fail.
Other part of the code: VPlan construction and generation are done correctly, so no wonder it was not discovered before.

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


More information about the llvm-commits mailing list