Skip to content

[LLVM][CostModel] Support struct types in select #144016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ivanradanov
Copy link
Contributor

@llvmbot
Copy link
Member

llvmbot commented Jun 13, 2025

@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-backend-x86

Author: Ivan R. Ivanov (ivanradanov)

Changes

https://godbolt.org/z/b3TYcq7dv


Full diff: https://github.com/llvm/llvm-project/pull/144016.diff

2 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/BasicTTIImpl.h (+5)
  • (modified) llvm/test/Analysis/CostModel/X86/select.ll (+24)
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
+}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants