From e13d04138e307d6af58f6efa418cd3758916bdca Mon Sep 17 00:00:00 2001 From: Michael Maitland Date: Fri, 22 Sep 2023 11:26:28 -0700 Subject: [PATCH 1/7] [RISCV][CostModel] Precommit RISCV cost model tests for VPIntrinsics On RISCV, only a few VPIntrinsics have their cost modeled by the VectorIntrinsicCostTable. Even so, none of those entries consider LMUL. All other VPIntrinsics do not have meaningful modeling. --- .../CostModel/RISCV/rvv-intrinsics.ll | 370 +++++++++++++++++- 1 file changed, 369 insertions(+), 1 deletion(-) diff --git a/llvm/test/Analysis/CostModel/RISCV/rvv-intrinsics.ll b/llvm/test/Analysis/CostModel/RISCV/rvv-intrinsics.ll index 93de623cf1c6da..cedb87395495fc 100644 --- a/llvm/test/Analysis/CostModel/RISCV/rvv-intrinsics.ll +++ b/llvm/test/Analysis/CostModel/RISCV/rvv-intrinsics.ll @@ -206,10 +206,378 @@ define void @vp_fshl() { ret void } +define void @add() { +; CHECK-LABEL: 'add' +; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %t0 = call <2 x i8> @llvm.vp.add.v2i8(<2 x i8> undef, <2 x i8> undef, <2 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t1 = add <2 x i8> undef, undef +; CHECK-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %t2 = call <4 x i8> @llvm.vp.add.v4i8(<4 x i8> undef, <4 x i8> undef, <4 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t3 = add <4 x i8> undef, undef +; CHECK-NEXT: Cost Model: Found an estimated cost of 23 for instruction: %t4 = call <8 x i8> @llvm.vp.add.v8i8(<8 x i8> undef, <8 x i8> undef, <8 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t5 = add <8 x i8> undef, undef +; CHECK-NEXT: Cost Model: Found an estimated cost of 47 for instruction: %t6 = call <16 x i8> @llvm.vp.add.v16i8(<16 x i8> undef, <16 x i8> undef, <16 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t7 = add <16 x i8> undef, undef +; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %t8 = call <2 x i64> @llvm.vp.add.v2i64(<2 x i64> undef, <2 x i64> undef, <2 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t9 = add <2 x i64> undef, undef +; CHECK-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %t10 = call <4 x i64> @llvm.vp.add.v4i64(<4 x i64> undef, <4 x i64> undef, <4 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t12 = add <4 x i64> undef, undef +; CHECK-NEXT: Cost Model: Found an estimated cost of 23 for instruction: %t13 = call <8 x i64> @llvm.vp.add.v8i64(<8 x i64> undef, <8 x i64> undef, <8 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %t14 = add <8 x i64> undef, undef +; CHECK-NEXT: Cost Model: Found an estimated cost of 47 for instruction: %t15 = call <16 x i64> @llvm.vp.add.v16i64(<16 x i64> undef, <16 x i64> undef, <16 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %t16 = add <16 x i64> undef, undef +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t17 = call @llvm.vp.add.nxv2i8( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t18 = add undef, undef +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t19 = call @llvm.vp.add.nxv4i8( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t20 = add undef, undef +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t21 = call @llvm.vp.add.nxv8i8( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t22 = add undef, undef +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t23 = call @llvm.vp.add.nxv16i8( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t24 = add undef, undef +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t25 = call @llvm.vp.add.nxv2i64( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t26 = add undef, undef +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t27 = call @llvm.vp.add.nxv4i64( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %t28 = add undef, undef +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t29 = call @llvm.vp.add.nxv8i64( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %t30 = add undef, undef +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t31 = call @llvm.vp.add.nxv16i64( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %t32 = add undef, undef +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; + %t0 = call <2 x i8> @llvm.vp.add.v2i8(<2 x i8> undef, <2 x i8> undef, <2 x i1> undef, i32 undef) + %t1 = add <2 x i8> undef, undef + %t2 = call <4 x i8> @llvm.vp.add.v4i8(<4 x i8> undef, <4 x i8> undef, <4 x i1> undef, i32 undef) + %t3 = add <4 x i8> undef, undef + %t4 = call <8 x i8> @llvm.vp.add.v8i8(<8 x i8> undef, <8 x i8> undef, <8 x i1> undef, i32 undef) + %t5 = add <8 x i8> undef, undef + %t6 = call <16 x i8> @llvm.vp.add.v16i8(<16 x i8> undef, <16 x i8> undef, <16 x i1> undef, i32 undef) + %t7 = add <16 x i8> undef, undef + %t8 = call <2 x i64> @llvm.vp.add.v2i64(<2 x i64> undef, <2 x i64> undef, <2 x i1> undef, i32 undef) + %t9 = add <2 x i64> undef, undef + %t10 = call <4 x i64> @llvm.vp.add.v4i64(<4 x i64> undef, <4 x i64> undef, <4 x i1> undef, i32 undef) + %t12 = add <4 x i64> undef, undef + %t13 = call <8 x i64> @llvm.vp.add.v8i64(<8 x i64> undef, <8 x i64> undef, <8 x i1> undef, i32 undef) + %t14 = add <8 x i64> undef, undef + %t15 = call <16 x i64> @llvm.vp.add.v16i64(<16 x i64> undef, <16 x i64> undef, <16 x i1> undef, i32 undef) + %t16 = add <16 x i64> undef, undef + %t17 = call @llvm.vp.add.nv2i8( undef, undef, undef, i32 undef) + %t18 = add undef, undef + %t19 = call @llvm.vp.add.nv4i8( undef, undef, undef, i32 undef) + %t20 = add undef, undef + %t21 = call @llvm.vp.add.nv8i8( undef, undef, undef, i32 undef) + %t22 = add undef, undef + %t23 = call @llvm.vp.add.nv16i8( undef, undef, undef, i32 undef) + %t24 = add undef, undef + %t25 = call @llvm.vp.add.nv2i64( undef, undef, undef, i32 undef) + %t26 = add undef, undef + %t27 = call @llvm.vp.add.nv4i64( undef, undef, undef, i32 undef) + %t28 = add undef, undef + %t29 = call @llvm.vp.add.nv8i64( undef, undef, undef, i32 undef) + %t30 = add undef, undef + %t31 = call @llvm.vp.add.nv16i64( undef, undef, undef, i32 undef) + %t32 = add undef, undef + ret void +} + +define void @abs() { +; CHECK-LABEL: 'abs' +; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %1 = call <2 x i8> @llvm.vp.abs.v2i8(<2 x i8> undef, i1 false, <2 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %2 = call <2 x i8> @llvm.abs.v2i8(<2 x i8> undef, i1 false) +; CHECK-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %3 = call <4 x i8> @llvm.vp.abs.v4i8(<4 x i8> undef, i1 false, <4 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %4 = call <4 x i8> @llvm.abs.v4i8(<4 x i8> undef, i1 false) +; CHECK-NEXT: Cost Model: Found an estimated cost of 23 for instruction: %5 = call <8 x i8> @llvm.vp.abs.v8i8(<8 x i8> undef, i1 false, <8 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %6 = call <8 x i8> @llvm.abs.v8i8(<8 x i8> undef, i1 false) +; CHECK-NEXT: Cost Model: Found an estimated cost of 47 for instruction: %7 = call <16 x i8> @llvm.vp.abs.v16i8(<16 x i8> undef, i1 false, <16 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %8 = call <16 x i8> @llvm.abs.v16i8(<16 x i8> undef, i1 false) +; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %9 = call <2 x i64> @llvm.vp.abs.v2i64(<2 x i64> undef, i1 false, <2 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %10 = call <2 x i64> @llvm.abs.v2i64(<2 x i64> undef, i1 false) +; CHECK-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %11 = call <4 x i64> @llvm.vp.abs.v4i64(<4 x i64> undef, i1 false, <4 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %12 = call <4 x i64> @llvm.abs.v4i64(<4 x i64> undef, i1 false) +; CHECK-NEXT: Cost Model: Found an estimated cost of 23 for instruction: %13 = call <8 x i64> @llvm.vp.abs.v8i64(<8 x i64> undef, i1 false, <8 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %14 = call <8 x i64> @llvm.abs.v8i64(<8 x i64> undef, i1 false) +; CHECK-NEXT: Cost Model: Found an estimated cost of 47 for instruction: %15 = call <16 x i64> @llvm.vp.abs.v16i64(<16 x i64> undef, i1 false, <16 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %16 = call <16 x i64> @llvm.abs.v16i64(<16 x i64> undef, i1 false) +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %17 = call @llvm.vp.abs.nxv2i8( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %18 = call @llvm.abs.nxv2i8( undef, i1 false) +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %19 = call @llvm.vp.abs.nxv4i8( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %20 = call @llvm.abs.nxv4i8( undef, i1 false) +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %21 = call @llvm.vp.abs.nxv8i8( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %22 = call @llvm.abs.nxv8i8( undef, i1 false) +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %23 = call @llvm.vp.abs.nxv16i8( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %24 = call @llvm.abs.nxv16i8( undef, i1 false) +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %25 = call @llvm.vp.abs.nxv2i64( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %26 = call @llvm.abs.nxv2i64( undef, i1 false) +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %27 = call @llvm.vp.abs.nxv4i64( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %28 = call @llvm.abs.nxv4i64( undef, i1 false) +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %29 = call @llvm.vp.abs.nxv8i64( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %30 = call @llvm.abs.nxv8i64( undef, i1 false) +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %31 = call @llvm.vp.abs.nxv16i64( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %32 = call @llvm.abs.nxv16i64( undef, i1 false) +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; + call <2 x i8> @llvm.vp.abs.v2i8(<2 x i8> undef, i1 0, <2 x i1> undef, i32 undef) + call <2 x i8> @llvm.abs.v2i8(<2 x i8> undef, i1 0) + call <4 x i8> @llvm.vp.abs.v4i8(<4 x i8> undef, i1 0, <4 x i1> undef, i32 undef) + call <4 x i8> @llvm.abs.v4i8(<4 x i8> undef, i1 0) + call <8 x i8> @llvm.vp.abs.v8i8(<8 x i8> undef, i1 0, <8 x i1> undef, i32 undef) + call <8 x i8> @llvm.abs.v8i8(<8 x i8> undef, i1 0) + call <16 x i8> @llvm.vp.abs.v16i8(<16 x i8> undef, i1 0, <16 x i1> undef, i32 undef) + call <16 x i8> @llvm.abs.v16i8(<16 x i8> undef, i1 0) + call <2 x i64> @llvm.vp.abs.v2i64(<2 x i64> undef, i1 0, <2 x i1> undef, i32 undef) + call <2 x i64> @llvm.abs.v2i64(<2 x i64> undef, i1 0) + call <4 x i64> @llvm.vp.abs.v4i64(<4 x i64> undef, i1 0, <4 x i1> undef, i32 undef) + call <4 x i64> @llvm.abs.v4i64(<4 x i64> undef, i1 0) + call <8 x i64> @llvm.vp.abs.v8i64(<8 x i64> undef, i1 0, <8 x i1> undef, i32 undef) + call <8 x i64> @llvm.abs.v8i64(<8 x i64> undef, i1 0) + call <16 x i64> @llvm.vp.abs.v16i64(<16 x i64> undef, i1 0, <16 x i1> undef, i32 undef) + call <16 x i64> @llvm.abs.v16i64(<16 x i64> undef, i1 0) + call @llvm.vp.abs.nv2i8( undef, i1 0, undef, i32 undef) + call @llvm.abs.nv2i8( undef, i1 0) + call @llvm.vp.abs.nv4i8( undef, i1 0, undef, i32 undef) + call @llvm.abs.nv4i8( undef, i1 0) + call @llvm.vp.abs.nv8i8( undef, i1 0, undef, i32 undef) + call @llvm.abs.nv8i8( undef, i1 0) + call @llvm.vp.abs.nv16i8( undef, i1 0, undef, i32 undef) + call @llvm.abs.nv16i8( undef, i1 0) + call @llvm.vp.abs.nv2i64( undef, i1 0, undef, i32 undef) + call @llvm.abs.nv2i64( undef, i1 0) + call @llvm.vp.abs.nv4i64( undef, i1 0, undef, i32 undef) + call @llvm.abs.nv4i64( undef, i1 0) + call @llvm.vp.abs.nv8i64( undef, i1 0, undef, i32 undef) + call @llvm.abs.nv8i64( undef, i1 0) + call @llvm.vp.abs.nv16i64( undef, i1 0, undef, i32 undef) + call @llvm.abs.nv16i64( undef, i1 0) + ret void +} + +define void @load() { +; CHECK-LABEL: 'load' +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t0 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr undef, <2 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t1 = load <2 x i8>, ptr undef, align 2 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t2 = call <4 x i8> @llvm.vp.load.v4i8.p0(ptr undef, <4 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t3 = load <4 x i8>, ptr undef, align 4 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t4 = call <8 x i8> @llvm.vp.load.v8i8.p0(ptr undef, <8 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t5 = load <8 x i8>, ptr undef, align 8 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t6 = call <16 x i8> @llvm.vp.load.v16i8.p0(ptr undef, <16 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t7 = load <16 x i8>, ptr undef, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t8 = call <2 x i64> @llvm.vp.load.v2i64.p0(ptr undef, <2 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t9 = load <2 x i64>, ptr undef, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t10 = call <4 x i64> @llvm.vp.load.v4i64.p0(ptr undef, <4 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t12 = load <4 x i64>, ptr undef, align 32 +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %t13 = call <8 x i64> @llvm.vp.load.v8i64.p0(ptr undef, <8 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %t14 = load <8 x i64>, ptr undef, align 64 +; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %t15 = call <16 x i64> @llvm.vp.load.v16i64.p0(ptr undef, <16 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %t16 = load <16 x i64>, ptr undef, align 128 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t17 = call @llvm.vp.load.nxv2i8.p0(ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t18 = load , ptr undef, align 2 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t19 = call @llvm.vp.load.nxv4i8.p0(ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t20 = load , ptr undef, align 4 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t21 = call @llvm.vp.load.nxv8i8.p0(ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t22 = load , ptr undef, align 8 +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t23 = call @llvm.vp.load.nxv16i8.p0(ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t24 = load , ptr undef, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t25 = call @llvm.vp.load.nxv2i64.p0(ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t26 = load , ptr undef, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %t27 = call @llvm.vp.load.nxv4i64.p0(ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %t28 = load , ptr undef, align 32 +; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %t29 = call @llvm.vp.load.nxv8i64.p0(ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %t30 = load , ptr undef, align 64 +; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %t31 = call @llvm.vp.load.nxv16i64.p0(ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %t32 = load , ptr undef, align 128 +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; + %t0 = call <2 x i8> @llvm.vp.load.v2i8(ptr undef, <2 x i1> undef, i32 undef) + %t1 = load <2 x i8>, ptr undef + %t2 = call <4 x i8> @llvm.vp.load.v4i8(ptr undef, <4 x i1> undef, i32 undef) + %t3 = load <4 x i8>, ptr undef + %t4 = call <8 x i8> @llvm.vp.load.v8i8(ptr undef, <8 x i1> undef, i32 undef) + %t5 = load <8 x i8>, ptr undef + %t6 = call <16 x i8> @llvm.vp.load.v16i8(ptr undef, <16 x i1> undef, i32 undef) + %t7 = load <16 x i8>, ptr undef + %t8 = call <2 x i64> @llvm.vp.load.v2i64(ptr undef, <2 x i1> undef, i32 undef) + %t9 = load <2 x i64>, ptr undef + %t10 = call <4 x i64> @llvm.vp.load.v4i64(ptr undef, <4 x i1> undef, i32 undef) + %t12 = load <4 x i64>, ptr undef + %t13 = call <8 x i64> @llvm.vp.load.v8i64(ptr undef, <8 x i1> undef, i32 undef) + %t14 = load <8 x i64>, ptr undef + %t15 = call <16 x i64> @llvm.vp.load.v16i64(ptr undef, <16 x i1> undef, i32 undef) + %t16 = load <16 x i64>, ptr undef + %t17 = call @llvm.vp.load.nv2i8(ptr undef, undef, i32 undef) + %t18 = load , ptr undef + %t19 = call @llvm.vp.load.nv4i8(ptr undef, undef, i32 undef) + %t20 = load , ptr undef + %t21 = call @llvm.vp.load.nv8i8(ptr undef, undef, i32 undef) + %t22 = load , ptr undef + %t23 = call @llvm.vp.load.nv16i8(ptr undef, undef, i32 undef) + %t24 = load , ptr undef + %t25 = call @llvm.vp.load.nv2i64(ptr undef, undef, i32 undef) + %t26 = load , ptr undef + %t27 = call @llvm.vp.load.nv4i64(ptr undef, undef, i32 undef) + %t28 = load , ptr undef + %t29 = call @llvm.vp.load.nv8i64(ptr undef, undef, i32 undef) + %t30 = load , ptr undef + %t31 = call @llvm.vp.load.nv16i64(ptr undef, undef, i32 undef) + %t32 = load , ptr undef + ret void +} + +define void @store() { +; CHECK-LABEL: 'store' +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: call void @llvm.vp.store.v2i8.p0(<2 x i8> undef, ptr undef, <2 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store <2 x i8> undef, ptr undef, align 2 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: call void @llvm.vp.store.v4i8.p0(<4 x i8> undef, ptr undef, <4 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store <4 x i8> undef, ptr undef, align 4 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: call void @llvm.vp.store.v8i8.p0(<8 x i8> undef, ptr undef, <8 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store <8 x i8> undef, ptr undef, align 8 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: call void @llvm.vp.store.v16i8.p0(<16 x i8> undef, ptr undef, <16 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store <16 x i8> undef, ptr undef, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: call void @llvm.vp.store.v2i64.p0(<2 x i64> undef, ptr undef, <2 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store <2 x i64> undef, ptr undef, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: call void @llvm.vp.store.v4i64.p0(<4 x i64> undef, ptr undef, <4 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: store <4 x i64> undef, ptr undef, align 32 +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: call void @llvm.vp.store.v8i64.p0(<8 x i64> undef, ptr undef, <8 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: store <8 x i64> undef, ptr undef, align 64 +; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: call void @llvm.vp.store.v16i64.p0(<16 x i64> undef, ptr undef, <16 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: store <16 x i64> undef, ptr undef, align 128 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: call void @llvm.vp.store.nxv2i8.p0( undef, ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store undef, ptr undef, align 2 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: call void @llvm.vp.store.nxv4i8.p0( undef, ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store undef, ptr undef, align 4 +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: call void @llvm.vp.store.nxv8i8.p0( undef, ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store undef, ptr undef, align 8 +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: call void @llvm.vp.store.nxv16i8.p0( undef, ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: store undef, ptr undef, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: call void @llvm.vp.store.nxv2i64.p0( undef, ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: store undef, ptr undef, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: call void @llvm.vp.store.nxv4i64.p0( undef, ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: store undef, ptr undef, align 32 +; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: call void @llvm.vp.store.nxv8i64.p0( undef, ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: store undef, ptr undef, align 64 +; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: call void @llvm.vp.store.nxv16i64.p0( undef, ptr undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: store undef, ptr undef, align 128 +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void +; + call void @llvm.vp.store.v2i8(<2 x i8> undef, ptr undef, <2 x i1> undef, i32 undef) + store <2 x i8> undef, ptr undef + call void @llvm.vp.store.v4i8(<4 x i8> undef, ptr undef, <4 x i1> undef, i32 undef) + store <4 x i8> undef, ptr undef + call void @llvm.vp.store.v8i8(<8 x i8> undef, ptr undef, <8 x i1> undef, i32 undef) + store <8 x i8> undef, ptr undef + call void @llvm.vp.store.v16i8(<16 x i8> undef, ptr undef, <16 x i1> undef, i32 undef) + store <16 x i8> undef, ptr undef + call void @llvm.vp.store.v2i64(<2 x i64> undef, ptr undef, <2 x i1> undef, i32 undef) + store <2 x i64> undef, ptr undef + call void @llvm.vp.store.v4i64(<4 x i64> undef, ptr undef, <4 x i1> undef, i32 undef) + store <4 x i64> undef, ptr undef + call void @llvm.vp.store.v8i64(<8 x i64> undef, ptr undef, <8 x i1> undef, i32 undef) + store <8 x i64> undef, ptr undef + call void @llvm.vp.store.v16i64(<16 x i64> undef, ptr undef, <16 x i1> undef, i32 undef) + store <16 x i64> undef, ptr undef + call void @llvm.vp.store.nv2i8( undef, ptr undef, undef, i32 undef) + store undef, ptr undef + call void @llvm.vp.store.nv4i8( undef, ptr undef, undef, i32 undef) + store undef, ptr undef + call void @llvm.vp.store.nv8i8( undef, ptr undef, undef, i32 undef) + store undef, ptr undef + call void @llvm.vp.store.nv16i8( undef, ptr undef, undef, i32 undef) + store undef, ptr undef + call void @llvm.vp.store.nv2i64( undef, ptr undef, undef, i32 undef) + store undef, ptr undef + call void @llvm.vp.store.nv4i64( undef, ptr undef, undef, i32 undef) + store undef, ptr undef + call void @llvm.vp.store.nv8i64( undef, ptr undef, undef, i32 undef) + store undef, ptr undef + call void @llvm.vp.store.nv16i64( undef, ptr undef, undef, i32 undef) + store undef, ptr undef + ret void +} + +declare <2 x i8> @llvm.vp.add.v2i8(<2 x i8>, <2 x i8>, <2 x i1>, i32) +declare <4 x i8> @llvm.vp.add.v4i8(<4 x i8>, <4 x i8>, <4 x i1>, i32) +declare <8 x i8> @llvm.vp.add.v8i8(<8 x i8>, <8 x i8>, <8 x i1>, i32) +declare <16 x i8> @llvm.vp.add.v16i8(<16 x i8>, <16 x i8>, <16 x i1>, i32) +declare <2 x i64> @llvm.vp.add.v2i64(<2 x i64>, <2 x i64>, <2 x i1>, i32) +declare <4 x i64> @llvm.vp.add.v4i64(<4 x i64>, <4 x i64>, <4 x i1>, i32) +declare <8 x i64> @llvm.vp.add.v8i64(<8 x i64>, <8 x i64>, <8 x i1>, i32) +declare <16 x i64> @llvm.vp.add.v16i64(<16 x i64>, <16 x i64>, <16 x i1>, i32) +declare @llvm.vp.add.nv2i8(, , , i32) +declare @llvm.vp.add.nv4i8(, , , i32) +declare @llvm.vp.add.nv8i8(, , , i32) +declare @llvm.vp.add.nv16i8(, , , i32) +declare @llvm.vp.add.nv2i64(, , , i32) +declare @llvm.vp.add.nv4i64(, , , i32) +declare @llvm.vp.add.nv8i64(, , , i32) +declare @llvm.vp.add.nv16i64(, , , i32) + +declare <2 x i8> @llvm.vp.abs.v2i8(<2 x i8>, i1, <2 x i1>, i32) +declare <4 x i8> @llvm.vp.abs.v4i8(<4 x i8>, i1, <4 x i1>, i32) +declare <8 x i8> @llvm.vp.abs.v8i8(<8 x i8>, i1, <8 x i1>, i32) +declare <16 x i8> @llvm.vp.abs.v16i8(<16 x i8>, i1, <16 x i1>, i32) +declare <2 x i64> @llvm.vp.abs.v2i64(<2 x i64>, i1, <2 x i1>, i32) +declare <4 x i64> @llvm.vp.abs.v4i64(<4 x i64>, i1, <4 x i1>, i32) +declare <8 x i64> @llvm.vp.abs.v8i64(<8 x i64>, i1, <8 x i1>, i32) +declare <16 x i64> @llvm.vp.abs.v16i64(<16 x i64>, i1, <16 x i1>, i32) +declare @llvm.vp.abs.nv2i8(, i1, , i32) +declare @llvm.vp.abs.nv4i8(, i1, , i32) +declare @llvm.vp.abs.nv8i8(, i1, , i32) +declare @llvm.vp.abs.nv16i8(, i1, , i32) +declare @llvm.vp.abs.nv2i64(, i1, , i32) +declare @llvm.vp.abs.nv4i64(, i1, , i32) +declare @llvm.vp.abs.nv8i64(, i1, , i32) +declare @llvm.vp.abs.nv16i64(, i1, , i32) + +declare <2 x i8> @llvm.abs.v2i8(<2 x i8>, i1) +declare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1) +declare <8 x i8> @llvm.abs.v8i8(<8 x i8>, i1) +declare <16 x i8> @llvm.abs.v16i8(<16 x i8>, i1) +declare <2 x i64> @llvm.abs.v2i64(<2 x i64>, i1) +declare <4 x i64> @llvm.abs.v4i64(<4 x i64>, i1) +declare <8 x i64> @llvm.abs.v8i64(<8 x i64>, i1) +declare <16 x i64> @llvm.abs.v16i64(<16 x i64>, i1) +declare @llvm.abs.nv2i8(, i1) +declare @llvm.abs.nv4i8(, i1) +declare @llvm.abs.nv8i8(, i1) +declare @llvm.abs.nv16i8(, i1) +declare @llvm.abs.nv2i64(, i1) +declare @llvm.abs.nv4i64(, i1) +declare @llvm.abs.nv8i64(, i1) +declare @llvm.abs.nv16i64(, i1) + +declare <2 x i8> @llvm.vp.load.v2i8(ptr, <2 x i1>, i32) +declare <4 x i8> @llvm.vp.load.v4i8(ptr, <4 x i1>, i32) +declare <8 x i8> @llvm.vp.load.v8i8(ptr, <8 x i1>, i32) +declare <16 x i8> @llvm.vp.load.v16i8(ptr, <16 x i1>, i32) +declare <2 x i64> @llvm.vp.load.v2i64(ptr, <2 x i1>, i32) +declare <4 x i64> @llvm.vp.load.v4i64(ptr, <4 x i1>, i32) +declare <8 x i64> @llvm.vp.load.v8i64(ptr, <8 x i1>, i32) +declare <16 x i64> @llvm.vp.load.v16i64(ptr, <16 x i1>, i32) +declare @llvm.vp.load.nv2i8(ptr, , i32) +declare @llvm.vp.load.nv4i8(ptr, , i32) +declare @llvm.vp.load.nv8i8(ptr, , i32) +declare @llvm.vp.load.nv16i8(ptr, , i32) +declare @llvm.vp.load.nv2i64(ptr, , i32) +declare @llvm.vp.load.nv4i64(ptr, , i32) +declare @llvm.vp.load.nv8i64(ptr, , i32) +declare @llvm.vp.load.nv16i64(ptr, , i32) + +declare void @llvm.vp.store.v2i8(<2 x i8>, ptr, <2 x i1>, i32) +declare void @llvm.vp.store.v4i8(<4 x i8>, ptr, <4 x i1>, i32) +declare void @llvm.vp.store.v8i8(<8 x i8>, ptr, <8 x i1>, i32) +declare void @llvm.vp.store.v16i8(<16 x i8>, ptr, <16 x i1>, i32) +declare void @llvm.vp.store.v2i64(<2 x i64>, ptr, <2 x i1>, i32) +declare void @llvm.vp.store.v4i64(<4 x i64>, ptr, <4 x i1>, i32) +declare void @llvm.vp.store.v8i64(<8 x i64>, ptr, <8 x i1>, i32) +declare void @llvm.vp.store.v16i64(<16 x i64>, ptr, <16 x i1>, i32) +declare void @llvm.vp.store.nv2i8(, ptr, , i32) +declare void @llvm.vp.store.nv4i8(, ptr, , i32) +declare void @llvm.vp.store.nv8i8(, ptr, , i32) +declare void @llvm.vp.store.nv16i8(, ptr, , i32) +declare void @llvm.vp.store.nv2i64(, ptr, , i32) +declare void @llvm.vp.store.nv4i64(, ptr, , i32) +declare void @llvm.vp.store.nv8i64(, ptr, , i32) +declare void @llvm.vp.store.nv16i64(, ptr, , i32) + declare @llvm.fshr.nxv4i32( %a, %b, %c) declare @llvm.fshl.nxv4i32( %a, %b, %c) - declare @llvm.pow.nxv4f32(, ) declare @llvm.powi.nxv4f32.i32(, i32) declare @llvm.nearbyint.nxv4f32() From d5083088dbfb9f75c5b3482faf3fd0fe79aeaca0 Mon Sep 17 00:00:00 2001 From: Michael Maitland Date: Fri, 22 Sep 2023 11:30:23 -0700 Subject: [PATCH 2/7] [RISCV][CostModel] VPIntrinsics have same cost as their non-vp counterparts On RISCV, only a few VPIntrinsics have their cost modeled by the VectorIntrinsicCostTable. Even so, none of those entries consider LMUL. All other VPIntrinsics do not have meaningful modeling. This patch models the cost of a VPIntrinsic as the cost of its non-VP counterpart. It is possible that the VP Intrinsic is cheaper than the non-VP version depending on VL. On RISCV, this may be due two reasons (if the instruction is part of a loop): 1. A smaller VL can be used on the last iteration of the loop. 2. The VP instruction may avoid a scalar remainder loop. I have left this as a TODO since I think this change puts us on the right path of modeling the cost of a VPInstruction, and it isn't entierly clear to me how much of a discount we should give to a known VL { } } + // VP Intrinsics should have the same cost as their non-vp counterpart. + // TODO: Adjust the cost to make the vp intrinsic cheaper than its non-vp + // counterpart when the vector length argument is smaller than the maximum + // vector length. + if (VPIntrinsic::isVPIntrinsic(ICA.getID())) { + std::optional FOp = + VPIntrinsic::getFunctionalOpcodeForVP(ICA.getID()); + if (FOp) + return thisT()->getArithmeticInstrCost(*FOp, ICA.getReturnType(), + CostKind); + + std::optional FID = + VPIntrinsic::getFunctionalIntrinsicIDForVP(ICA.getID()); + if (FID) { + // Non-vp version will have same Args/Tys except mask and vector length. + ArrayRef NewArgs(ICA.getArgs().begin(), + ICA.getArgs().end() - 2); + ArrayRef NewTys(ICA.getArgTypes().begin(), + ICA.getArgTypes().end() - 2); + + IntrinsicCostAttributes NewICA(*FID, ICA.getReturnType(), NewArgs, + NewTys, ICA.getFlags(), ICA.getInst(), + ICA.getScalarizationCost()); + return thisT()->getIntrinsicInstrCost(NewICA, CostKind); + } + } + // Assume that we need to scalarize this intrinsic. // Compute the scalarization overhead based on Args for a vector // intrinsic. diff --git a/llvm/test/Analysis/CostModel/RISCV/gep.ll b/llvm/test/Analysis/CostModel/RISCV/gep.ll index be518faf7e0516..17be5c66327726 100644 --- a/llvm/test/Analysis/CostModel/RISCV/gep.ll +++ b/llvm/test/Analysis/CostModel/RISCV/gep.ll @@ -270,7 +270,7 @@ define void @non_foldable_vector_uses(ptr %base, <2 x ptr> %base.vec) { ; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %4 = getelementptr i8, ptr %base, i32 42 ; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x4 = call <2 x i8> @llvm.masked.expandload.v2i8(ptr %4, <2 x i1> undef, <2 x i8> undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %5 = getelementptr i8, ptr %base, i32 42 -; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x5 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr %5, <2 x i1> undef, i32 undef) +; RVI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %x5 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr %5, <2 x i1> undef, i32 undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %6 = getelementptr i8, ptr %base, i32 42 ; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x6 = call <2 x i8> @llvm.experimental.vp.strided.load.v2i8.p0.i64(ptr %6, i64 undef, <2 x i1> undef, i32 undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %7 = getelementptr i8, ptr %base, i32 42 @@ -282,7 +282,7 @@ define void @non_foldable_vector_uses(ptr %base, <2 x ptr> %base.vec) { ; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %10 = getelementptr i8, ptr %base, i32 42 ; RVI-NEXT: Cost Model: Found an estimated cost of 12 for instruction: call void @llvm.masked.compressstore.v2i8(<2 x i8> undef, ptr %10, <2 x i1> undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %11 = getelementptr i8, ptr %base, i32 42 -; RVI-NEXT: Cost Model: Found an estimated cost of 12 for instruction: call void @llvm.vp.store.v2i8.p0(<2 x i8> undef, ptr %11, <2 x i1> undef, i32 undef) +; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: call void @llvm.vp.store.v2i8.p0(<2 x i8> undef, ptr %11, <2 x i1> undef, i32 undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %12 = getelementptr i8, ptr %base, i32 42 ; RVI-NEXT: Cost Model: Found an estimated cost of 12 for instruction: call void @llvm.experimental.vp.strided.store.v2i8.p0.i64(<2 x i8> undef, ptr %12, i64 undef, <2 x i1> undef, i32 undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void @@ -340,7 +340,7 @@ define void @foldable_vector_uses(ptr %base, <2 x ptr> %base.vec) { ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %4 = getelementptr i8, ptr %base, i32 0 ; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x4 = call <2 x i8> @llvm.masked.expandload.v2i8(ptr %4, <2 x i1> undef, <2 x i8> undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %5 = getelementptr i8, ptr %base, i32 0 -; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x5 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr %5, <2 x i1> undef, i32 undef) +; RVI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %x5 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr %5, <2 x i1> undef, i32 undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %6 = getelementptr i8, ptr %base, i32 0 ; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x6 = call <2 x i8> @llvm.experimental.vp.strided.load.v2i8.p0.i64(ptr %6, i64 undef, <2 x i1> undef, i32 undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %7 = getelementptr i8, ptr %base, i32 0 @@ -352,7 +352,7 @@ define void @foldable_vector_uses(ptr %base, <2 x ptr> %base.vec) { ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %10 = getelementptr i8, ptr %base, i32 0 ; RVI-NEXT: Cost Model: Found an estimated cost of 12 for instruction: call void @llvm.masked.compressstore.v2i8(<2 x i8> undef, ptr %10, <2 x i1> undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %11 = getelementptr i8, ptr %base, i32 0 -; RVI-NEXT: Cost Model: Found an estimated cost of 12 for instruction: call void @llvm.vp.store.v2i8.p0(<2 x i8> undef, ptr %11, <2 x i1> undef, i32 undef) +; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: call void @llvm.vp.store.v2i8.p0(<2 x i8> undef, ptr %11, <2 x i1> undef, i32 undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %12 = getelementptr i8, ptr %base, i32 0 ; RVI-NEXT: Cost Model: Found an estimated cost of 12 for instruction: call void @llvm.experimental.vp.strided.store.v2i8.p0.i64(<2 x i8> undef, ptr %12, i64 undef, <2 x i1> undef, i32 undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void diff --git a/llvm/test/Analysis/CostModel/RISCV/rvv-intrinsics.ll b/llvm/test/Analysis/CostModel/RISCV/rvv-intrinsics.ll index cedb87395495fc..85364c935267d2 100644 --- a/llvm/test/Analysis/CostModel/RISCV/rvv-intrinsics.ll +++ b/llvm/test/Analysis/CostModel/RISCV/rvv-intrinsics.ll @@ -208,37 +208,37 @@ define void @vp_fshl() { define void @add() { ; CHECK-LABEL: 'add' -; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %t0 = call <2 x i8> @llvm.vp.add.v2i8(<2 x i8> undef, <2 x i8> undef, <2 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t0 = call <2 x i8> @llvm.vp.add.v2i8(<2 x i8> undef, <2 x i8> undef, <2 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t1 = add <2 x i8> undef, undef -; CHECK-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %t2 = call <4 x i8> @llvm.vp.add.v4i8(<4 x i8> undef, <4 x i8> undef, <4 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t2 = call <4 x i8> @llvm.vp.add.v4i8(<4 x i8> undef, <4 x i8> undef, <4 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t3 = add <4 x i8> undef, undef -; CHECK-NEXT: Cost Model: Found an estimated cost of 23 for instruction: %t4 = call <8 x i8> @llvm.vp.add.v8i8(<8 x i8> undef, <8 x i8> undef, <8 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t4 = call <8 x i8> @llvm.vp.add.v8i8(<8 x i8> undef, <8 x i8> undef, <8 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t5 = add <8 x i8> undef, undef -; CHECK-NEXT: Cost Model: Found an estimated cost of 47 for instruction: %t6 = call <16 x i8> @llvm.vp.add.v16i8(<16 x i8> undef, <16 x i8> undef, <16 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t6 = call <16 x i8> @llvm.vp.add.v16i8(<16 x i8> undef, <16 x i8> undef, <16 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t7 = add <16 x i8> undef, undef -; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %t8 = call <2 x i64> @llvm.vp.add.v2i64(<2 x i64> undef, <2 x i64> undef, <2 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t8 = call <2 x i64> @llvm.vp.add.v2i64(<2 x i64> undef, <2 x i64> undef, <2 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t9 = add <2 x i64> undef, undef -; CHECK-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %t10 = call <4 x i64> @llvm.vp.add.v4i64(<4 x i64> undef, <4 x i64> undef, <4 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t10 = call <4 x i64> @llvm.vp.add.v4i64(<4 x i64> undef, <4 x i64> undef, <4 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t12 = add <4 x i64> undef, undef -; CHECK-NEXT: Cost Model: Found an estimated cost of 23 for instruction: %t13 = call <8 x i64> @llvm.vp.add.v8i64(<8 x i64> undef, <8 x i64> undef, <8 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %t13 = call <8 x i64> @llvm.vp.add.v8i64(<8 x i64> undef, <8 x i64> undef, <8 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %t14 = add <8 x i64> undef, undef -; CHECK-NEXT: Cost Model: Found an estimated cost of 47 for instruction: %t15 = call <16 x i64> @llvm.vp.add.v16i64(<16 x i64> undef, <16 x i64> undef, <16 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %t15 = call <16 x i64> @llvm.vp.add.v16i64(<16 x i64> undef, <16 x i64> undef, <16 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %t16 = add <16 x i64> undef, undef -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t17 = call @llvm.vp.add.nxv2i8( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t17 = call @llvm.vp.add.nxv2i8( undef, undef, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t18 = add undef, undef -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t19 = call @llvm.vp.add.nxv4i8( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t19 = call @llvm.vp.add.nxv4i8( undef, undef, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t20 = add undef, undef -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t21 = call @llvm.vp.add.nxv8i8( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t21 = call @llvm.vp.add.nxv8i8( undef, undef, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %t22 = add undef, undef -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t23 = call @llvm.vp.add.nxv16i8( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t23 = call @llvm.vp.add.nxv16i8( undef, undef, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t24 = add undef, undef -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t25 = call @llvm.vp.add.nxv2i64( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t25 = call @llvm.vp.add.nxv2i64( undef, undef, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %t26 = add undef, undef -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t27 = call @llvm.vp.add.nxv4i64( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %t27 = call @llvm.vp.add.nxv4i64( undef, undef, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %t28 = add undef, undef -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t29 = call @llvm.vp.add.nxv8i64( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %t29 = call @llvm.vp.add.nxv8i64( undef, undef, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %t30 = add undef, undef -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %t31 = call @llvm.vp.add.nxv16i64( undef, undef, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %t31 = call @llvm.vp.add.nxv16i64( undef, undef, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %t32 = add undef, undef ; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void ; @@ -279,37 +279,37 @@ define void @add() { define void @abs() { ; CHECK-LABEL: 'abs' -; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %1 = call <2 x i8> @llvm.vp.abs.v2i8(<2 x i8> undef, i1 false, <2 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %1 = call <2 x i8> @llvm.vp.abs.v2i8(<2 x i8> undef, i1 false, <2 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %2 = call <2 x i8> @llvm.abs.v2i8(<2 x i8> undef, i1 false) -; CHECK-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %3 = call <4 x i8> @llvm.vp.abs.v4i8(<4 x i8> undef, i1 false, <4 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %3 = call <4 x i8> @llvm.vp.abs.v4i8(<4 x i8> undef, i1 false, <4 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %4 = call <4 x i8> @llvm.abs.v4i8(<4 x i8> undef, i1 false) -; CHECK-NEXT: Cost Model: Found an estimated cost of 23 for instruction: %5 = call <8 x i8> @llvm.vp.abs.v8i8(<8 x i8> undef, i1 false, <8 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %5 = call <8 x i8> @llvm.vp.abs.v8i8(<8 x i8> undef, i1 false, <8 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %6 = call <8 x i8> @llvm.abs.v8i8(<8 x i8> undef, i1 false) -; CHECK-NEXT: Cost Model: Found an estimated cost of 47 for instruction: %7 = call <16 x i8> @llvm.vp.abs.v16i8(<16 x i8> undef, i1 false, <16 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %7 = call <16 x i8> @llvm.vp.abs.v16i8(<16 x i8> undef, i1 false, <16 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %8 = call <16 x i8> @llvm.abs.v16i8(<16 x i8> undef, i1 false) -; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %9 = call <2 x i64> @llvm.vp.abs.v2i64(<2 x i64> undef, i1 false, <2 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %9 = call <2 x i64> @llvm.vp.abs.v2i64(<2 x i64> undef, i1 false, <2 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %10 = call <2 x i64> @llvm.abs.v2i64(<2 x i64> undef, i1 false) -; CHECK-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %11 = call <4 x i64> @llvm.vp.abs.v4i64(<4 x i64> undef, i1 false, <4 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %11 = call <4 x i64> @llvm.vp.abs.v4i64(<4 x i64> undef, i1 false, <4 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %12 = call <4 x i64> @llvm.abs.v4i64(<4 x i64> undef, i1 false) -; CHECK-NEXT: Cost Model: Found an estimated cost of 23 for instruction: %13 = call <8 x i64> @llvm.vp.abs.v8i64(<8 x i64> undef, i1 false, <8 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %13 = call <8 x i64> @llvm.vp.abs.v8i64(<8 x i64> undef, i1 false, <8 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %14 = call <8 x i64> @llvm.abs.v8i64(<8 x i64> undef, i1 false) -; CHECK-NEXT: Cost Model: Found an estimated cost of 47 for instruction: %15 = call <16 x i64> @llvm.vp.abs.v16i64(<16 x i64> undef, i1 false, <16 x i1> undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %15 = call <16 x i64> @llvm.vp.abs.v16i64(<16 x i64> undef, i1 false, <16 x i1> undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %16 = call <16 x i64> @llvm.abs.v16i64(<16 x i64> undef, i1 false) -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %17 = call @llvm.vp.abs.nxv2i8( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %17 = call @llvm.vp.abs.nxv2i8( undef, i1 false, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %18 = call @llvm.abs.nxv2i8( undef, i1 false) -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %19 = call @llvm.vp.abs.nxv4i8( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %19 = call @llvm.vp.abs.nxv4i8( undef, i1 false, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %20 = call @llvm.abs.nxv4i8( undef, i1 false) -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %21 = call @llvm.vp.abs.nxv8i8( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %21 = call @llvm.vp.abs.nxv8i8( undef, i1 false, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %22 = call @llvm.abs.nxv8i8( undef, i1 false) -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %23 = call @llvm.vp.abs.nxv16i8( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %23 = call @llvm.vp.abs.nxv16i8( undef, i1 false, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %24 = call @llvm.abs.nxv16i8( undef, i1 false) -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %25 = call @llvm.vp.abs.nxv2i64( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %25 = call @llvm.vp.abs.nxv2i64( undef, i1 false, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %26 = call @llvm.abs.nxv2i64( undef, i1 false) -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %27 = call @llvm.vp.abs.nxv4i64( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %27 = call @llvm.vp.abs.nxv4i64( undef, i1 false, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %28 = call @llvm.abs.nxv4i64( undef, i1 false) -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %29 = call @llvm.vp.abs.nxv8i64( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %29 = call @llvm.vp.abs.nxv8i64( undef, i1 false, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %30 = call @llvm.abs.nxv8i64( undef, i1 false) -; CHECK-NEXT: Cost Model: Invalid cost for instruction: %31 = call @llvm.vp.abs.nxv16i64( undef, i1 false, undef, i32 undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %31 = call @llvm.vp.abs.nxv16i64( undef, i1 false, undef, i32 undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %32 = call @llvm.abs.nxv16i64( undef, i1 false) ; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void ; From 99551af70a0cdf0518db559c2c2f37fea610921a Mon Sep 17 00:00:00 2001 From: Michael Maitland Date: Fri, 22 Sep 2023 14:15:34 -0700 Subject: [PATCH 3/7] Load/Store instructions should use getMemoryOpCost --- llvm/include/llvm/CodeGen/BasicTTIImpl.h | 33 +++++++++++++++++++++-- llvm/test/Analysis/CostModel/RISCV/gep.ll | 4 +-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h index 2160025c8108bd..e1a84144efb711 100644 --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -1692,11 +1692,40 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { // counterpart when the vector length argument is smaller than the maximum // vector length. if (VPIntrinsic::isVPIntrinsic(ICA.getID())) { - std::optional FOp = + std::optional FOp = VPIntrinsic::getFunctionalOpcodeForVP(ICA.getID()); - if (FOp) + if (FOp) { + if (ICA.getID() == Intrinsic::vp_load) { + Align Alignment = isa_and_nonnull(ICA.getInst()) + ? cast(ICA.getInst()) + ->getPointerAlignment() + .valueOrOne() + : Align(1); + unsigned AS = ICA.getArgs().size() >= 1 && + isa(ICA.getArgs()[0]->getType()) + ? cast(ICA.getArgs()[0]->getType()) + ->getAddressSpace() + : 0; + return thisT()->getMemoryOpCost(*FOp, ICA.getReturnType(), Alignment, + AS, CostKind); + } else if (ICA.getID() == Intrinsic::vp_store) { + Align Alignment = isa_and_nonnull(ICA.getInst()) + ? cast(ICA.getInst()) + ->getPointerAlignment() + .valueOrOne() + : Align(1); + unsigned AS = ICA.getArgs().size() >= 2 && + isa(ICA.getArgs()[1]->getType()) + ? cast(ICA.getArgs()[1]->getType()) + ->getAddressSpace() + : 0; + return thisT()->getMemoryOpCost(*FOp, Args[0]->getType(), Alignment, + AS, CostKind); + } + // TODO: Support other kinds of Intrinsics (i.e. reductions) return thisT()->getArithmeticInstrCost(*FOp, ICA.getReturnType(), CostKind); + } std::optional FID = VPIntrinsic::getFunctionalIntrinsicIDForVP(ICA.getID()); diff --git a/llvm/test/Analysis/CostModel/RISCV/gep.ll b/llvm/test/Analysis/CostModel/RISCV/gep.ll index 17be5c66327726..4fadf34c1973f8 100644 --- a/llvm/test/Analysis/CostModel/RISCV/gep.ll +++ b/llvm/test/Analysis/CostModel/RISCV/gep.ll @@ -270,7 +270,7 @@ define void @non_foldable_vector_uses(ptr %base, <2 x ptr> %base.vec) { ; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %4 = getelementptr i8, ptr %base, i32 42 ; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x4 = call <2 x i8> @llvm.masked.expandload.v2i8(ptr %4, <2 x i1> undef, <2 x i8> undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %5 = getelementptr i8, ptr %base, i32 42 -; RVI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %x5 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr %5, <2 x i1> undef, i32 undef) +; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %x5 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr %5, <2 x i1> undef, i32 undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %6 = getelementptr i8, ptr %base, i32 42 ; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x6 = call <2 x i8> @llvm.experimental.vp.strided.load.v2i8.p0.i64(ptr %6, i64 undef, <2 x i1> undef, i32 undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %7 = getelementptr i8, ptr %base, i32 42 @@ -340,7 +340,7 @@ define void @foldable_vector_uses(ptr %base, <2 x ptr> %base.vec) { ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %4 = getelementptr i8, ptr %base, i32 0 ; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x4 = call <2 x i8> @llvm.masked.expandload.v2i8(ptr %4, <2 x i1> undef, <2 x i8> undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %5 = getelementptr i8, ptr %base, i32 0 -; RVI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %x5 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr %5, <2 x i1> undef, i32 undef) +; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %x5 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr %5, <2 x i1> undef, i32 undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %6 = getelementptr i8, ptr %base, i32 0 ; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x6 = call <2 x i8> @llvm.experimental.vp.strided.load.v2i8.p0.i64(ptr %6, i64 undef, <2 x i1> undef, i32 undef) ; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %7 = getelementptr i8, ptr %base, i32 0 From dfc3bb52b53fdfd08f7d42cc63c01ba395ab28b5 Mon Sep 17 00:00:00 2001 From: Michael Maitland Date: Fri, 22 Sep 2023 15:03:37 -0700 Subject: [PATCH 4/7] Only do getArithmeticCost if its a binop --- llvm/include/llvm/CodeGen/BasicTTIImpl.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h index e1a84144efb711..06f6287dd415cb 100644 --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -1695,6 +1695,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { std::optional FOp = VPIntrinsic::getFunctionalOpcodeForVP(ICA.getID()); if (FOp) { + // TODO: Support other kinds of Intrinsics (i.e. reductions) if (ICA.getID() == Intrinsic::vp_load) { Align Alignment = isa_and_nonnull(ICA.getInst()) ? cast(ICA.getInst()) @@ -1721,10 +1722,10 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { : 0; return thisT()->getMemoryOpCost(*FOp, Args[0]->getType(), Alignment, AS, CostKind); + } else if (VPBinOpIntrinsic::isVPBinOp(ICA.getID())) { + return thisT()->getArithmeticInstrCost(*FOp, ICA.getReturnType(), + CostKind); } - // TODO: Support other kinds of Intrinsics (i.e. reductions) - return thisT()->getArithmeticInstrCost(*FOp, ICA.getReturnType(), - CostKind); } std::optional FID = From b1a51d64d85f9bea15c66ccf730eb4ca3bc9b155 Mon Sep 17 00:00:00 2001 From: Michael Maitland Date: Fri, 22 Sep 2023 16:08:07 -0700 Subject: [PATCH 5/7] Simplify Align and AS assignment --- llvm/include/llvm/CodeGen/BasicTTIImpl.h | 37 +++++++++++------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h index 06f6287dd415cb..fa4101155d157d 100644 --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -1697,29 +1697,23 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { if (FOp) { // TODO: Support other kinds of Intrinsics (i.e. reductions) if (ICA.getID() == Intrinsic::vp_load) { - Align Alignment = isa_and_nonnull(ICA.getInst()) - ? cast(ICA.getInst()) - ->getPointerAlignment() - .valueOrOne() - : Align(1); - unsigned AS = ICA.getArgs().size() >= 1 && - isa(ICA.getArgs()[0]->getType()) - ? cast(ICA.getArgs()[0]->getType()) - ->getAddressSpace() - : 0; + Align Alignment; + if (auto *VPI = dyn_cast_or_null(ICA.getInst())) + Alignment = VPI->getPointerAlignment().valueOrOne(); + unsigned AS = 0; + if (ICA.getArgs().size() > 1) + if (auto PtrTy = dyn_cast(ICA.getArgs()[0]->getType())) + AS = PtrTy->getAddressSpace(); return thisT()->getMemoryOpCost(*FOp, ICA.getReturnType(), Alignment, AS, CostKind); } else if (ICA.getID() == Intrinsic::vp_store) { - Align Alignment = isa_and_nonnull(ICA.getInst()) - ? cast(ICA.getInst()) - ->getPointerAlignment() - .valueOrOne() - : Align(1); - unsigned AS = ICA.getArgs().size() >= 2 && - isa(ICA.getArgs()[1]->getType()) - ? cast(ICA.getArgs()[1]->getType()) - ->getAddressSpace() - : 0; + Align Alignment; + if (auto *VPI = dyn_cast_or_null(ICA.getInst())) + Alignment = VPI->getPointerAlignment().valueOrOne(); + unsigned AS = 0; + if (ICA.getArgs().size() >= 2) + if (auto PtrTy = dyn_cast(ICA.getArgs()[1]->getType())) + AS = PtrTy->getAddressSpace(); return thisT()->getMemoryOpCost(*FOp, Args[0]->getType(), Alignment, AS, CostKind); } else if (VPBinOpIntrinsic::isVPBinOp(ICA.getID())) { @@ -1732,6 +1726,9 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { VPIntrinsic::getFunctionalIntrinsicIDForVP(ICA.getID()); if (FID) { // Non-vp version will have same Args/Tys except mask and vector length. + assert(ICA.getArgs().size() >= 2 && ICA.getArgTypes().size() >= 2 && + "Expected VPIntrinsic to have Mask and Vector Length args and " + "types"); ArrayRef NewArgs(ICA.getArgs().begin(), ICA.getArgs().end() - 2); ArrayRef NewTys(ICA.getArgTypes().begin(), From 634dd0e135b497893981ada7922ea28a47e74e50 Mon Sep 17 00:00:00 2001 From: Michael Maitland Date: Wed, 4 Oct 2023 14:28:35 -0700 Subject: [PATCH 6/7] fixup! Only do getArithmeticCost if its a binop respond to craigs comments --- llvm/include/llvm/CodeGen/BasicTTIImpl.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h index fa4101155d157d..34619f0417eacc 100644 --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -1702,21 +1702,23 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { Alignment = VPI->getPointerAlignment().valueOrOne(); unsigned AS = 0; if (ICA.getArgs().size() > 1) - if (auto PtrTy = dyn_cast(ICA.getArgs()[0]->getType())) + if (auto *PtrTy = dyn_cast(ICA.getArgs()[0]->getType())) AS = PtrTy->getAddressSpace(); return thisT()->getMemoryOpCost(*FOp, ICA.getReturnType(), Alignment, AS, CostKind); - } else if (ICA.getID() == Intrinsic::vp_store) { + } + if (ICA.getID() == Intrinsic::vp_store) { Align Alignment; if (auto *VPI = dyn_cast_or_null(ICA.getInst())) Alignment = VPI->getPointerAlignment().valueOrOne(); unsigned AS = 0; if (ICA.getArgs().size() >= 2) - if (auto PtrTy = dyn_cast(ICA.getArgs()[1]->getType())) + if (auto *PtrTy = dyn_cast(ICA.getArgs()[1]->getType())) AS = PtrTy->getAddressSpace(); return thisT()->getMemoryOpCost(*FOp, Args[0]->getType(), Alignment, AS, CostKind); - } else if (VPBinOpIntrinsic::isVPBinOp(ICA.getID())) { + } + if (VPBinOpIntrinsic::isVPBinOp(ICA.getID())) { return thisT()->getArithmeticInstrCost(*FOp, ICA.getReturnType(), CostKind); } @@ -1729,10 +1731,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { assert(ICA.getArgs().size() >= 2 && ICA.getArgTypes().size() >= 2 && "Expected VPIntrinsic to have Mask and Vector Length args and " "types"); - ArrayRef NewArgs(ICA.getArgs().begin(), - ICA.getArgs().end() - 2); - ArrayRef NewTys(ICA.getArgTypes().begin(), - ICA.getArgTypes().end() - 2); + ArrayRef NewArgs = ArrayRef(ICA.getArgs()).drop_back(2); + ArrayRef NewTys = ArrayRef(ICA.getArgTypes()).drop_back(2); IntrinsicCostAttributes NewICA(*FID, ICA.getReturnType(), NewArgs, NewTys, ICA.getFlags(), ICA.getInst(), From b6c888f30e06c869968b20a29919b7974d07fcf5 Mon Sep 17 00:00:00 2001 From: Michael Maitland Date: Wed, 4 Oct 2023 14:55:37 -0700 Subject: [PATCH 7/7] Format --- llvm/include/llvm/CodeGen/BasicTTIImpl.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h index 34619f0417eacc..86be1189fc82c1 100644 --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -1702,7 +1702,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { Alignment = VPI->getPointerAlignment().valueOrOne(); unsigned AS = 0; if (ICA.getArgs().size() > 1) - if (auto *PtrTy = dyn_cast(ICA.getArgs()[0]->getType())) + if (auto *PtrTy = + dyn_cast(ICA.getArgs()[0]->getType())) AS = PtrTy->getAddressSpace(); return thisT()->getMemoryOpCost(*FOp, ICA.getReturnType(), Alignment, AS, CostKind); @@ -1713,7 +1714,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase { Alignment = VPI->getPointerAlignment().valueOrOne(); unsigned AS = 0; if (ICA.getArgs().size() >= 2) - if (auto *PtrTy = dyn_cast(ICA.getArgs()[1]->getType())) + if (auto *PtrTy = + dyn_cast(ICA.getArgs()[1]->getType())) AS = PtrTy->getAddressSpace(); return thisT()->getMemoryOpCost(*FOp, Args[0]->getType(), Alignment, AS, CostKind);