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

    <tr>
        <th>Summary</th>
        <td>
            [EarlyCSE] Miscompile with llvm.maximumnum.f64 and llvm.maximum.f64
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          patrick-rivos
      </td>
    </tr>
</table>

<pre>
    Testcase:
```llvm ir
source_filename = "test.ll"
target triple = "x86_64-unknown-linux-gnu"

define i64 @main() #0 {
  %zext.1 = zext i32 -2147483648 to i64
  %zext.2 = zext i32 2147483647 to i64
  %shl.1 = shl i64 %zext.2, 32
  %or.1 = or i64 %zext.1, %shl.1
  %call.1 = call i64 @float_fn(i64 44, i64 %or.1, i64 4, ptr null)
 %add.1 = add i64 %call.1, 0
  %bitcast.1 = bitcast i64 15 to double
 %bitcast.2 = bitcast i64 %add.1 to double
  %call.2 = call double @llvm.maximumnum.f64(double %bitcast.1, double %bitcast.2)
  %bitcast.3 = bitcast double %call.2 to i64
  %add.2 = add i64 %bitcast.3, 0
  %bitcast.4 = bitcast i64 43 to double
  %bitcast.5 = bitcast i64 %add.1 to double
 %call.3 = call double @llvm.maximum.f64(double %bitcast.4, double %bitcast.5)
  %bitcast.6 = bitcast double %call.3 to i64
  %add.3 = add i64 %bitcast.6, 0
  %icmp.1 = icmp ne i64 %add.2, 15
  %res = zext i1 %icmp.1 to i64
  ret i64 %res
}

define internal i64 @float_fn(i64 %arg0, i64 %arg1, i64 %arg2, ptr %arg3) #0 {
  ret i64 u0x7ff8000000000000
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.maximumnum.f64(double, double) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.maximum.f64(double, double) #1

attributes #0 = { "target-cpu"="skylake" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```

Commands:
```
$ ./llvm/bin/opt good.ll -passes="early-cse" -o bad.bc
$ ./llvm/bin/clang bad.bc -O0 -o bad && ./bad
$ echo $?
130
$ ./llvm/bin/clang good.ll -O0 -o good && ./good
$ echo $?
0
```
Godbolt: https://godbolt.org/z/jExWdcGqx
Alive2: https://alive2.llvm.org/ce/z/WZDPeF (I added the willreturn attribute to get the value mismatch error msg)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVs1u6zYTfRp6Q9ighpRsL7xw4vjiW3xogRa4QDcBRY1t3lCkSlKJc5--oH4c_6XNpkANL0TqzOGcwxlSMgS9t4grkj-QfDORbTw4v2pk9Fq9TL1-dWFSuup99TuGqGRAwteErUnB-r8xrzXVnrB1cK1X-LzTBq2skRK-oQQgYogzYwgAYeso_R4jjV435oQ4LornQkxb-2Ldm50abdvjdG_bPoSwdYU7bZHqQlAiWC21JbAgsKQEOKNk_kDYmlIC-U88xlnW8aZHqjnQKWRiLha8EAsaXSK5QMMl-gSeX4HDwQzM4WD6VEYGAo-Uwwh0fsA5fwHLEmwkGsFKmpE2PY4Sd8bJ-LxLMtOMECl2IEv847Cbb6Kntk0OLxMtgVxW1UAqq2qM65dKAWxcvdRpR0fHhlGHz_Ikv3JtaXAgHcFwAz6teBFyWhM-5PVvk8JUNrNaHnXd1ratZ7tCEFiM789SSwnfTsMg9nyOXyT2ETMkcbmdKWG4tujEdNclcSNc8FvJIzr_ok1jgvyfXPrUInHfovyORcXfWcTvWMQ_s6i4sEiruhmqKD3SsVkHnxM2y0ewx3DWc9lZ_Nn6Hk-meQzpGJhvLg8DG9Fb-VnLpKX9np31jfT77HIIY_f0Q35zooxJtOw43-0W7Ox3nhHhD3TbWhW1s3Qdow-Er2ndhth4t_cYArUuWVxK9UKt23lEal14t4pa19o3bSsaGlStkVGmLXnTxniMrbe0xtr5dwIL6yz2W1qhMtL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