Bug type: crash
Component: SLPVectorizer
Bug location: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp: BoUpSLP::computeMinimumValueSizes
Issue title: [SLP] Cannot getTypeInfo() on a type that is unsized!
Labels: release:backport
llvm:SLPVectorizer
crash-on-valid
Reported by: DianQK

I tried the following IR with SLP:

```llvm
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @foo(ptr %i) {
bb:
  %i1 = getelementptr i8, ptr %i, i64 4
  br label %bb2

bb2:                                              ; preds = %bb2, %bb
  %i3 = phi i32 [ %i6, %bb2 ], [ 0, %bb ]
  %i4 = phi i32 [ %i8, %bb2 ], [ 0, %bb ]
  store i32 %i3, ptr %i
  store i32 %i4, ptr %i1
  %i5 = trunc i32 0 to i1
  %i6 = select i1 %i5, i32 0, i32 0
  %i7 = trunc i32 %i4 to i1
  %i8 = select i1 %i7, i32 0, i32 0
  br label %bb2
}
```

It failed with an error output:`Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!"' failed`. It's getting the size returned by the `store i32 %i4, ptr %i1` instruction.​

https://llvm.godbolt.org/z/fMx9qMcfK

cc f6e01b9ece1e73f6eda6e1dbff3aa72e917f4007 @alexey-bataev


Comments: author: dtcxzyw
body: https://github.com/llvm/llvm-project/blob/2cbd1bc830861bc08f78fb6cc11747b82f66c4c6/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp#L16067

`U` is `store i32 %i4, ptr %i1`.

author: DianQK
body: Reverting f6e01b9ece1e73f6eda6e1dbff3aa72e917f4007 seems reasonable to me. What do you think? @alexey-bataev ^^
author: alexey-bataev
body: will fix it asap today

Fix patch:
commit f381cd069965dabfeb277f30a4e532d7fd498f6e
Author: Alexey Bataev <a.bataev@outlook.com>
Date:   Tue Sep 3 04:52:47 2024 -0700

    [SLP]Fix PR107036: Check if the type of the user is sizable before requesting its size.
    
    Only some instructions should be considered as potentially reducing the
    size of the operands types, not all instructions should be considered.
    
    Fixes https://github.com/llvm/llvm-project/issues/107036

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 58137cd6f543..f58803fc56a2 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -16055,15 +16055,16 @@ void BoUpSLP::computeMinimumValueSizes() {
                     const TreeEntry *UserTE = E.UserTreeIndices.back().UserTE;
                     if (TE == UserTE || !TE)
                       return false;
+                    if (!isa<CastInst, BinaryOperator, FreezeInst, PHINode,
+                             SelectInst>(U) ||
+                        !isa<CastInst, BinaryOperator, FreezeInst, PHINode,
+                             SelectInst>(UserTE->getMainOp()))
+                      return true;
                     unsigned UserTESz = DL->getTypeSizeInBits(
                         UserTE->Scalars.front()->getType());
                     auto It = MinBWs.find(TE);
                     if (It != MinBWs.end() && It->second.first > UserTESz)
                       return true;
-                    // The size of icmp is always 1 and should not be
-                    // considered.
-                    if (TE->getOpcode() == Instruction::ICmp)
-                      return true;
                     return DL->getTypeSizeInBits(U->getType()) > UserTESz;
                   }));
         })) {


Regression tests:
file: llvm/test/Transforms/SLPVectorizer/X86/minbw-user-non-sizable.ll
commands: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s -slp-threshold=-100
tests: test_name: test
test_body: define void @test(ptr %i) {
bb:
  %i1 = getelementptr i8, ptr %i, i64 4
  br label %bb2

bb2:                                              ; preds = %bb2, %bb
  %i3 = phi i32 [ %i6, %bb2 ], [ 0, %bb ]
  %i4 = phi i32 [ %i8, %bb2 ], [ 0, %bb ]
  store i32 %i3, ptr %i, align 4
  store i32 %i4, ptr %i1, align 4
  %i5 = trunc i32 0 to i1
  %i6 = select i1 %i5, i32 0, i32 0
  %i7 = trunc i32 %i4 to i1
  %i8 = select i1 %i7, i32 0, i32 0
  br label %bb2
}