<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/114350>114350</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] miscompilation folding `or`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bongjunj
</td>
</tr>
</table>
<pre>
The following lines are executed:
https://github.com/llvm/llvm-project/blob/948249d80483a85c2f20b709d977e124473dd10b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L3897-L3903
Alive2 report: https://alive2.llvm.org/ce/z/wCsYN9
```llvm
----------------------------------------
define i1 @or_simplify_ule.2(i8 %y_in, i8 %rhs_in, i1 %c) {
#0:
%y = or i8 %y_in, 1
%rhs = and i8 %rhs_in, 254
%#1 = sub i8 %y_in, 3
%lbo = or i8 %y, %#1
%r = icmp ule i8 %lbo, %rhs
ret i1 %r
}
=>
define i1 @or_simplify_ule.2(i8 %y_in, i8 %rhs_in, i1 %c) {
#0:
%rhs = and i8 %rhs_in, 254
%#1 = add i8 %y_in, 253
%y = or i8 %y_in, %#1
%r = icmp ule i8 %y, %rhs
ret i1 %r
}
Transformation doesn't verify!
ERROR: Target's return value is more undefined
Example:
i8 %y_in = undef
i8 %rhs_in = #x00 (0)
i1 %c = poison
Source:
i8 %y = #x01 (1) [based on undef value]
i8 %rhs = #x00 (0)
i8 %#1 = #xfd (253, -3) [based on undef value]
i8 %lbo = #xfd (253, -3)
i1 %r = #x0 (0)
Target:
i8 %rhs = #x00 (0)
i8 %#1 = #x00 (0)
i8 %y = #x00 (0)
i1 %r = #x1 (1)
Source value: #x0 (0)
Target value: #x1 (1)
----------------------------------------
define i8 @or_simplify_ugt.2(i8 %y_in, i8 %rhs_in) {
#0:
%#1 = add i8 %rhs_in, 3
%y = or i8 %#1, 1
%rhs = and i8 %rhs_in, 254
%lbo = or i8 %y, %rhs
ret i8 %lbo
}
=>
define i8 @or_simplify_ugt.2(i8 %y_in, i8 %rhs_in) {
#0:
%#1 = add i8 %rhs_in, 3
%y = or i8 %#1, %rhs_in
ret i8 %y
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
i8 %y_in = poison
i8 %rhs_in = undef
Source:
i8 %#1 = #x03 (3) [based on undef value]
i8 %y = #x03 (3)
i8 %rhs = #x00 (0) [based on undef value]
i8 %lbo = #x03 (3)
Target:
i8 %#1 = #x04 (4)
i8 %y = #x04 (4)
Source value: #x03 (3)
Target value: #x04 (4)
Summary:
0 correct transformations
2 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errors
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMV19r6zYU_zTKi2iQjuzYfvBD2tzA4LILXRnbU5EtOVGRrSDZabNPP2S7ie0mzU0Z45aiRNHv_Nf5ccSdU5tKyhSF9yhczXhTb41NM1NtXprqZZYZcUifthIXRmvzqqoN1qqSDnMrsXyTeVNLgdgSkRUiy21d75zfwRrBeqPqbZPNc1MiWGu9f_-421nzIvMawTrTJkOwToIYgkTEJIgZj8McCiBZRBKRRJGkEAQRE4KSbKBH-c2T5ZUrjC0dgvVvlasfTJmpSo53y0r8sH8ZO893OwTsO4uT6O47SwjrvO7WpVZ7CdjKnbE1Yks8Doa3x3Nvfm7sBsE692b-QbB-fXB__54MdfXrgnT_rc_tT3c_-dehhSxUJbGiGAXE2Genyp1WxeG50XIOCGIVYwTh4VlVCB5wt7Nb976nfp8jSDCK7nufgJFjuXArjRFbYWPxWBkdQOzWtSBeiQ9GIAwGSASMtlDXZBOFbADTmZlY9Yhefmi4Ram83OFGyx6rM9Oj7da9g62s-3htH2i06r-wFWLf_seEfiFbXIhJtiBk12v0kwk73JKuY0vxWpkKCyNdhSCq8V5aVRwQ0OEV__b4-OPRN8sTtxtZI4ic193YCu-5biRWDpfGStxUXe7FSPqNlzstj-k7RdeG0coMT7o8tmcI2BshGEFMEPS915enPd8Z5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