<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/154387>154387</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AArch64] AND optimization does not work if there is a freeze between AND and the cmp
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
AZero13
</td>
</tr>
</table>
<pre>
Here is a case from the real world where this happens:
define i1 @test_disjoint(i1 %0, i32 %1, i32 %2) {
%3 = or disjoint i32 %2, 8388608
%4 = shl nuw i32 1, %1
%5 = and i32 %3, %4
%6 = icmp eq i32 %5, 0
%7 = select i1 %0, i1 true, i1 %6
ret i1 %7
}
We get:
test_disjoint: // @test_disjoint
mov w8, #1 // =0x1
orr w9, w2, #0x800000
lsl w8, w8, w1
and w8, w9, w8
cmp w8, #0
cset w8, eq
orr w8, w0, w8
and w0, w8, #0x1
ret
There are many ways to solve this problem.
In the short term, I guess we can fix this by special casing it. However, I am not sure of if this will be safe every time.
In all honesty, I think that perhaps this optimization should not be done at all in the long term. Why? This seems more like a peephole optimizer job.
So, my solution to this problem, and yes this definitely will not catch all cases because this works on a different domain to the SelDAG, is https://github.com/llvm/llvm-project/pull/153608, but also we don't do the replace all users in GISel anyway, so this benefits that too.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVcGOozgQ_RrnUtrIGAjkkAPTUWb6spceaaS9rAwUwd3GZlymaebrVzakO63RarUcgMSvXr16VdiSSF0N4onlX1h-3snJ99adqr_Q2STd1bZdTt_QISgCCY0khM7ZAXyP4FBqmK3TLcx9wPheEfRyHNEQSyvGqxY7ZRBUAizjHsn_3Sp6tsp4Jsrwr8g5Ew-gUhHek7t3wcQRWPGF8QrC7xRYegbr4MZwB3yAMi3LAy9v4CyCqddgpjkCI3VMsUHyCJGmvfGkGyILCCbyQwSoZhgBf95AeQDxG0expkGNjYf7chLwbsLtN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