<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/113077>113077</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong ICmp folding of `and` and `or`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bonjune
</td>
</tr>
</table>
<pre>
https://github.com/llvm/llvm-project/blob/11dad2fa5138a50d60a5a34a2c7e074b976820e2/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L770-L803
The case below runs the code above:
Alive2 report: https://alive2.llvm.org/ce/z/aRCvwb
```
----------------------------------------
define i1 @f(i32 %k, i32 %c1, i32 %c2) {
#0:
%t = shl i32 1, %c1
%#1 = and i32 %c2, %t
%t4 = lshr i32 2147483648, %#1
%t1 = and i32 %t, %k
%t2 = icmp eq i32 %t1, 0
%t5 = and i32 %t4, %k
%t6 = icmp eq i32 %t5, 0
%or = or i1 %t2, %t6
ret i1 %or
}
=>
define i1 @f(i32 %k, i32 %c1, i32 %c2) {
#0:
%t = shl nuw i32 1, %c1
%#1 = and i32 %c2, %t
%t4 = lshr exact i32 2147483648, %#1
%#2 = or i32 %t, %t4
%#3 = and i32 %k, %#2
%or = icmp ne i32 %#3, %#2
ret i1 %or
}
Transformation doesn't verify!
ERROR: Target's return value is more undefined
Example:
i32 %k = #xc0000001 (3221225473, -1073741823)
i32 %c1 = #x00000000 (0)
i32 %c2 = undef
Source:
i32 %t = #x00000001 (1)
i32 %#1 = #x00000000 (0) [based on undef value]
i32 %t4 = #x80000000 (2147483648, -2147483648)
i32 %t1 = #x00000001 (1)
i1 %t2 = #x0 (0)
i32 %t5 = #x80000000 (2147483648, -2147483648)
i1 %t6 = #x0 (0)
i1 %or = #x0 (0)
Target:
i32 %t = #x00000001 (1)
i32 %#1 = #x00000000 (0)
i32 %t4 = #x80000000 (2147483648, -2147483648)
i32 %#2 = #x80000001 (2147483649, -2147483647)
i32 %#3 = #x80000001 (2147483649, -2147483647)
i1 %or = #x1 (1)
Source value: #x0 (0)
Target value: #x1 (1)
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errors
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vl9v4rgX_TTmxQLZ106cPOSBlkEaaaSR-qv021cnccDTYLO2Q9v99Ks4gSbA7s5WOxGCGJ97fO4fX13pvd4ZpQqUPKBks5Bd2FtXlNb86IxalLZ-L_YhHD1iawRbBNudDvuuXFX2gGDbtqfzz_Lo7A9VBQTbsrUlgi2ltayhkQllmUxInRKZSMYlVEIRwctcpBkQBRMe3ds9O2l8Y93BI9h-NT482kOpjZqv1qb-7n6zblUdjwjYNyHI8ltGGCIbRNbD9_Ne4Up6hUvV2lfsOuNx6P-ztcKytCfVuzUxWLf6pAA7dbQuILbGc99l3F71alfW7RBsq17VH_3W0-PptRy5UjJ-4nL5k8-ArlWjjcKaYsRJgyDTDDCC5AXBIx7fKzpdAIIcI_EwHg6MXLzCPSBgxDbY79toEU0Hjg8IAkYjSpp6yhuRYcrFI6z1exdxQLngGUt5NoJ7pin-hjaMwJcpCiJKV4cjVr9fkFEqmeKSGzZ-jy69S5dc01kXcdbFaPcyzh6nZ5RTYdy0boyv2IwvbIPYl1-fNNO93k_cZ_Om3mQVfip7CBhcQjRPX-BzHLuW8fJBCbcxj7npIzaAe4Jb_N8E_9IjZNDW4NoqbxCIgE_K6eYdAZ1e6y9PT9-f-uv8LN1OBQTC9-SdM_gk205h7fHBOoU7M2Synlm_ycOx_WgVZwejIwjYW0Xi0yvNGAAFSLiI_iwpEUxwmgFDkM_MK3qxJ-PT25Mb3JCBqGyq6n-2c9WNqHBNGkXRa9JL3dw_PkfJQym9qrE1w8lDnFCymZ_GLyTZhGReVsvpci4j3Ii4lksn7SHC7sZo7Auf0EEn_eIeP53U7J39sRiHqvolqfgPo325zRMGOmPI5wziDgP7LMN1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