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

    <tr>
        <th>Summary</th>
        <td>
            [loop-reduce] Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"' failed.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:crash
      </td>
    </tr>

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

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

<pre>
    Reduced from https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65323

```ll
; ModuleID = 'bugpoint-reduced-simplified.bc'
source_filename = "llvm/test/Transforms/InstCombine/fold-vector-zero.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-unknown-linux-gnu"

@G = external global i32

define void @foo() {
bb8:
  br label %bb30

bb30: ; preds = %bb30, %bb8
  %l0 = phi i64 [ -2222, %bb8 ], [ %r23, %bb30 ]
  %A22 = alloca i16, align 2
 %r23 = add nuw i64 1, %l0
  %G7 = getelementptr i16, ptr %A22, i64 %r23
  %B15 = urem i64 %r23, %r23
  %G6 = getelementptr i16, ptr %G7, i64 %B15
  %B1 = urem i64 %r23, %r23
  %B8 = sub i64 -1, %r23
  %B18 = sub i64 %B8, %B1
  %G5 = getelementptr i16, ptr %G6, i64 %B18
  store ptr %G5, ptr undef, align 8
  br label %bb30
}
```
opt -passes=loop-reduce
```
opt: /home/simon/LLVM/llvm-project/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From*) [with To = llvm::SCEVAddExpr; From = const llvm::SCEV]: Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"' failed.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU2P3CgT_jX0BbllF_6aQx_c0_EoehPpVSbKNcKm3M0u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