[llvm] [LV] fix logical error in trunc cost (PR #91136)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 05:02:40 PDT 2024


================
@@ -7123,16 +7117,15 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, ElementCount VF,
       // "zext i8 %1 to i32" becomes "zext i8 %1 to i16".
       //
       // Calculate the modified src and dest types.
-      Type *MinVecTy = VectorTy;
       if (Opcode == Instruction::Trunc) {
-        SrcVecTy = smallestIntegerVectorType(SrcVecTy, MinVecTy);
+        SrcVecTy = smallestIntegerVectorType(SrcVecTy, VectorTy);
         VectorTy =
-            largestIntegerVectorType(ToVectorTy(I->getType(), VF), MinVecTy);
+            smallestIntegerVectorType(ToVectorTy(I->getType(), VF), VectorTy);
----------------
fhahn wrote:

Ah yes. looking at this agin, we should be able to compute the accurate type for the source (by also checking if `Src` is truncated and if it is retrieving the it's width from `MinBW`)?


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


More information about the llvm-commits mailing list