[llvm] [AArch64][SVE2p1] Remove redundant PTESTs when predicate is a WHILEcc_x2 (PR #156478)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 5 10:04:26 PDT 2025
paulwalker-arm wrote:
As discussed, the while pair instructions end like:
```
PSTATE.<N,Z,C,V> = PredTest(mask, result, esize);
P[d0, PL] = result<PL-1:0>;
P[d1, PL] = result<PL*2-1:PL>;
```
So the condition codes are set based on the result of testing the concatenation of the two register results. This means `ptest(while_x2(a,b))` is not the same operation as `ptest(svget(while_x2(a,b), 0))`. There is overlap however, for example when branching on pfirst whereby the two will produce the same result because only the first result of the while pair is relevant.
The problem is when calling `canRemovePTestInstr` we know there's a `ptest` we want to remove but we don't know which part of the condition code will be used and thus we cannot identify which of the while pair results is relevant.
We've hit something similar to this before and solved it by creating the PTEST_PP_ANY pseudo node (there's a matching PTEST_ANY ISD node) that essentially encodes this condition code information. I believe your work requires us to create a PTEST_PP_FIRST equivalent which you can match against to prove it's safe to look through the COPY.
I recommend adding the PTEST_PP_FIRST pseudo and AArch64ISD::PTEST_FIRST support as a separate refactoring PR, which this PR can then build upon.
https://github.com/llvm/llvm-project/pull/156478
More information about the llvm-commits
mailing list