<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/120361>120361</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] `samesign` should be dropped when folding logical and of icmps
</td>
</tr>
<tr>
<th>Labels</th>
<td>
miscompilation,
llvm:instcombine
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
dtcxzyw
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dtcxzyw
</td>
</tr>
</table>
<pre>
Reproducer: https://alive2.llvm.org/ce/z/YSW_NC
```
define i1 @src(i8 %0, i8 %1) {
start:
%2 = icmp samesign eq i8 %0, -1
%3 = icmp ne i8 %0, 0
%4 = icmp ugt i8 %0, %0
%result = select i1 %3, i1 %2, i1 %4
ret i1 %result
}
define i1 @tgt(i8 %0, i8 %1) {
start:
%2 = icmp samesign eq i8 %0, -1
ret i1 %2
}
```
```
----------------------------------------
define i1 @src(i8 %#0, i8 %#1) {
start:
%#2 = icmp samesign eq i8 %#0, 255
%#3 = icmp ne i8 %#0, 0
%#4 = icmp ugt i8 %#0, %#0
%result = select i1 %#3, i1 %#2, i1 %#4
ret i1 %result
}
=>
define i1 @tgt(i8 %#0, i8 %#1) {
start:
%#2 = icmp samesign eq i8 %#0, 255
ret i1 %#2
}
Transformation doesn't verify!
ERROR: Target is more poisonous than source
Example:
i8 %#0 = #x00 (0)
i8 %#1 = poison
Source:
i1 %#2 = poison
i1 %#3 = #x0 (0)
i1 %#4 = #x0 (0)
i1 %result = #x0 (0)
Target:
i1 %#2 = poison
Source value: #x0 (0)
Target value: poison
```
Reported by https://github.com/dtcxzyw/llvm-mutation-based-fuzz-service/issues/14 while reviewing https://github.com/llvm/llvm-project/pull/120177.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VcuO4zYQ_Jr2hfCAakp-HHTwjtdALgngXSDIKaDElsyAEhWS8jy-PhBljTSTgTc5rGHYtFmsruoSSem9rluiHLIvgKhC-fz68gSIkB1Xsg8X6_Lbn6vCqpf8TJ2zqi_JgTiwSwidB3EAPAGepNFXwgdjrs2DdTXgqSTA0yvg6Y9vv__56yPwA2z47c0PiirdEtMJg5R7VwLu9I4BZhzwkY3DBHDPYPsF-MEH6cJQjB_YMIUMxJHpsumYlw0NRhj9zRYU62TCihk7VJwhfEKkM6KvwxISv28oR743IUI9GSpDVI-ZiIrjEOdhGpc5mlDj6qEL2-Pw-aEFoQ4_qwWzBpzLL6J4N-aH9X983QsRUCxMAIo7PgDFXSsTF2bZYslnoU5IvsB9Gu0EnIY_CHgoNwc76H3360dJiyOIr_fy_pndmmVF3ZOo7062vrKukUHblilLvgXcBnYlp6sXwGR8GL6ez7-dh93-Xbp6oPKssY5YZ7W3re09CxfZMm97V9JtybNsOkOj5llUFA0onjlngDsOuF_OJ3F-pB15vo2cI03yzvsbbM5npl-yJ--egs-nF6l_BAyNir7vqxiVsqs0_aD3XzS33r3Nzy4XO-9MnXWBFCtePhyttQ6XvngobQN4ejulT8NRu276EBNcF9KTWlf96-vak7vqePpq73vygKckZU8XbYg5ump60m19r8bAPBXonP2LygB46npjBirkyXb7MHYH-GGlcqH2Yi9XlCdbkab7_WaTri45CbUphCTF5U5RVfGsVLstLwqJssrKaqVz5JgmmOx4hts0fZApr8R-UxLueUJ8DymnRmrzdqusoqE8QS42ycrIgoy_3V6N9qVtOm1iO4ZLDB8BMVoRB936UNqm0C3d7jeXR3tFX3tIudE--LlM0MHEa_GX1ofH27rsyGDDpx0HG878xfZGsYKYcrbrSLGnC7WsskYNHTa21qU0TLaK2SpuWL_qncn_d-vnHEfn1xz_CQAA__908SMN">