[llvm] [RISCV][CostModel] Remove cost of icmp inst in icmp+select with SFB. (PR #91158)
Elvis Wang via llvm-commits
llvm-commits at lists.llvm.org
Mon May 13 08:00:09 PDT 2024
https://github.com/ElvisWang123 updated https://github.com/llvm/llvm-project/pull/91158
>From 71a7c431aab7a261526fefcb729892e58944c560 Mon Sep 17 00:00:00 2001
From: Elvis Wang <elvis.wang at sifive.com>
Date: Sun, 5 May 2024 18:23:14 -0700
Subject: [PATCH 1/3] Pre-commit test case for instruction cost of cmp instr
(nfc)
---
llvm/test/Analysis/CostModel/RISCV/cmp-select.ll | 13 +++++++++++++
1 file changed, 13 insertions(+)
create mode 100644 llvm/test/Analysis/CostModel/RISCV/cmp-select.ll
diff --git a/llvm/test/Analysis/CostModel/RISCV/cmp-select.ll b/llvm/test/Analysis/CostModel/RISCV/cmp-select.ll
new file mode 100644
index 0000000000000..d50bd824bcfac
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/RISCV/cmp-select.ll
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
+; RUN: opt < %s -mtriple=riscv64 -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=CHECK
+
+define void @cmp-select() {
+; CHECK-LABEL: 'cmp-select'
+; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 0, 1
+; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 5, i32 4
+; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+ %cmp1 = icmp slt i64 0, 1
+ %select1 = select i1 %cmp1, i32 5, i32 4
+ ret void
+}
>From f88d5ae36bfc35654aabc7c7b0b5521efcb6987d Mon Sep 17 00:00:00 2001
From: Elvis Wang <elvis.wang at sifive.com>
Date: Sun, 5 May 2024 18:28:24 -0700
Subject: [PATCH 2/3] [RISCV][CostModel] Remove cost of cmp inst in cmp+select
with SFB.
With ShortFowrardBranchOpt(SFB) or ConditionalMoveFusion, scalar
ICmp and scalar Select instructinos will lower to SELECT_CC
and lower to PseudoCCMOVGPR which will generate a conditional
branch instr and a move instr.
The cost of scalar (ICmp + Select) = (0 + Select instr cost).
---
.../Target/RISCV/RISCVTargetTransformInfo.cpp | 11 ++++++
.../Analysis/CostModel/RISCV/cmp-select.ll | 34 +++++++++++++++----
2 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index d94dff5f2b1f5..1e843ed20ef1d 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -1443,6 +1443,17 @@ InstructionCost RISCVTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
}
}
+ // With ShortForwardBranchOpt or ConditionalMoveFusion, scalar icmp + select
+ // instructions will lower to SELECT_CC and lower to PseudoCCMOVGPR which will
+ // generate a conditional branch + mv. The cost of scalar (icmp + select) will
+ // be (0 + select instr cost).
+ if (ST->hasConditionalMoveFusion() && I && isa<ICmpInst>(I) &&
+ !ValTy->isVectorTy() && I->hasOneUser() &&
+ isa<SelectInst>(I->user_back()) &&
+ !I->user_back()->getType()->isVectorTy() &&
+ I->user_back()->getOperand(0) == I)
+ return 0;
+
// TODO: Add cost for scalar type.
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind, I);
diff --git a/llvm/test/Analysis/CostModel/RISCV/cmp-select.ll b/llvm/test/Analysis/CostModel/RISCV/cmp-select.ll
index d50bd824bcfac..695b5f114155a 100644
--- a/llvm/test/Analysis/CostModel/RISCV/cmp-select.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/cmp-select.ll
@@ -1,13 +1,35 @@
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
-; RUN: opt < %s -mtriple=riscv64 -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=CHECK
+; RUN: opt < %s -mtriple=riscv64 -mcpu=sifive-u74 -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=SFB64
+; RUN: opt < %s -mtriple=riscv64 -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=RV64
-define void @cmp-select() {
-; CHECK-LABEL: 'cmp-select'
-; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 0, 1
-; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 5, i32 4
-; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
+define void @icmp-select() {
+; SFB64-LABEL: 'icmp-select'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %cmp1 = icmp slt i64 0, 1
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 5, i32 4
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+; RV64-LABEL: 'icmp-select'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 0, 1
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 5, i32 4
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
;
%cmp1 = icmp slt i64 0, 1
%select1 = select i1 %cmp1, i32 5, i32 4
ret void
}
+
+define void @fcmp-select() {
+; SFB64-LABEL: 'fcmp-select'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float 0.000000e+00, 1.000000e+00
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %fcmp1, i32 5, i32 4
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+; RV64-LABEL: 'fcmp-select'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float 0.000000e+00, 1.000000e+00
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %fcmp1, i32 5, i32 4
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+ %fcmp1 = fcmp ogt float 0.0, 1.0
+ %select1 = select i1 %fcmp1, i32 5, i32 4
+ ret void
+}
>From 066803134cc88a7ba0a39cff8b66f935c0c6f7f5 Mon Sep 17 00:00:00 2001
From: Elvis Wang <elvis.wang at sifive.com>
Date: Mon, 13 May 2024 00:04:33 -0700
Subject: [PATCH 3/3] Address comments
---
.../Target/RISCV/RISCVTargetTransformInfo.cpp | 16 +-
.../Analysis/CostModel/RISCV/cmp-select.ll | 287 ++++++++++++++++--
2 files changed, 266 insertions(+), 37 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 1e843ed20ef1d..8b15592673ac8 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -14,9 +14,11 @@
#include "llvm/CodeGen/CostTable.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/IR/Instructions.h"
+#include "llvm/IR/PatternMatch.h"
#include <cmath>
#include <optional>
using namespace llvm;
+using namespace llvm::PatternMatch;
#define DEBUG_TYPE "riscvtti"
@@ -1448,11 +1450,15 @@ InstructionCost RISCVTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
// generate a conditional branch + mv. The cost of scalar (icmp + select) will
// be (0 + select instr cost).
if (ST->hasConditionalMoveFusion() && I && isa<ICmpInst>(I) &&
- !ValTy->isVectorTy() && I->hasOneUser() &&
- isa<SelectInst>(I->user_back()) &&
- !I->user_back()->getType()->isVectorTy() &&
- I->user_back()->getOperand(0) == I)
- return 0;
+ ValTy->isIntegerTy() && !I->user_empty()) {
+ if (all_of(I->users(), [&](const User *U) {
+ return match(U, m_Select(m_Specific(I), m_Value(), m_Value())) &&
+ U->getType()->isIntegerTy() &&
+ !isa<ConstantData>(U->getOperand(1)) &&
+ !isa<ConstantData>(U->getOperand(2));
+ }))
+ return 0;
+ }
// TODO: Add cost for scalar type.
diff --git a/llvm/test/Analysis/CostModel/RISCV/cmp-select.ll b/llvm/test/Analysis/CostModel/RISCV/cmp-select.ll
index 695b5f114155a..3de100b9b339c 100644
--- a/llvm/test/Analysis/CostModel/RISCV/cmp-select.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/cmp-select.ll
@@ -1,35 +1,258 @@
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
; RUN: opt < %s -mtriple=riscv64 -mcpu=sifive-u74 -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=SFB64
-; RUN: opt < %s -mtriple=riscv64 -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=RV64
-
-define void @icmp-select() {
-; SFB64-LABEL: 'icmp-select'
-; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %cmp1 = icmp slt i64 0, 1
-; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 5, i32 4
-; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
-;
-; RV64-LABEL: 'icmp-select'
-; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 0, 1
-; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 5, i32 4
-; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
-;
- %cmp1 = icmp slt i64 0, 1
- %select1 = select i1 %cmp1, i32 5, i32 4
- ret void
-}
-
-define void @fcmp-select() {
-; SFB64-LABEL: 'fcmp-select'
-; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float 0.000000e+00, 1.000000e+00
-; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %fcmp1, i32 5, i32 4
-; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
-;
-; RV64-LABEL: 'fcmp-select'
-; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float 0.000000e+00, 1.000000e+00
-; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %fcmp1, i32 5, i32 4
-; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
-;
- %fcmp1 = fcmp ogt float 0.0, 1.0
- %select1 = select i1 %fcmp1, i32 5, i32 4
- ret void
+; RUN: opt < %s -mtriple=riscv64 -mattr=+v,+f -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=RV64
+
+define i32 @icmp-iselect(i64 %ca, i64 %cb, i32 %a, i32 %b) {
+; SFB64-LABEL: 'icmp-iselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %cmp1 = icmp slt i64 %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %select1
+;
+; RV64-LABEL: 'icmp-iselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %select1
+;
+ %cmp1 = icmp slt i64 %ca, %cb
+ %select1 = select i1 %cmp1, i32 %a, i32 %b
+ ret i32 %select1
+}
+
+define i32 @icmp-iselects(i64 %ca, i64 %cb, i32 %a, i32 %b, i32 %c) {
+; SFB64-LABEL: 'icmp-iselects'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %cmp1 = icmp slt i64 %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select2 = select i1 %cmp1, i32 %a, i32 %c
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ret = add i32 %select1, %select2
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %ret
+;
+; RV64-LABEL: 'icmp-iselects'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select2 = select i1 %cmp1, i32 %a, i32 %c
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ret = add i32 %select1, %select2
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %ret
+;
+ %cmp1 = icmp slt i64 %ca, %cb
+ %select1 = select i1 %cmp1, i32 %a, i32 %b
+ %select2 = select i1 %cmp1, i32 %a, i32 %c
+ %ret = add i32 %select1, %select2
+ ret i32 %ret
+}
+
+define i32 @icmp-ifselects(i64 %ca, i64 %cb, i32 %a, i32 %b, float %c, float %d) {
+; SFB64-LABEL: 'icmp-ifselects'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select2 = select i1 %cmp1, float %c, float %d
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %selectint = fptosi float %select2 to i32
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ret = add i32 %select1, %selectint
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %ret
+;
+; RV64-LABEL: 'icmp-ifselects'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select2 = select i1 %cmp1, float %c, float %d
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %selectint = fptosi float %select2 to i32
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ret = add i32 %select1, %selectint
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %ret
+;
+ %cmp1 = icmp slt i64 %ca, %cb
+ %select1 = select i1 %cmp1, i32 %a, i32 %b
+ %select2 = select i1 %cmp1, float %c, float %d
+ %selectint = fptosi float %select2 to i32
+ %ret = add i32 %select1, %selectint
+ ret i32 %ret
+}
+
+define i32 @constant-icmp-iselect(i64 %ca, i64 %cb, i32 %a) {
+; SFB64-LABEL: 'constant-icmp-iselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 7
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %select1
+;
+; RV64-LABEL: 'constant-icmp-iselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 7
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %select1
+;
+ %cmp1 = icmp slt i64 %ca, %cb
+ %select1 = select i1 %cmp1, i32 %a, i32 7
+ ret i32 %select1
+}
+
+define i32 @fcmp-iselect(float %ca, float %cb, i32 %a, i32 %b) {
+; SFB64-LABEL: 'fcmp-iselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %fcmp1, i32 %a, i32 %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %select1
+;
+; RV64-LABEL: 'fcmp-iselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %fcmp1, i32 %a, i32 %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %select1
+;
+ %fcmp1 = fcmp ogt float %ca, %cb
+ %select1 = select i1 %fcmp1, i32 %a, i32 %b
+ ret i32 %select1
+}
+
+define float @fcmp-fselect(float %ca, float %cb, float %a, float %b) {
+; SFB64-LABEL: 'fcmp-fselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fselect1 = select i1 %fcmp1, float %a, float %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret float %fselect1
+;
+; RV64-LABEL: 'fcmp-fselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fselect1 = select i1 %fcmp1, float %a, float %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret float %fselect1
+;
+ %fcmp1 = fcmp ogt float %ca, %cb
+ %fselect1 = select i1 %fcmp1, float %a, float %b
+ ret float %fselect1
+}
+
+define float @icmp-fselect(i64 %ca, i64 %cb, float %a, float %b) {
+; SFB64-LABEL: 'icmp-fselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt i64 %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fselect1 = select i1 %icmp1, float %a, float %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret float %fselect1
+;
+; RV64-LABEL: 'icmp-fselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt i64 %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fselect1 = select i1 %icmp1, float %a, float %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret float %fselect1
+;
+ %icmp1 = icmp slt i64 %ca, %cb
+ %fselect1 = select i1 %icmp1, float %a, float %b
+ ret float %fselect1
+}
+
+define <2 x i32> @vector-icmp-vector-iselect(<2 x i32> %ca, <2 x i32> %cb, <2 x i32> %a, <2 x i32> %b) {
+; SFB64-LABEL: 'vector-icmp-vector-iselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %icmp = icmp slt <2 x i32> %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %select1 = select <2 x i1> %icmp, <2 x i32> %a, <2 x i32> %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1
+;
+; RV64-LABEL: 'vector-icmp-vector-iselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp = icmp slt <2 x i32> %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select <2 x i1> %icmp, <2 x i32> %a, <2 x i32> %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1
+;
+ %icmp = icmp slt <2 x i32> %ca, %cb
+ %select1 = select <2 x i1> %icmp, <2 x i32> %a, <2 x i32> %b
+ ret <2 x i32> %select1
+}
+
+define <2 x i32> @vector-fcmp-vector-iselect(<2 x float> %ca, <2 x float> %cb, <2 x i32> %a, <2 x i32> %b) {
+; SFB64-LABEL: 'vector-fcmp-vector-iselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %fcmp1 = fcmp ogt <2 x float> %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %select1 = select <2 x i1> %fcmp1, <2 x i32> %a, <2 x i32> %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1
+;
+; RV64-LABEL: 'vector-fcmp-vector-iselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt <2 x float> %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select <2 x i1> %fcmp1, <2 x i32> %a, <2 x i32> %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1
+;
+ %fcmp1 = fcmp ogt <2 x float> %ca, %cb
+ %select1 = select <2 x i1> %fcmp1, <2 x i32> %a, <2 x i32> %b
+ ret <2 x i32> %select1
+}
+
+define <2 x float> @vector-fcmp-vector-fselect(<2 x float> %ca, <2 x float> %cb, <2 x float> %a, <2 x float> %b) {
+; SFB64-LABEL: 'vector-fcmp-vector-fselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %fcmp1 = fcmp ogt <2 x float> %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %select1 = select <2 x i1> %fcmp1, <2 x float> %a, <2 x float> %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1
+;
+; RV64-LABEL: 'vector-fcmp-vector-fselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt <2 x float> %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select <2 x i1> %fcmp1, <2 x float> %a, <2 x float> %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1
+;
+ %fcmp1 = fcmp ogt <2 x float> %ca, %cb
+ %select1 = select <2 x i1> %fcmp1, <2 x float> %a, <2 x float> %b
+ ret <2 x float> %select1
+}
+
+define <2 x float> @vector-icmp-vector-fselect(<2 x i32> %ca, <2 x i32> %cb, <2 x float> %a, <2 x float> %b) {
+; SFB64-LABEL: 'vector-icmp-vector-fselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %icmp1 = icmp slt <2 x i32> %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %select1 = select <2 x i1> %icmp1, <2 x float> %a, <2 x float> %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1
+;
+; RV64-LABEL: 'vector-icmp-vector-fselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt <2 x i32> %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select <2 x i1> %icmp1, <2 x float> %a, <2 x float> %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1
+;
+ %icmp1 = icmp slt <2 x i32> %ca, %cb
+ %select1 = select <2 x i1> %icmp1, <2 x float> %a, <2 x float> %b
+ ret <2 x float> %select1
+}
+
+define <2 x float> @icmp-vector-fselect(i1 %ca, i1 %cb, <2 x float> %a, <2 x float> %b) {
+; SFB64-LABEL: 'icmp-vector-fselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt i1 %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %select1 = select i1 %icmp1, <2 x float> %a, <2 x float> %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1
+;
+; RV64-LABEL: 'icmp-vector-fselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt i1 %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %select1 = select i1 %icmp1, <2 x float> %a, <2 x float> %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1
+;
+ %icmp1 = icmp slt i1 %ca, %cb
+ %select1 = select i1 %icmp1, <2 x float> %a, <2 x float> %b
+ ret <2 x float> %select1
+}
+
+define <2 x i32> @icmp-vector-iselect(i1 %ca, i1 %cb, <2 x i32> %a, <2 x i32> %b) {
+; SFB64-LABEL: 'icmp-vector-iselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt i1 %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %select1 = select i1 %icmp1, <2 x i32> %a, <2 x i32> %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1
+;
+; RV64-LABEL: 'icmp-vector-iselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt i1 %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %select1 = select i1 %icmp1, <2 x i32> %a, <2 x i32> %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1
+;
+ %icmp1 = icmp slt i1 %ca, %cb
+ %select1 = select i1 %icmp1, <2 x i32> %a, <2 x i32> %b
+ ret <2 x i32> %select1
+}
+
+define <2 x float> @fcmp-vector-fselect(float %ca, float %cb, <2 x float> %a, <2 x float> %b) {
+; SFB64-LABEL: 'fcmp-vector-fselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %select1 = select i1 %fcmp1, <2 x float> %a, <2 x float> %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1
+;
+; RV64-LABEL: 'fcmp-vector-fselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %select1 = select i1 %fcmp1, <2 x float> %a, <2 x float> %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1
+;
+ %fcmp1 = fcmp ogt float %ca, %cb
+ %select1 = select i1 %fcmp1, <2 x float> %a, <2 x float> %b
+ ret <2 x float> %select1
+}
+
+define <2 x i32> @fcmp-vector-iselect(float %ca, float %cb, <2 x i32> %a, <2 x i32> %b) {
+; SFB64-LABEL: 'fcmp-vector-iselect'
+; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb
+; SFB64-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %select1 = select i1 %fcmp1, <2 x i32> %a, <2 x i32> %b
+; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1
+;
+; RV64-LABEL: 'fcmp-vector-iselect'
+; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb
+; RV64-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %select1 = select i1 %fcmp1, <2 x i32> %a, <2 x i32> %b
+; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1
+;
+ %fcmp1 = fcmp ogt float %ca, %cb
+ %select1 = select i1 %fcmp1, <2 x i32> %a, <2 x i32> %b
+ ret <2 x i32> %select1
}
More information about the llvm-commits
mailing list