[llvm] b87a093 - [RISCV] Add tests for cost modelling constants in phis

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 29 05:55:28 PDT 2023


Author: Luke Lau
Date: 2023-06-29T13:55:22+01:00
New Revision: b87a09301f085d772997df742262ed54ddb987bb

URL: https://github.com/llvm/llvm-project/commit/b87a09301f085d772997df742262ed54ddb987bb
DIFF: https://github.com/llvm/llvm-project/commit/b87a09301f085d772997df742262ed54ddb987bb.diff

LOG: [RISCV] Add tests for cost modelling constants in phis

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D149168

Added: 
    llvm/test/Analysis/CostModel/RISCV/phi-const.ll
    llvm/test/Analysis/CostModel/RISCV/rvv-phi-const.ll
    llvm/test/Transforms/SLPVectorizer/RISCV/phi-const.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/CostModel/RISCV/phi-const.ll b/llvm/test/Analysis/CostModel/RISCV/phi-const.ll
new file mode 100644
index 00000000000000..b2f1dea4e81e12
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/RISCV/phi-const.ll
@@ -0,0 +1,182 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 2
+; RUN: opt < %s -mtriple=riscv64 -mattr=+f,+d -disable-output -passes="print<cost-model>" 2>&1 | FileCheck %s
+
+define i8 @phi_i8(i1 %c) {
+; CHECK-LABEL: 'phi_i8'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi i8 [ 16, %a ], [ 32, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret i8 %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi i8 [16, %a], [32, %b]
+  ret i8 %x
+}
+
+define i16 @phi_i16_small(i1 %c) {
+; CHECK-LABEL: 'phi_i16_small'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi i16 [ 1, %a ], [ 2, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret i16 %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi i16 [1, %a], [2, %b]
+  ret i16 %x
+}
+
+define i16 @phi_i16_large(i1 %c) {
+; CHECK-LABEL: 'phi_i16_large'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi i16 [ 42, %a ], [ -7616, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret i16 %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi i16 [42, %a], [123456, %b]
+  ret i16 %x
+}
+
+define i32 @phi_i32_small(i1 %c) {
+; CHECK-LABEL: 'phi_i32_small'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi i32 [ 1, %a ], [ 2, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret i32 %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi i32 [1, %a], [2, %b]
+  ret i32 %x
+}
+
+define i32 @phi_i32_large(i1 %c) {
+; CHECK-LABEL: 'phi_i32_large'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi i32 [ 42, %a ], [ 123456, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret i32 %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi i32 [42, %a], [123456, %b]
+  ret i32 %x
+}
+
+define i64 @phi_i64_small(i1 %c) {
+; CHECK-LABEL: 'phi_i64_small'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi i64 [ 1, %a ], [ 2, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret i64 %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi i64 [1, %a], [2, %b]
+  ret i64 %x
+}
+
+define i64 @phi_i64_large(i1 %c) {
+; CHECK-LABEL: 'phi_i64_large'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi i64 [ 42, %a ], [ 123456, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret i64 %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi i64 [42, %a], [123456, %b]
+  ret i64 %x
+}
+
+define half @phi_f16(i1 %c) {
+; CHECK-LABEL: 'phi_f16'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi half [ 0xHE3CE, %a ], [ 0xH5144, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret half %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi half [-999.0, %a], [42.125, %b]
+  ret half %x
+}
+
+define float @phi_f32(i1 %c) {
+; CHECK-LABEL: 'phi_f32'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi float [ -9.990000e+02, %a ], [ 4.212500e+01, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret float %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi float [-999.0, %a], [42.125, %b]
+  ret float %x
+}
+
+define double @phi_f64(i1 %c) {
+; CHECK-LABEL: 'phi_f64'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi double [ -9.990000e+02, %a ], [ 4.212500e+01, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret double %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi double [-999.0, %a], [42.125, %b]
+  ret double %x
+}

diff  --git a/llvm/test/Analysis/CostModel/RISCV/rvv-phi-const.ll b/llvm/test/Analysis/CostModel/RISCV/rvv-phi-const.ll
new file mode 100644
index 00000000000000..6a0137faad1e10
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/RISCV/rvv-phi-const.ll
@@ -0,0 +1,477 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 2
+; RUN: opt < %s -mtriple=riscv64 -mattr=+v,+f,+d -disable-output -passes="print<cost-model>" 2>&1 | FileCheck %s
+
+define <2 x i8> @phi_v2i8_small(i1 %c) {
+; CHECK-LABEL: 'phi_v2i8_small'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <2 x i8> [ <i8 1, i8 -1>, %a ], [ <i8 -1, i8 1>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <2 x i8> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <2 x i8> [<i8 1, i8 -1>, %a], [<i8 -1, i8 1>, %b]
+  ret <2 x i8> %x
+}
+
+define <4 x i8> @phi_v4i8_splat(i1 %c) {
+; CHECK-LABEL: 'phi_v4i8_splat'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i8> [ <i8 1, i8 1, i8 1, i8 1>, %a ], [ <i8 2, i8 2, i8 2, i8 2>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i8> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i8> [<i8 1, i8 1, i8 1, i8 1>, %a], [<i8 2, i8 2, i8 2, i8 2>, %b]
+  ret <4 x i8> %x
+}
+
+define <4 x i8> @phi_v4i8_small(i1 %c) {
+; CHECK-LABEL: 'phi_v4i8_small'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i8> [ <i8 1, i8 2, i8 3, i8 4>, %a ], [ <i8 2, i8 4, i8 6, i8 8>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i8> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i8> [<i8 1, i8 2, i8 3, i8 4>, %a], [<i8 2, i8 4, i8 6, i8 8>, %b]
+  ret <4 x i8> %x
+}
+
+define <4 x i8> @phi_v4i8_large(i1 %c) {
+; CHECK-LABEL: 'phi_v4i8_large'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i8> [ <i8 -46, i8 -31, i8 15, i8 74>, %a ], [ <i8 8, i8 32, i8 -59, i8 12>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i8> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i8> [<i8 1234, i8 4321, i8 9999, i8 2378>, %a], [<i8 7432, i8 -4832, i8 381381, i8 12>, %b]
+  ret <4 x i8> %x
+}
+
+; The cost should be conservative and assume it will need to materialize the more expensive constant
+define <4 x i8> @phi_v4i8_cheap_and_expensive(i1 %c) {
+; CHECK-LABEL: 'phi_v4i8_cheap_and_expensive'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i8> [ <i8 1, i8 1, i8 1, i8 1>, %a ], [ <i8 8, i8 32, i8 -59, i8 12>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i8> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i8> [<i8 1, i8 1, i8 1, i8 1>, %a], [<i8 7432, i8 -4832, i8 381381, i8 12>, %b]
+  ret <4 x i8> %x
+}
+
+define <4 x i16> @phi_v4i16_splat(i1 %c) {
+; CHECK-LABEL: 'phi_v4i16_splat'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i16> [ <i16 1, i16 1, i16 1, i16 1>, %a ], [ <i16 2, i16 2, i16 2, i16 2>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i16> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i16> [<i16 1, i16 1, i16 1, i16 1>, %a], [<i16 2, i16 2, i16 2, i16 2>, %b]
+  ret <4 x i16> %x
+}
+
+define <4 x i16> @phi_v4i16_small(i1 %c) {
+; CHECK-LABEL: 'phi_v4i16_small'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i16> [ <i16 1, i16 2, i16 3, i16 4>, %a ], [ <i16 2, i16 4, i16 6, i16 8>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i16> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i16> [<i16 1, i16 2, i16 3, i16 4>, %a], [<i16 2, i16 4, i16 6, i16 8>, %b]
+  ret <4 x i16> %x
+}
+
+define <4 x i16> @phi_v4i16_large(i1 %c) {
+; CHECK-LABEL: 'phi_v4i16_large'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i16> [ <i16 1234, i16 4321, i16 9999, i16 2378>, %a ], [ <i16 7432, i16 -4832, i16 -11835, i16 12>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i16> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i16> [<i16 1234, i16 4321, i16 9999, i16 2378>, %a], [<i16 7432, i16 -4832, i16 381381, i16 12>, %b]
+  ret <4 x i16> %x
+}
+
+; The cost should be conservative and assume it will need to materialize the more expensive constant
+define <4 x i16> @phi_v4i16_cheap_and_expensive(i1 %c) {
+; CHECK-LABEL: 'phi_v4i16_cheap_and_expensive'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i16> [ <i16 1, i16 1, i16 1, i16 1>, %a ], [ <i16 7432, i16 -4832, i16 -11835, i16 12>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i16> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i16> [<i16 1, i16 1, i16 1, i16 1>, %a], [<i16 7432, i16 -4832, i16 381381, i16 12>, %b]
+  ret <4 x i16> %x
+}
+
+define <4 x i32> @phi_v4i32_splat(i1 %c) {
+; CHECK-LABEL: 'phi_v4i32_splat'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %a ], [ <i32 2, i32 2, i32 2, i32 2>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i32> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i32> [<i32 1, i32 1, i32 1, i32 1>, %a], [<i32 2, i32 2, i32 2, i32 2>, %b]
+  ret <4 x i32> %x
+}
+
+define <4 x i32> @phi_v4i32_small(i1 %c) {
+; CHECK-LABEL: 'phi_v4i32_small'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %a ], [ <i32 2, i32 4, i32 6, i32 8>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i32> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i32> [<i32 1, i32 2, i32 3, i32 4>, %a], [<i32 2, i32 4, i32 6, i32 8>, %b]
+  ret <4 x i32> %x
+}
+
+define <4 x i32> @phi_v4i32_large(i1 %c) {
+; CHECK-LABEL: 'phi_v4i32_large'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i32> [ <i32 1234, i32 4321, i32 9999, i32 2378>, %a ], [ <i32 7432, i32 -4832, i32 381381, i32 12>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i32> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i32> [<i32 1234, i32 4321, i32 9999, i32 2378>, %a], [<i32 7432, i32 -4832, i32 381381, i32 12>, %b]
+  ret <4 x i32> %x
+}
+
+; The cost should be conservative and assume it will need to materialize the more expensive constant
+define <4 x i32> @phi_v4i32_cheap_and_expensive(i1 %c) {
+; CHECK-LABEL: 'phi_v4i32_cheap_and_expensive'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %a ], [ <i32 7432, i32 -4832, i32 381381, i32 12>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i32> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i32> [<i32 1, i32 1, i32 1, i32 1>, %a], [<i32 7432, i32 -4832, i32 381381, i32 12>, %b]
+  ret <4 x i32> %x
+}
+
+define <4 x i64> @phi_v4i64_splat(i1 %c) {
+; CHECK-LABEL: 'phi_v4i64_splat'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i64> [ <i64 1, i64 1, i64 1, i64 1>, %a ], [ <i64 2, i64 2, i64 2, i64 2>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i64> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i64> [<i64 1, i64 1, i64 1, i64 1>, %a], [<i64 2, i64 2, i64 2, i64 2>, %b]
+  ret <4 x i64> %x
+}
+
+define <4 x i64> @phi_v4i64_small(i1 %c) {
+; CHECK-LABEL: 'phi_v4i64_small'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i64> [ <i64 1, i64 2, i64 3, i64 4>, %a ], [ <i64 2, i64 4, i64 6, i64 8>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i64> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i64> [<i64 1, i64 2, i64 3, i64 4>, %a], [<i64 2, i64 4, i64 6, i64 8>, %b]
+  ret <4 x i64> %x
+}
+
+define <4 x i64> @phi_v4i64_large(i1 %c) {
+; CHECK-LABEL: 'phi_v4i64_large'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i64> [ <i64 1234, i64 4321, i64 9999, i64 2378>, %a ], [ <i64 7432, i64 -4832, i64 381381, i64 12>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i64> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i64> [<i64 1234, i64 4321, i64 9999, i64 2378>, %a], [<i64 7432, i64 -4832, i64 381381, i64 12>, %b]
+  ret <4 x i64> %x
+}
+
+; The cost should be conservative and assume it will need to materialize the more expensive constant
+define <4 x i64> @phi_v4i64_cheap_and_expensive(i1 %c) {
+; CHECK-LABEL: 'phi_v4i64_cheap_and_expensive'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x i64> [ <i64 1, i64 1, i64 1, i64 1>, %a ], [ <i64 7432, i64 -4832, i64 381381, i64 12>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x i64> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x i64> [<i64 1, i64 1, i64 1, i64 1>, %a], [<i64 7432, i64 -4832, i64 381381, i64 12>, %b]
+  ret <4 x i64> %x
+}
+
+define <4 x half> @phi_v4f16_splat(i1 %c) {
+; CHECK-LABEL: 'phi_v4f16_splat'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x half> [ <half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00>, %a ], [ <half 0xH4000, half 0xH4000, half 0xH4000, half 0xH4D00>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x half> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x half> [<half 1.0, half 1.0, half 1.0, half 1.0>, %a], [<half 2.0, half 2.0, half 2.0, half 20.>, %b]
+  ret <4 x half> %x
+}
+
+define <4 x half> @phi_v4f16(i1 %c) {
+; CHECK-LABEL: 'phi_v4f16'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x half> [ <half 0xH3C00, half 0xH4000, half 0xH4200, half 0xH4400>, %a ], [ <half 0xH4000, half 0xH4400, half 0xH4600, half 0xH4800>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x half> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x half> [<half 1.0, half 2.0, half 3.0, half 4.0>, %a], [<half 2.0, half 4.0, half 6.0, half 8.0>, %b]
+  ret <4 x half> %x
+}
+
+; The cost should be conservative and assume it will need to materialize the more expensive constant
+define <4 x half> @phi_v4f16_cheap_and_expensive(i1 %c) {
+; CHECK-LABEL: 'phi_v4f16_cheap_and_expensive'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x half> [ <half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00>, %a ], [ <half 0xH6F42, half 0xHECB8, half 0xH5DF6, half 0xH4A40>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x half> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x half> [<half 1.0, half 1.0, half 1.0, half 1.0>, %a], [<half 7432.0, half -4832.0, half 381.5, half 12.5>, %b]
+  ret <4 x half> %x
+}
+
+define <4 x float> @phi_v4f32_splat(i1 %c) {
+; CHECK-LABEL: 'phi_v4f32_splat'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x float> [ <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, %a ], [ <float 2.000000e+00, float 2.000000e+00, float 2.000000e+00, float 2.000000e+01>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x float> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x float> [<float 1.0, float 1.0, float 1.0, float 1.0>, %a], [<float 2.0, float 2.0, float 2.0, float 20.>, %b]
+  ret <4 x float> %x
+}
+
+define <4 x float> @phi_v4f32(i1 %c) {
+; CHECK-LABEL: 'phi_v4f32'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x float> [ <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00>, %a ], [ <float 2.000000e+00, float 4.000000e+00, float 6.000000e+00, float 8.000000e+00>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x float> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x float> [<float 1.0, float 2.0, float 3.0, float 4.0>, %a], [<float 2.0, float 4.0, float 6.0, float 8.0>, %b]
+  ret <4 x float> %x
+}
+
+; The cost should be conservative and assume it will need to materialize the more expensive constant
+define <4 x float> @phi_v4f32_cheap_and_expensive(i1 %c) {
+; CHECK-LABEL: 'phi_v4f32_cheap_and_expensive'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x float> [ <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, %a ], [ <float 7.432000e+03, float -4.832000e+03, float 3.815000e+02, float 1.250000e+01>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x float> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x float> [<float 1.0, float 1.0, float 1.0, float 1.0>, %a], [<float 7432.0, float -4832.0, float 381.5, float 12.5>, %b]
+  ret <4 x float> %x
+}
+
+define <4 x double> @phi_v4f64_splat(i1 %c) {
+; CHECK-LABEL: 'phi_v4f64_splat'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x double> [ <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>, %a ], [ <double 2.000000e+00, double 2.000000e+00, double 2.000000e+00, double 2.000000e+01>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x double> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x double> [<double 1.0, double 1.0, double 1.0, double 1.0>, %a], [<double 2.0, double 2.0, double 2.0, double 20.>, %b]
+  ret <4 x double> %x
+}
+
+define <4 x double> @phi_v4f64(i1 %c) {
+; CHECK-LABEL: 'phi_v4f64'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x double> [ <double 1.000000e+00, double 2.000000e+00, double 3.000000e+00, double 4.000000e+00>, %a ], [ <double 2.000000e+00, double 4.000000e+00, double 6.000000e+00, double 8.000000e+00>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x double> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x double> [<double 1.0, double 2.0, double 3.0, double 4.0>, %a], [<double 2.0, double 4.0, double 6.0, double 8.0>, %b]
+  ret <4 x double> %x
+}
+
+; The cost should be conservative and assume it will need to materialize the more expensive constant
+define <4 x double> @phi_v4f64_cheap_and_expensive(i1 %c) {
+; CHECK-LABEL: 'phi_v4f64_cheap_and_expensive'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br i1 %c, label %a, label %b
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %d
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %x = phi <4 x double> [ <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>, %a ], [ <double 7.432000e+03, double -4.832000e+03, double 3.815000e+02, double 1.250000e+01>, %b ]
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: ret <4 x double> %x
+;
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi <4 x double> [<double 1.0, double 1.0, double 1.0, double 1.0>, %a], [<double 7432.0, double -4832.0, double 381.5, double 12.5>, %b]
+  ret <4 x double> %x
+}

diff  --git a/llvm/test/Transforms/SLPVectorizer/RISCV/phi-const.ll b/llvm/test/Transforms/SLPVectorizer/RISCV/phi-const.ll
new file mode 100644
index 00000000000000..3982a4523af40e
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/RISCV/phi-const.ll
@@ -0,0 +1,69 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -passes=slp-vectorizer -S < %s -mtriple=riscv32 -mattr=+v \
+; RUN:     -riscv-v-slp-max-vf=0 | FileCheck %s
+; RUN: opt -passes=slp-vectorizer -S < %s -mtriple=riscv64 -mattr=+v \
+; RUN:     -riscv-v-slp-max-vf=0 | FileCheck %s
+
+; These shouldn't be vectorized as the cost of materializing the constants as
+; vectors should outweigh the scalar cost
+
+define void @f(ptr %p, i1 %c) {
+; CHECK-LABEL: define void @f
+; CHECK-SAME: (ptr [[P:%.*]], i1 [[C:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:    [[P_0:%.*]] = getelementptr i8, ptr [[P]]
+; CHECK-NEXT:    br i1 [[C]], label [[A:%.*]], label [[B:%.*]]
+; CHECK:       a:
+; CHECK-NEXT:    br label [[D:%.*]]
+; CHECK:       b:
+; CHECK-NEXT:    br label [[D]]
+; CHECK:       d:
+; CHECK-NEXT:    [[TMP1:%.*]] = phi <2 x i8> [ <i8 1, i8 -1>, [[A]] ], [ <i8 -1, i8 1>, [[B]] ]
+; CHECK-NEXT:    store <2 x i8> [[TMP1]], ptr [[P_0]], align 1
+; CHECK-NEXT:    ret void
+;
+  %p.0 = getelementptr i8, ptr %p
+  %p.1 = getelementptr i8, ptr %p, i32 1
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi i8 [1, %a], [-1, %b]
+  %y = phi i8 [-1, %a], [1, %b]
+  store i8 %x, ptr %p.0
+  store i8 %y, ptr %p.1
+  ret void
+}
+
+define void @g(ptr %p, i1 %c) {
+; CHECK-LABEL: define void @g
+; CHECK-SAME: (ptr [[P:%.*]], i1 [[C:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    [[P_0:%.*]] = getelementptr i8, ptr [[P]]
+; CHECK-NEXT:    br i1 [[C]], label [[A:%.*]], label [[B:%.*]]
+; CHECK:       a:
+; CHECK-NEXT:    br label [[D:%.*]]
+; CHECK:       b:
+; CHECK-NEXT:    br label [[D]]
+; CHECK:       d:
+; CHECK-NEXT:    [[TMP1:%.*]] = phi <2 x i8> [ <i8 1, i8 -1>, [[A]] ], [ <i8 -1, i8 1>, [[B]] ]
+; CHECK-NEXT:    [[TMP2:%.*]] = add <2 x i8> [[TMP1]], <i8 1, i8 1>
+; CHECK-NEXT:    store <2 x i8> [[TMP2]], ptr [[P_0]], align 1
+; CHECK-NEXT:    ret void
+;
+  %p.0 = getelementptr i8, ptr %p
+  %p.1 = getelementptr i8, ptr %p, i32 1
+  br i1 %c, label %a, label %b
+a:
+  br label %d
+b:
+  br label %d
+d:
+  %x = phi i8 [1, %a], [-1, %b]
+  %y = phi i8 [-1, %a], [1, %b]
+  %x.add = add i8 %x, 1
+  %y.add = add i8 %y, 1
+  store i8 %x.add, ptr %p.0
+  store i8 %y.add, ptr %p.1
+  ret void
+}


        


More information about the llvm-commits mailing list