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

    <tr>
        <th>Summary</th>
        <td>
            Missed optimization: eliminate redundant null pointer check
        </td>
    </tr>

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

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

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

<pre>
    ```
define i1 @src(ptr %arg0) {
  %v0 = getelementptr inbounds nuw i8, ptr %arg0, i64 24
  %v1 = load i32, ptr %v0, align 8
  %v2 = icmp eq i32 %v1, 14
  %v3 = icmp ne ptr %arg0, null
  %v4 = and i1 %v3, %v2
  ret i1 %v4
}

define i1 @tgt(ptr %arg0) {
  %v0 = getelementptr inbounds nuw i8, ptr %arg0, i64 24
  %v1 = load i32, ptr %v0, align 8
  %v2 = icmp eq i32 %v1, 14
  ret i1 %v2
}
```

Alive2: https://alive2.llvm.org/ce/z/-wS56j
Godbolt: https://godbolt.org/z/sbnj71bqa

Found the pattern in https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/llvm/optimized/DAGISelMatcher.ll
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUk8FuuzgQxp9muFiNzICTcOBAG1Htoac-gYEJuDU2tU3S5ulXdrNJtyvt_S9FkfD85vN8H4z0Xo2GqAbxCOKQyTVM1tWXzyCyzg5fNWz59cebgY7KEFM5g5J71wPul-AYoJBu5IAVg90j8IbFoxNnUBzYSIE0zWRCRJXp7GoGz8x6ZmoP-MT-pfDE1LZkWN5E8iSirRyYKvAHf0q01Go0bH_DMeGqnxdGH7HjWySi-V20uFOGfg9gVq1vZJlIaYZkOrZGJN2UGEfhn0qUh90h_v9KKozhT0zqhze8e_vxOQBvGq1OhFA0bAph8VA0gC1gK9P5RuvTvLFuBGx7AmwvgO3D-VVs34A3z3borA7_bR6_C9fG2OM787bLuw_5fWsbk2FhIrbIEMgZpsxvDRWmtdv0dgZsh9B_Xr7OgG0c6MEu4aEj00-zdO-AbadtB9jOUpn4FCtXFLC1S1CzutAA2B6a579eSb_I0E_kNlpnQ10MVVHJjOp8J0TJMc9FNtW0zY-iP5ZYIfZc4O7IebHPJa8Q85wfM1UjR8H3-Y4XZS7EpqBiW-4HXuJ-K48ooOQ0S6VvGWbK-5XqXBRVVWVadqR92lpEQ2eWqoAYl9jVyWe3jh5KrpUP_i4TVNBUvyjvaWBXdzIoa-KLIK1mZWQg5mhYzSBNSAvBFqtMIMf6ifr3bHW6_p-8r9GlIRZn36gPgG2a0AO2VwunGv8OAAD__-nNU40">