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

    <tr>
        <th>Summary</th>
        <td>
            SLPVectorizer produces use-before-def after 03b118c
        </td>
    </tr>

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

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

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

<pre>
    While doing some work internally, we encountered a test case where the SLP Vectorizer pass was creating a use-before-def which we bisected back to change 03b118c7e456e9b4d66891aca68401761aa94bdd.

Consider the following code:
```
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-sie-ps5"

define void @_Z3fooP3bar() {
.thread:
  %0 = extractelement <2 x i1> zeroinitializer, i64 0
 %1 = extractelement <2 x i1> zeroinitializer, i64 0
  %2 = fcmp ole <2 x double> zeroinitializer, zeroinitializer
  %3 = extractelement <2 x i1> %2, i64 0
  %4 = extractelement <2 x i1> zeroinitializer, i64 0
  br label %5

5:                                                ; preds = %.thread
  %6 = select i1 false, i1 false, i1 false
  %7 = select i1 %6, i1 %0, i1 false
  %8 = select i1 %7, i1 %1, i1 false
  %9 = select i1 %8, i1 false, i1 false
  %10 = select i1 %9, i1 %3, i1 false
  %11 = select i1 %10, i1 %4, i1 false
  br i1 %11, label %12, label %13

12:                                               ; preds = %5
 ret void

13:                                               ; preds = %5
  ret void
}
```

If you build this with opt and run the SLP Vectorizer pass, it generates IR which contains a use of %1 before the definition which then triggers an error about a broken module:
```
$ ~/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt --passes=slp-vectorizer repro2.ll -o - -S --print-after-all
*** IR Dump After SLPVectorizerPass on _Z3fooP3bar ***
define void @_Z3fooP3bar() {
.thread:
  %0 = shufflevector <2 x i1> zeroinitializer, <2 x i1> %1, <4 x i32> <i32 0, i32 0, i32 0, i32 2>
  %1 = fcmp ole <2 x double> zeroinitializer, zeroinitializer
  br label %2

2: ; preds = %.thread
  %3 = select i1 false, i1 false, i1 false
  %4 = freeze <4 x i1> %0
  %5 = call i1 @llvm.vector.reduce.and.v4i1(<4 x i1> %4)
  %op.rdx = select i1 %5, i1 false, i1 false
  %op.rdx1 = select i1 %3, i1 %op.rdx, i1 false
  br i1 %op.rdx1, label %6, label %7

6: ; preds = %2
  ret void

7: ; preds = %2
  ret void
}
Instruction does not dominate all uses!
  %1 = fcmp ole <2 x double> zeroinitializer, zeroinitializer
  %0 = shufflevector <2 x i1> zeroinitializer, <2 x i1> %1, <4 x i32> <i32 0, i32 0, i32 0, i32 2>
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:
0.      Program arguments: /home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt --passes=slp-vectorizer repro2.ll -o - -S --print-after-all
 #0 0x0000558027a2387f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x35b787f)
 #1 0x0000558027a20fd4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f978c0e5420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f978bbb200b raise /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #4 0x00007f978bb91859 abort /build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:81:7
 #5 0x0000558024cd8f26 llvm::RISCVISAInfo::updateImplication() (.cold) RISCVISAInfo.cpp:0:0
 #6 0x00005580279752fe (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x35092fe)
 #7 0x0000558027396d83 (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x2f2ad83)
 #8 0x0000558024db7e16 llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x94be16)
 #9 0x000055802735b5ed llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x2eef5ed)
#10 0x0000558024dc39b5 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) (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x9579b5)
#11 0x0000558024ce38f3 main (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x8778f3)
#12 0x00007f978bb93083 __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:342:3
#13 0x0000558024db6f3e _start (/home/dyung/src/upstream/03b118c7e456e9b4d66891aca68401761aa94bdd-linux/bin/opt+0x94af3e)
Aborted
```
@valerydmit this appears to be a change you made, can you take a look?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWUtv4zgS_jXKpWBDIvU8-OB0Ymyw3ZggGfQCezEosWRzmyYFkkriHPa3L0jZsZXYO-nHBANM4MgSWS9WFb9iycxasVKIsyi7jLKrC9a7tTYzvu3V6qLWfDv711pIBK6FWoHVG4RHbb6BUA6NYlJuI_IJHhFQNbr3g8i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