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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] Miscompilation in `simplifyWithOpReplaced`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            miscompilation,
            llvm:instcombine
      </td>
    </tr>

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

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

<pre>
    Reproducer: https://godbolt.org/z/dzn8c8eYj
```
; bin/opt -passes=instcombine test.ll -S
; ModuleID = 'test.c'
source_filename = "test.c"
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"

@f = dso_local global [2 x i32] zeroinitializer, align 4
@__const.g.n = private unnamed_addr constant [1 x ptr] [ptr getelementptr (i8, ptr @f, i64 4)]

define void @g() {
entry:
  %n = alloca [1 x ptr], align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %n) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %n, ptr align 8 @__const.g.n, i64 8, i1 false)
  %0 = load ptr, ptr %n, align 8
  %cmp3 = icmp eq ptr %0, null
  %1 = load i32, ptr %0, align 4
  %and = select i1 %cmp3, i32 %1, i32 0
  store i32 %and, ptr %0, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %n) #4
  ret void
}
```
```
define void @g() {
  store i1 true, ptr poison, align 1
  ret void
}
```
```
IC: Visiting:   %cmp3 = icmp eq ptr getelementptr (i8, ptr @f, i64 4), null
IC: Visiting:   %0 = load i32, ptr getelementptr (i8, ptr @f, i64 4), align 4
IC: Visiting:   %and = select i1 %cmp3, i32 %0, i32 0
ADD DEFERRED:   %0 = load i32, ptr null, align 4
IC: Mod =   %and = select i1 %cmp3, i32 %0, i32 0
    New = %and = select i1 %cmp3, i32 %0, i32 0
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVk1v4zYQ_TX0hZBBjT590MFZrYE9pAWyQIueDFocK9xSpEpSSZxfX5CW7TibNLtbwJA50pv33nBGH9w52WvEhhQ3BED47un58EgASNEu-OTvjW3mk4udEYfmDkdrxNShJdma3ns_OpKtCWwIbHojdkb5pbE9gc0zgY141nVX41_fCGsJW5OSzb9jmN3QndQENmb0NBm5c-hI1krtfGeGndRIPTq_VIomXy85t0ZMCr-0lGQtJVBFTEegOkKcmWyH271UqPmAMwpOKDiiPLc9eiq454ofzORPOEwGkq0xGaFiJFtnEA8hTK_DsCrzeEjkeZFCTbJ1CnWyr9m80vFUeUov8-RrgL2y4q0c1dnuU11uyzyZ9N_aPOpEST09Jb2ezlnzMWf7mCKc2SrTcUV7ZXZcUVLcAH2iMgu9pM9ojdTSS67kM1oCnyhXstc0P_Nst53Rzi_7pY6Mo5UP3COddNhGseVCWBohXPtAn9InOnob6ElxM3pLe_SocEDtQ0SglnVQikHO9mEty5zmBFakaF_WIXAf2v1gpAjQnoT9WVFS3Ryvo_b2ECYtRpQSKI4uuQpVX9u5VFef8B1X6syu1MOwVHKPXg64dJ5bvxxZsFvm9OIYCh09QJa_TzPg0I2H5cjCL4wB1CF5lp9JjoTnc1d7fdqUqCtTuufKYdigS6UsVqoMF7HAK3_fVUqg6IYxiymyG0aK_5zgLMD1pNQLbHrhDqNy4WbfzUjEcy1ihkOFnQ-GZ8FoP4PIeVqzU6LzxuLpMtfiA53_6BZq8YO9sugjxzxmVfv2Q-g6_GgOz6Wk1NsJT_qjkc686Eb6v0x8-RQern9IJ73UfVi_39afueWuuv-OCHtzHn5S5aqd7wj9yCCxV4O0blvaft58vrv73H7gOBb6tpVbc1T-ZRuUUvobPs6P6l-ieNXxhWgyscpWfIFNWkEKdZbV9eK-STmU1Qp2Ii9qvmcpZqIsugKw2pdVmqcL2QCDnFVpzcq0hGopUqwEB9bldZ7mIEjOcOBSLeN9ZGy_kM5N2KxWeVYuFN-hcvPrf5CuM8MoFfcyTHPYTAIQEkm2fvFanj8QbBMuJbupd-E-lc67i4qXXsXvii_a-U9zXtHS2ysRKjUlJXNyGJXcH_6U_v738Q5HxTsUpGSLyarm1WeG9PfTbtmZgcAmejv-JaM137DzBDaxQkdgcyzyoYF_AwAA__9Px4Kr">