From b87a09301f085d772997df742262ed54ddb987bb Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Thu, 29 Jun 2023 13:54:57 +0100 Subject: [PATCH] [RISCV] Add tests for cost modelling constants in phis Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D149168 --- llvm/test/Analysis/CostModel/RISCV/phi-const.ll | 182 ++++++++ .../test/Analysis/CostModel/RISCV/rvv-phi-const.ll | 477 +++++++++++++++++++++ .../Transforms/SLPVectorizer/RISCV/phi-const.ll | 69 +++ 3 files changed, 728 insertions(+) create mode 100644 llvm/test/Analysis/CostModel/RISCV/phi-const.ll create mode 100644 llvm/test/Analysis/CostModel/RISCV/rvv-phi-const.ll create mode 100644 llvm/test/Transforms/SLPVectorizer/RISCV/phi-const.ll 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 0000000..b2f1dea --- /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" 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 0000000..6a0137f --- /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" 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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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> [ , %a ], [ , %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> [, %a], [, %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 0000000..3982a45 --- /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> [ , [[A]] ], [ , [[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> [ , [[A]] ], [ , [[B]] ] +; CHECK-NEXT: [[TMP2:%.*]] = add <2 x i8> [[TMP1]], +; 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 +} -- 2.7.4