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

    <tr>
        <th>Summary</th>
        <td>
            Missed optimization: fold (x & C1) == C2 to x == C2 when C1 & C2 == C2
        </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 8
  %v1 = load i32, ptr %v0, align 8
  %v2 = and i32 %v1, 255
  %v3 = icmp eq i32 %v2, 17
  ret i1 %v3
}

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

Alive2: https://alive2.llvm.org/ce/z/tjnF6d
Godbolt: https://godbolt.org/z/9rrPhKE5b

Pattern found in: https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/llvm/optimized/AArch64TargetMachine.ll
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykk82O2ywUhq_meIMmwsfGsRdeeJLP36IaaRa9AWzO2EwxpJj8TK6-MomS9EdVq0pRJDgPr3kOIOdZD5aoBvEMYpvIfRidr8-nIJLOqY8aCn798UbRm7bEdMog57PvActd8AxQSD9wwIrB-hl4w5apA2eQbdlAgQxNZMOCatu5vVUzs_sj0yXghn2XsGG6yFl5y0hjhnFSMZ3hA36IsDR6sA84RlzaSF8CFgyFuCFZRHQ_7Rh9vWExOl1HylOIigsMvIH1dvn_wT4M4R_s_9K8_EPxm1V5d79IPTjh3enhaIE3jdEHQsgaNoawmyFrAFvAVsb5lTGHaeX8ANj2BNieAdvwbttCAW_-d6pzJvy8eLgUrguXNZX3r-On_0R3-eqrDIG8ZW9LZ5i2v4jQYdx3q95NgK0K_en8cQRsl_08uV146sj24yT9F8C2M64DbCep7TJaKlcUsHW7oCd9JgXYNo3vxyL_LP1A4UX2o7a0MiZRdaaqrJIJ1elaiLwQouDJWHOSfJ13lVJdn6qCMpJ53imVZlWe5lma6Bo5Cl6ma0zTCvmqKAlFlnUil7nAsoKc0yS1uTUy0fO8pzoVOc9EYmRHZo7PENHSkcUqIC6v0tfRttsPM-Tc6DnM95igg6H6Rc8zKXZ1lEG72Mo3ZxQDLE8MsGCbNF7TbLvclg2y4NjpYXgcybJNekHxXkj23tS_OZRrf-Med969Ux8A2ygwA7ZXw0ON3wIAAP__ZP1IuA">