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

    <tr>
        <th>Summary</th>
        <td>
            [RISCV] Assertion failure from std::optional in VLOptimizer
        </td>
    </tr>

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

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

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

<pre>
    This test case causes VL optimizer to access the value of an unset std::optional. https://godbolt.org/z/cPccraWM6

```
 source_filename = "reduced_2.ll" 
  target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128" 
  target triple = "riscv64-unknown-linux-gnu" 
 
  define i32 @pps_is_equal(<vscale x 16 x i1> %0, <vscale x 16 x i1> %1) #0 {    
  entry: 
    %2 = tail call <vscale x 16 x i1> @llvm.vp.or.nxv16i1(<vscale x 16 x i1> zeroinitializer, <vscale x 16 x i1> zeroinitializer, <vscale x 16 x i1> %0, i32 1)
    %3 = tail call i32 @llvm.vp.reduce.smax.nxv16i32(i32 0, <vscale x 16 x i32> zeroinitializer, <vscale x 16 x i1> %2, i32 1)
    ret i32 %3 
  } 
 
  declare <vscale x 16 x i1> @llvm.vp.or.nxv16i1(<vscale x 16 x i1>, <vscale x 16 x i1>, <vscale x 16 x i1>, i32) #1
 
  declare i32 @llvm.vp.reduce.smax.nxv16i32(i32, <vscale x 16 x i32>, <vscale x 16 x i1>, i32) #1
 
  attributes #0 = { "target-cpu"="sifive-x280" }                                 
 attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVdtu4zYQ_RrqZSBBGlq3Bz04cQ0U2KJFt0gfA5oa2-xSpMqL4-TrCyrOZput011gDcE2hjM8Z85cJLxXB0M0sPqG1ZtMxHC0bgh2nsnJbGfHx-GPo_IQyAeQwhNIET15uPsAdg5qUk_kIFgQUpL3EI4EJ6Ejgd2DMBCNpwA-jIyvGV-nEGuELuAYwuyTEbcMtwc77qwOhXUHhtsnhlv5m5RO_PlLw8p1epry8pRr8DY6Sfd7pcmIiYDxDTBER2OUNN5joTVDhOQKQbgDBRhFEFo82hhevCmfGF9TPjO-blbLV64-_6mwY3xdYZcbjs-2j8n25trg1KxfCSgvT80qj-aTsQ8m18rEc34w8SVsCR1prwyB4ghsVc6zv1f-nv6OQrMEenvyUmiCM1QNnEFVjP8EDOuS4S1cP64Y9sCQl8DaGwB4xiIT3CPjF2RIjriwDUJpkELrq1euSq1PU3GaC-sKcz5VjaquE3wiZ5VRQQmdOuIdrt_u-ZJ0Uiql95oDf5PDRcsXws-NUPhJnC_MOTLsktcVFVONv5Ma_gc1R-GZy0Ix2Vi7-bLyUgtHP0by6-zeP1m0WFql-orYN-v4jorfjy5CcGoXA_lLA6dpam_SRD2PWS7nNEKMbxiiV3t1ovyMXbmMVbuB__sklH-DVJ9BjE0dtBPyExi7d0RgrH80EoyN5kGZER6U1o5CdAYmmqx7ZNgZa2jJo918uZyyceBjz3uR0VC1q6Yru3bVZ8eh7bAqK96Ivul5O4pu1Y6y6boGm06Mos7UgCXWZV32VcP7sivGkddjWfdVL9pd2XO2KmkSShdLcaw7ZMr7SEPFe-y6TIsdab-scURDD7CcJtHqTeaGFJTv4sGn6iof_Os1QQW97P_ff_54e8fqDay9J5f2NOyF0tER7J2dvl7ioAzcffj15S2QRaeHN2tdhWPcFdJODLcJ8fKTz87-RTIw3C48PcPtJZHTgP8EAAD__7me7Bc">