[llvm] [LLVM][CostModel] Support struct types in select (PR #144016)
Ivan R. Ivanov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 12 23:00:08 PDT 2025
https://github.com/ivanradanov updated https://github.com/llvm/llvm-project/pull/144016
>From 93ff6d0c38756ead4067f74bc84b11ce2814aa30 Mon Sep 17 00:00:00 2001
From: Ivan Radanov Ivanov <ivanov.i.aa at m.titech.ac.jp>
Date: Fri, 13 Jun 2025 13:47:08 +0900
Subject: [PATCH 1/2] [LLVM][CostModel] Support struct types in select
---
llvm/include/llvm/CodeGen/BasicTTIImpl.h | 5 +++++
llvm/test/Analysis/CostModel/X86/select.ll | 24 ++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index 574152e254f15..9208f76f020f5 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -1370,6 +1370,11 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
Op1Info, Op2Info, I);
+ // Structs etc
+ if (getTLI()->getValueType(DL, ValTy, true) == MVT::Other)
+ return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
+ Op1Info, Op2Info, I);
+
// Selects on vectors are actually vector selects.
if (ISD == ISD::SELECT) {
assert(CondTy && "CondTy must exist");
diff --git a/llvm/test/Analysis/CostModel/X86/select.ll b/llvm/test/Analysis/CostModel/X86/select.ll
index f2c2890a182fc..e7e12178db3f3 100644
--- a/llvm/test/Analysis/CostModel/X86/select.ll
+++ b/llvm/test/Analysis/CostModel/X86/select.ll
@@ -554,3 +554,27 @@ define <32 x i8> @test_32i8(<32 x i8> %a, <32 x i8> %b) {
ret <32 x i8> %sel
}
+define { ptr, ptr } @test_struct( { ptr, ptr } %a, { ptr, ptr } %b, i1 %c) {
+; SSE-LABEL: 'test_struct'
+; SSE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
+; SSE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { ptr, ptr } %sel
+;
+; AVX1-LABEL: 'test_struct'
+; AVX1-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
+; AVX1-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { ptr, ptr } %sel
+;
+; AVX2-LABEL: 'test_struct'
+; AVX2-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
+; AVX2-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { ptr, ptr } %sel
+;
+; AVX512-LABEL: 'test_struct'
+; AVX512-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
+; AVX512-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { ptr, ptr } %sel
+;
+; SLM-LABEL: 'test_struct'
+; SLM-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
+; SLM-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { ptr, ptr } %sel
+;
+ %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
+ ret { ptr, ptr } %sel
+}
>From ef20c361777a88f586b3349981a9d0ddb33c8d5a Mon Sep 17 00:00:00 2001
From: Ivan Radanov Ivanov <ivanov.i.aa at m.titech.ac.jp>
Date: Fri, 13 Jun 2025 14:59:58 +0900
Subject: [PATCH 2/2] fix test
---
llvm/test/Analysis/CostModel/X86/select.ll | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/llvm/test/Analysis/CostModel/X86/select.ll b/llvm/test/Analysis/CostModel/X86/select.ll
index e7e12178db3f3..0b77731f2b3cd 100644
--- a/llvm/test/Analysis/CostModel/X86/select.ll
+++ b/llvm/test/Analysis/CostModel/X86/select.ll
@@ -560,20 +560,20 @@ define { ptr, ptr } @test_struct( { ptr, ptr } %a, { ptr, ptr } %b, i1 %c) {
; SSE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { ptr, ptr } %sel
;
; AVX1-LABEL: 'test_struct'
-; AVX1-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
-; AVX1-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { ptr, ptr } %sel
+; AVX1-NEXT: Cost Model: Found costs of 1 for: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
+; AVX1-NEXT: Cost Model: Found costs of RThru:0 CodeSize:1 Lat:1 SizeLat:1 for: ret { ptr, ptr } %sel
;
; AVX2-LABEL: 'test_struct'
-; AVX2-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
-; AVX2-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { ptr, ptr } %sel
+; AVX2-NEXT: Cost Model: Found costs of 1 for: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
+; AVX2-NEXT: Cost Model: Found costs of RThru:0 CodeSize:1 Lat:1 SizeLat:1 for: ret { ptr, ptr } %sel
;
; AVX512-LABEL: 'test_struct'
-; AVX512-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
-; AVX512-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { ptr, ptr } %sel
+; AVX512-NEXT: Cost Model: Found costs of 1 for: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
+; AVX512-NEXT: Cost Model: Found costs of RThru:0 CodeSize:1 Lat:1 SizeLat:1 for: ret { ptr, ptr } %sel
;
; SLM-LABEL: 'test_struct'
-; SLM-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
-; SLM-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { ptr, ptr } %sel
+; SLM-NEXT: Cost Model: Found costs of 1 for: %sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
+; SLM-NEXT: Cost Model: Found costs of RThru:0 CodeSize:1 Lat:1 SizeLat:1 for: ret { ptr, ptr } %sel
;
%sel = select i1 %c, { ptr, ptr } %a, { ptr, ptr } %b
ret { ptr, ptr } %sel
More information about the llvm-commits
mailing list