<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60649>60649</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            PHI nodes not grouped at top of BB after vector-combine pass
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ashermancinelli
      </td>
    </tr>
</table>

<pre>
    After the vector-combine pass, a phi node is added after other instructions in the basic block.

```shell
opt -passes=vector-combine test.ll -print-before-all -print-after-all -print-module-scope -S
```

Test case:
```llvm
*** IR Dump Before VectorCombinePass on foo ***
; ModuleID = 't.ll'
source_filename = "t.ll"
target datalayout = "e-p:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

define linkonce_odr void @foo() personality ptr null {
L.B5956:
  br label %L.B0779

L.B0778.preheader: ; No predecessors!
  br label %L.B0779

L.B0779:                                          ; preds = %L.B0778.preheader, %L.B5956
  %0 = phi <4 x double> [ zeroinitializer, %L.B5956 ], [ zeroinitializer, %L.B0778.preheader ]
  %1 = phi <4 x double> [ zeroinitializer, %L.B5956 ], [ zeroinitializer, %L.B0778.preheader ]
  %2 = shufflevector <4 x double> zeroinitializer, <4 x double> zeroinitializer, <4 x i32> <i32 0, i32 0, i32 1, i32 1>
  %3 = fdiv <4 x double> %0, %2
  %4 = fmul <4 x double> %0, %2
  %5 = shufflevector <4 x double> %3, <4 x double> %4, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
 store <4 x double> %5, ptr null, align 8
  ret void
}
```

Bad IR:
```llvm
*** IR Dump After VectorCombinePass on foo ***
; ModuleID = 't.ll'
source_filename = "t.ll"
target datalayout = "e-p:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

define linkonce_odr void @foo() personality ptr null {
L.B5956:
  br label %L.B0779

L.B0778.preheader: ; No predecessors!
  br label %L.B0779

L.B0779:                                          ; preds = %L.B0778.preheader, %L.B5956
  %0 = phi <4 x double> [ zeroinitializer, %L.B5956 ], [ zeroinitializer, %L.B0778.preheader ]
  %1 = shufflevector <4 x double> %0, <4 x double> %0, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
  %2 = shufflevector <4 x double> %0, <4 x double> %0, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>

  %3 = phi <4 x double> [ zeroinitializer, %L.B5956 ], [ zeroinitializer, %L.B0778.preheader ]
 Here ^^^^^

  %4 = fdiv <4 x double> %2, <double 0.000000e+00, double 0.000000e+00, double undef, double undef>
  %5 = fmul <4 x double> %1, <double 0.000000e+00, double 0.000000e+00, double undef, double undef>
 %6 = shufflevector <4 x double> %4, <4 x double> %5, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
  store <4 x double> %6, ptr null, align 8
  ret void
}
```

Stack trace:
```
PHI nodes not grouped at top of basic block!
  %3 = phi <4 x double> [ zeroinitializer, %L.B5956 ], [ zeroinitializer, %L.B0778.preheader ]
label %L.B0779
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
Program arguments: opt -passes=vector-combine -print-after-all -print-module-scope -print-before-all t.ll -S
 #0 0x0000561239dec528 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (llvm-install/bin/opt+0x1af9528)
 #1 0x0000561239dea49e llvm::sys::RunSignalHandlers() (llvm-install/bin/opt+0x1af749e)
 #2 0x0000561239deccbd SignalHandler(int) Signals.cpp:0:0
 #3 0x00007fc5bbe90c20 __restore_rt sigaction.c:0:0
 #4 0x00007fc5bb14b37f raise (/lib64/libc.so.6+0x3737f)
 #5 0x00007fc5bb135db5 abort (/lib64/libc.so.6+0x21db5)
 #6 0x0000561239d7c3ec llvm::report_fatal_error(llvm::Twine const&, bool) (llvm-install/bin/opt+0x1a893ec)
 #7 0x0000561239d7c216 (llvm-install/bin/opt+0x1a89216)
 #8 0x0000561239824a0c (llvm-install/bin/opt+0x1531a0c)
 #9 0x0000561238920ced llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (llvm-install/bin/opt+0x62dced)
#10 0x00005612397fc977 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (llvm-install/bin/opt+0x1509977)
#11 0x0000561238919256 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) (llvm-install/bin/opt+0x626256)
#12 0x0000561238926fd3 main (llvm-install/bin/opt+0x633fd3)
#13 0x00007fc5bb137493 __libc_start_main (/lib64/libc.so.6+0x23493)
#14 0x0000561238912a3e _start (llvm-install/bin/opt+0x61fa3e)
```
CC @mcinally 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWVtvIysS_jX4pWSrG_rifvCDnYsm2syeKBnNq0UDbbODoQX0THJ-_Qrat3acxDO7R6MjncixaSi--qqgisKmzsmVFmKG8gXKr0e082tjZ9Sthd1QzaQWSslRbfjLbN54YcGvBXwXzBs7ZmZTSy2gpc4hfAUU2rUEbbgA6YByLjjQOMn4tbAgtfO2Y14a7UDqCFVTJxnUyrBvE5Rco2S-fS-S_uXWQqm-z7QexkGZcIhcn5DwwvmJUjBurdR-XIvGWDGmh57I5LhjY3inxNgx0woYP53oPSbzRTgPjDqByCk9pb5vtl14-4K7R7juNi0sIgf4Gole9TwfqHNgNDTGwH7GFoAs4HPkdHcNiFwDwmUwCeGyF3Cms0w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