<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96130>96130</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong canonicalization by InstCombine
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bonjune
</td>
</tr>
</table>
<pre>
https://alive2.llvm.org/ce/z/Fv6zpv
https://github.com/llvm/llvm-project/blob/da0e5359fc1a5bf1749306440f9dad089046d772/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp#L1656-L1665
```
----------------------------------------
define i10 @src(i10 %val0) {
entry:
%val1 = urem i10 %val0, 42
%val2 = sub i10 0, %val1
%val3 = and i10 %val1, %val2
%val4 = add i10 %val3, 1023
ret i10 %val4
}
=>
define i10 @src(i10 %val0) nofree willreturn memory(none) {
entry:
%val1 = urem i10 %val0, 42
%#0 = add nsw i10 %val1, 1023
%#1 = xor i10 %val1, 1023
%val4 = and i10 %#0, %#1
%#range_%val4 = !range i10 %val4, i10 1023, i10 41
ret i10 %#range_%val4
}
Transformation doesn't verify!
ERROR: Target is more poisonous than source
Example:
i10 %val0 = undef
Source:
i10 %val1 = #x000 (0) [based on undef value]
i10 %val2 = #x000 (0)
i10 %val3 = #x000 (0)
i10 %val4 = #x3ff (1023, -1)
Target:
i10 %val1 = #x000 (0)
i10 %#0 = #x3ff (1023, -1)
i10 %#1 = #x3fd (1021, -3)
i10 %val4 = #x3fd (1021, -3)
i10 %#range_%val4 = poison
Source value: #x3ff (1023, -1)
Target value: poison
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errors
```
The transformation does not properly handle `undef` as a result of `urem i10 %val0, 42`.
`undef` propagates to intermediate instructions.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysll1r4zgUhn-NciNS5CN_XvgibSawMLDQGdjLRbaOEw2yFC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