diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp @@ -290,8 +290,24 @@ switch (ISD) { case ISD::SIGN_EXTEND: case ISD::ZERO_EXTEND: + if (Src->getScalarSizeInBits() == 1) { + // We do not use vsext/vzext to extend from mask vector. + // Instead we use the following instructions to extend from mask vector: + // vmv.v.i v8, 0 + // vmerge.vim v8, v8, -1, v0 + return 2; + } return 1; case ISD::TRUNCATE: + if (Dst->getScalarSizeInBits() == 1) { + // We do not use several vncvt to truncate to mask vector. So we could + // not use PowDiff to calculate it. + // Instead we use the following instructions to truncate to mask vector: + // vand.vi v8, v8, 1 + // vmsne.vi v0, v8, 0 + return 2; + } + [[fallthrough]]; case ISD::FP_EXTEND: case ISD::FP_ROUND: // Counts of narrow/widen instructions. diff --git a/llvm/test/Analysis/CostModel/RISCV/cast.ll b/llvm/test/Analysis/CostModel/RISCV/cast.ll --- a/llvm/test/Analysis/CostModel/RISCV/cast.ll +++ b/llvm/test/Analysis/CostModel/RISCV/cast.ll @@ -16,6 +16,14 @@ ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %z4i16i64 = zext <4 x i16> undef to <4 x i64> ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s4i32i64 = sext <4 x i32> undef to <4 x i64> ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %z4i32i64 = zext <4 x i32> undef to <4 x i64> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i8 = sext <4 x i1> undef to <4 x i8> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z4i1i8 = zext <4 x i1> undef to <4 x i8> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i16 = sext <4 x i1> undef to <4 x i16> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z4i1i16 = zext <4 x i1> undef to <4 x i16> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i32 = sext <4 x i1> undef to <4 x i32> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z4i1i32 = zext <4 x i1> undef to <4 x i32> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i64 = sext <4 x i1> undef to <4 x i64> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z4i1i64 = zext <4 x i1> undef to <4 x i64> ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s8i8i16 = sext <8 x i8> undef to <8 x i16> ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %z8i8i16 = zext <8 x i8> undef to <8 x i16> ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s8i8i32 = sext <8 x i8> undef to <8 x i32> @@ -26,6 +34,14 @@ ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %z8i16i32 = zext <8 x i16> undef to <8 x i32> ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s8i16i64 = sext <8 x i16> undef to <8 x i64> ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %z8i16i64 = zext <8 x i16> undef to <8 x i64> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s8i1i8 = sext <8 x i1> undef to <8 x i8> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z8i1i8 = zext <8 x i1> undef to <8 x i8> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s8i1i16 = sext <8 x i1> undef to <8 x i16> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z8i1i16 = zext <8 x i1> undef to <8 x i16> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s8i1i32 = sext <8 x i1> undef to <8 x i32> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z8i1i32 = zext <8 x i1> undef to <8 x i32> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s8i1i64 = sext <8 x i1> undef to <8 x i64> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z8i1i64 = zext <8 x i1> undef to <8 x i64> ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void ; ; RISCV64-LABEL: 'ext' @@ -41,6 +57,14 @@ ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %z4i16i64 = zext <4 x i16> undef to <4 x i64> ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s4i32i64 = sext <4 x i32> undef to <4 x i64> ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %z4i32i64 = zext <4 x i32> undef to <4 x i64> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i8 = sext <4 x i1> undef to <4 x i8> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z4i1i8 = zext <4 x i1> undef to <4 x i8> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i16 = sext <4 x i1> undef to <4 x i16> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z4i1i16 = zext <4 x i1> undef to <4 x i16> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i32 = sext <4 x i1> undef to <4 x i32> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z4i1i32 = zext <4 x i1> undef to <4 x i32> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i64 = sext <4 x i1> undef to <4 x i64> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z4i1i64 = zext <4 x i1> undef to <4 x i64> ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s8i8i16 = sext <8 x i8> undef to <8 x i16> ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %z8i8i16 = zext <8 x i8> undef to <8 x i16> ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s8i8i32 = sext <8 x i8> undef to <8 x i32> @@ -51,6 +75,14 @@ ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %z8i16i32 = zext <8 x i16> undef to <8 x i32> ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s8i16i64 = sext <8 x i16> undef to <8 x i64> ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %z8i16i64 = zext <8 x i16> undef to <8 x i64> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s8i1i8 = sext <8 x i1> undef to <8 x i8> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z8i1i8 = zext <8 x i1> undef to <8 x i8> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s8i1i16 = sext <8 x i1> undef to <8 x i16> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z8i1i16 = zext <8 x i1> undef to <8 x i16> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s8i1i32 = sext <8 x i1> undef to <8 x i32> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z8i1i32 = zext <8 x i1> undef to <8 x i32> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s8i1i64 = sext <8 x i1> undef to <8 x i64> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %z8i1i64 = zext <8 x i1> undef to <8 x i64> ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void ; %s4i8i16 = sext <4 x i8> undef to <4 x i16> @@ -65,6 +97,14 @@ %z4i16i64 = zext <4 x i16> undef to <4 x i64> %s4i32i64 = sext <4 x i32> undef to <4 x i64> %z4i32i64 = zext <4 x i32> undef to <4 x i64> + %s4i1i8 = sext <4 x i1> undef to <4 x i8> + %z4i1i8 = zext <4 x i1> undef to <4 x i8> + %s4i1i16 = sext <4 x i1> undef to <4 x i16> + %z4i1i16 = zext <4 x i1> undef to <4 x i16> + %s4i1i32 = sext <4 x i1> undef to <4 x i32> + %z4i1i32 = zext <4 x i1> undef to <4 x i32> + %s4i1i64 = sext <4 x i1> undef to <4 x i64> + %z4i1i64 = zext <4 x i1> undef to <4 x i64> %s8i8i16 = sext <8 x i8> undef to <8 x i16> %z8i8i16 = zext <8 x i8> undef to <8 x i16> @@ -76,6 +116,14 @@ %z8i16i32 = zext <8 x i16> undef to <8 x i32> %s8i16i64 = sext <8 x i16> undef to <8 x i64> %z8i16i64 = zext <8 x i16> undef to <8 x i64> + %s8i1i8 = sext <8 x i1> undef to <8 x i8> + %z8i1i8 = zext <8 x i1> undef to <8 x i8> + %s8i1i16 = sext <8 x i1> undef to <8 x i16> + %z8i1i16 = zext <8 x i1> undef to <8 x i16> + %s8i1i32 = sext <8 x i1> undef to <8 x i32> + %z8i1i32 = zext <8 x i1> undef to <8 x i32> + %s8i1i64 = sext <8 x i1> undef to <8 x i64> + %z8i1i64 = zext <8 x i1> undef to <8 x i64> ret void } @@ -87,6 +135,10 @@ ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s4i16i32 = trunc <4 x i32> undef to <4 x i16> ; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i16i64 = trunc <4 x i64> undef to <4 x i16> ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s4i32i64 = trunc <4 x i64> undef to <4 x i32> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i8 = trunc <4 x i8> undef to <4 x i1> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i16 = trunc <4 x i16> undef to <4 x i1> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i32 = trunc <4 x i32> undef to <4 x i1> +; RISCV32-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i64 = trunc <4 x i64> undef to <4 x i1> ; RISCV32-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void ; ; RISCV64-LABEL: 'trunc' @@ -96,6 +148,10 @@ ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s4i16i32 = trunc <4 x i32> undef to <4 x i16> ; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i16i64 = trunc <4 x i64> undef to <4 x i16> ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s4i32i64 = trunc <4 x i64> undef to <4 x i32> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i8 = trunc <4 x i8> undef to <4 x i1> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i16 = trunc <4 x i16> undef to <4 x i1> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i32 = trunc <4 x i32> undef to <4 x i1> +; RISCV64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %s4i1i64 = trunc <4 x i64> undef to <4 x i1> ; RISCV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void ; %s4i8i16 = trunc <4 x i16> undef to <4 x i8> @@ -104,6 +160,10 @@ %s4i16i32 = trunc <4 x i32> undef to <4 x i16> %s4i16i64 = trunc <4 x i64> undef to <4 x i16> %s4i32i64 = trunc <4 x i64> undef to <4 x i32> + %s4i1i8 = trunc <4 x i8> undef to <4 x i1> + %s4i1i16 = trunc <4 x i16> undef to <4 x i1> + %s4i1i32 = trunc <4 x i32> undef to <4 x i1> + %s4i1i64 = trunc <4 x i64> undef to <4 x i1> ret void }