Bug type: crash
Component: SLPVectorizer
Bug location: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp: BoUpSLP::buildTree_rec
Issue title: SLPVectorizer: "Reshuffling scalars not yet supported for nodes with padding" assert
Labels: llvm:SLPVectorizer
crash-on-valid
Reported by: aeubanks

```
$ cat /tmp/a.ll
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-grtev4-linux-gnu"

define void @gsl_matrix_long_double_minmax_index() {
entry:
  br i1 false, label %cleanup22, label %for.cond6.preheader.us.preheader

for.cond6.preheader.us.preheader:                 ; preds = %entry
  %cmp14.us = fcmp ogt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000
  %imax.2.us = select i1 %cmp14.us, i64 0, i64 0
  %jmax.2.us = select i1 %cmp14.us, i64 0, i64 0
  %cmp13.us = fcmp olt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000
  %imin.2.us = select i1 %cmp13.us, i64 0, i64 0
  %jmin.2.us = select i1 %cmp13.us, i64 0, i64 0
  br label %cleanup22

cleanup22:                                        ; preds = %for.cond6.preheader.us.preheader, %entry
  %storemerge64 = phi i64 [ 0, %entry ], [ %imin.2.us, %for.cond6.preheader.us.preheader ]
  %storemerge63 = phi i64 [ 0, %entry ], [ %jmin.2.us, %for.cond6.preheader.us.preheader ]
  %storemerge62 = phi i64 [ 0, %entry ], [ %imax.2.us, %for.cond6.preheader.us.preheader ]
  %storemerge = phi i64 [ 0, %entry ], [ %jmax.2.us, %for.cond6.preheader.us.preheader ]
  ret void
}
$ opt -p slp-vectorizer /tmp/a.ll -disable-output
opt: ../../llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3714: TreeEntry *llvm::slpvectorizer::BoUpSLP::newTreeEntry(ArrayRef<Value *>, TreeEntry::EntryState, ScheduleBundle &, const InstructionsState &, const EdgeInfo &, ArrayRef<int>, ArrayRef<unsigned int>): Assertion `(hasFullVectorsOrPowerOf2(*TTI, 
getValueType(VL.front()), VL.size()) || ReuseShuffleIndices.empty()) && "Reshuffling scalars not yet supported for nodes with padding"' failed.                                                                                                                                                                    

```

@alexey-bataev 


Fix patch:
commit bfd8cc0a3e82c5e6345a66dd5db5242accb6874b
Author: Alexey Bataev <a.bataev@outlook.com>
Date:   Mon Mar 31 10:31:18 2025 -0700

    [SLP]Fix a check for the whole register use
    
    Need to check the value type, not the return type, of the instructions,
    when doing the analysis for the whole register use to prevent a compiler
    crash.
    
    Fixes #133751

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index a4b0378abc07..0679eac17658 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -8854,7 +8854,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
       // FIXME: Reshuffing scalars is not supported yet for non-power-of-2 ops.
       if ((UserTreeIdx.UserTE &&
            UserTreeIdx.UserTE->hasNonWholeRegisterOrNonPowerOf2Vec(*TTI)) ||
-          !hasFullVectorsOrPowerOf2(*TTI, VL.front()->getType(), VL.size())) {
+          !hasFullVectorsOrPowerOf2(*TTI, getValueType(VL.front()),
+                                    VL.size())) {
         LLVM_DEBUG(dbgs() << "SLP: Reshuffling scalars not yet supported "
                              "for nodes with padding.\n");
         auto Invalid = ScheduleBundle::invalid();


Regression tests:
file: llvm/test/Transforms/SLPVectorizer/X86/cmp-values-non-full-registers.ll
commands: opt -S --passes=slp-vectorizer -mtriple=x86_64-grtev4-linux-gnu < %s
tests: test_name: <module>
test_body: 
define void @test() {
;
entry:
  br i1 false, label %bb1, label %bb2

bb2:
  %cmp14.us = fcmp ogt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000
  %imax.2.us = select i1 %cmp14.us, i64 0, i64 0
  %jmax.2.us = select i1 %cmp14.us, i64 0, i64 0
  %cmp13.us = fcmp olt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000
  %imin.2.us = select i1 %cmp13.us, i64 0, i64 0
  %jmin.2.us = select i1 %cmp13.us, i64 0, i64 0
  br label %bb1

bb1:
  %storemerge64 = phi i64 [ 0, %entry ], [ %imin.2.us, %bb2 ]
  %storemerge63 = phi i64 [ 0, %entry ], [ %jmin.2.us, %bb2 ]
  %storemerge62 = phi i64 [ 0, %entry ], [ %imax.2.us, %bb2 ]
  %storemerge = phi i64 [ 0, %entry ], [ %jmax.2.us, %bb2 ]
  ret void
}