<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJy1Vt9vozgQ_mvIyygIDOTHQx7SJN2r9qLtNbnq9qky4IAvBrO2ybb319_YkJak3dVKp5MI4LHnm88zH-OkMn9ZeMnNA2uU9JK1R2alMY32oqVHbvEqZJ5KYXypChz9g7_tPotZPPv8ySNzL1h7wbK770sGmcwZ8Bq8SeDFAa3zJ8XyNmM4hkNbZ4bLGrgGWoNsTdMakAdcr00mq5TXDBqqNagWp2swJa48e1lCXTCEdpcQp6oz5exgfXkIGLQL-MSzqnli33A_XrSK4Rl4RLxoAx5JRKk9soJ3dmXtc_CmNx0sWCPC4Mo1WDxg3957ndE6_zdH5dwyKkRPzPL1TywzUvkdSR8T5J9iHg5Yhj0shnvNL4BixqEgbJ-F6foqHVdFKFjNFDUsh4NUfT10m14XopKKgWwMr6jAhGNd3pZflM_u8Q6Klmntd6FucaGWFUNyVCOaDYtRcdgImjGNcJZL1VClbTRaUFtpCOA7N2U_w_Vw5vm2x_6NIS2k9710L8YjUw25rJ24LO6bepwSMhg3itdmTA-GqTEm3VJ-J5l-SPoL7h5g3WJdl9YLtjJvBYNHpviB4xircrLvL04VZ6f_RXIkCn6mO4z0y7oLnVvKTUYxpR_ICowEHg88yIXAeexQLHbwXn7kWn7DO4ngR7n9azaB9fLTGGngA-6w3KrtVLhjgnVvmDla5UXTjrlm4jLr0SDIlmalzb4TutXrq6KvKhEhDb3bLe1m9opmR_07P-GHofuE3Z79rNmSsh4eiZ-rKnBtjCRBl2RrCntTONx0mvqBJY52rsapkNnRD-yXeyYMIBCcX2APMIeVwxUnFZKZq8fqy_3XDxYFP1oUDCt6sejxfrW93_yxVuoCoFfPa9SBf4S2QkWdMB63Xx63u8_3O_Q_ciGwpQxDDNziodvuz5uIKD4b4mGeDGf5GL8ecElCCmFi77xqBM-4cVO4IXYQtBjKOnEQ3YZ2m_1qpSAeOn7kFGNPG2TpjHFe8LDZw7kUVFwreVPnUP2i0PzXDjPKF1E-j-Z0RFtTSrXIxxU9ykLWo1aJxdXZin2wTX3shDhwx1n3wF4m_8ZvAodca2y5-JJE0XQ-KhezNE2SSTZJpnka0ekknacxm2dJGLA4mk5nI0FTJrQ90z1CHGi07FszGrrtkoYp3E5Fa-ztaEzWo__OjS9IQEgQkjgMyCSJ_WieZNPkEAfhPA1pmmKnZBXlwncnIf6hGKmFg0xbrBoekFwb_TaJ_wR4UTPmtoIMDTeCLXZtej6uPjjnuuNVYx9rqeDmBbKSZceRY7pwNP8FLtqVTA>53379</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Suboptimal code generated for vectors equality check
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:codegen,
performance
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
d-makogon
</td>
</tr>
</table>
<pre>
[Repro](https://godbolt.org/z/MTc4e48KG)
The code in `@and_reduce` function is an output of instcombine pass run on this function:
```llvm
define i1 @reduce_icmp_eq(<4 x i32> %lhs, <4 x i32> %rhs) {
%cmp = icmp eq <4 x i32> %lhs, %rhs
%r = call i1 @llvm.vector.reduce.and.v4i1(<4 x i1> %cmp)
ret i1 %r
}
```
The code generated for `@sub` function is more optimal than for `@and_reduce`, I guess.
For some reason codegen replaces the comparsion against 0 with comparison against 0xF.
Here is where it's done in the output of `llc -print-after-all`:
```
*** IR Dump After Module Verifier (verify) ***
define i1 @reduce_icmp_eq(<4 x i32> %lhs, <4 x i32> %rhs) #0 {
%cmp = icmp ne <4 x i32> %lhs, %rhs
%1 = bitcast <4 x i1> %cmp to i4
%2 = icmp eq i4 %1, 0
ret i1 %2
}
# *** IR Dump After X86 DAG->DAG Instruction Selection (amdgpu-isel) ***:
# Machine code for function reduce_icmp_eq: IsSSA, TracksLiveness
Function Live Ins: $xmm0 in %0, $xmm1 in %1
bb.0 (%ir-block.0):
liveins: $xmm0, $xmm1
%1:vr128 = COPY $xmm1
%0:vr128 = COPY $xmm0
%2:vr128 = VPCMPEQDrr %0:vr128, %1:vr128
%3:gr32 = VMOVMSKPSrr killed %2:vr128
%4:gr32 = SUB32ri8 %3:gr32(tied-def 0), 15, implicit-def $eflags
%5:gr8 = SETCCr 4, implicit $eflags
$al = COPY %5:gr8
RET 0, $al
# End machine code for function reduce_icmp_eq.```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1VsFyozgQ_Rp86TIFAmJz8MGxndnUrGuysTe1e0oJIdvaCMRIwpPM129L4AQ7mam5TBXBqKV-_dT91EqhypdZkF3f80arIFsGZHqwtjFBMg_IDT57VRZK2lDpPY6-4996y1KeTj9_CkgeRMsgmnfv7YEDUyUHUUNwFQVpROvyUfOyZRzHsGtrZoWqQRigNajWNq0FtcP1xjJVFaLm0FBjQLc4XYM94MqTlyPUBUNo_0h5rDpTyXfOV8SAQbuAj4JVzSP_ivsJkkUKzyASEiQrCEgmDyYgC3hn186eQzC57mDBGREGVy7B4QH_-t7rhNb5vzlq78aolD0xxzc8cmaVDjuSISYoPKYiHrCMe1gM95pfAM2tR0HYPguT5UU6Loqw5zXX1PISdkr39TBtcVmISmkOqrGiohITjnV5W35WPrfHW9i33JiwC3WDC42qOJKjBtFcWIyKw0ZSxg3COS5VQ7Vx0eieukpDBN-EPfQzwgxnnm967D840kJ63w7-wwZkYqBUtReXw31Tj1cCg3GjRW3HdGe5HmPSHeV3kumHpH_g9h6WLdZ17rxgrcpWcnjgWuwEjrEqR_f94lVxcvotkiNJ9DPdYaRf1l3s3QphGcWUfiArsApEOvAgZwIXqUdx2NF7-ZFL-Q3fJIEf5faf6RUs55_GSAN_4BbLrdtOhRsuefeFmaNVuW_asTBcnmc9GQRZU3Zw2fdCd3p9VfRFJRKkYTabudvMVlP2ZP4URzwYpk_YzcnPmR0p5xGQ9LmqIt_GSBZ1SXamuDfFw00XRRg54mgXelxIxZ7CyJ3cE2EAieDiDHuAOawcrjjqmEx9PRZf7v79YFH0o0XRsKJn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