[llvm] [AArch64] Eliminate Common Subexpression of CSEL by Reassociation (PR #121350)
Marius Kamp via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 3 02:05:18 PST 2025
mskamp wrote:
> Hi - Am I right in thinking that any condition would be valid if we were just reassociating the adds and use the same constant? (As in https://alive2.llvm.org/ce/z/X7pFRT). The conditions allowed by this patch are to do with having to alter the constants to match the SUBS?
If we have an (icmp cc %a, const) and a (add (add %a, %b), -const), we can reassociate the adds and remove the comparison instruction by using a SUBS instruction. The motivating pattern for this PR, however, was slightly different: If we have a (icmp eq %a, 0) and a (add (add %a, %b), -1), we can change the comparison to (icmp ult %a, 1) and then perform the transformation stated before. Currently, the implemented transformation mainly targets the latter case (with some generalizations) but it is probably better (and might even be easier to read) to extend the transformation to handle the former case, too. I'll adapt the implementation accordingly.
> Do you have any tests where the type of the CSEL is different from the type of the SUBS?
I can add such tests but I'm wondering whether they are useful. If the SUBS has a different type than the operands of the CSEL, the operands of the SUBS used for comparison and the ADD won't match (as they must have different type) or the operands of the CSEL wouldn't be chains of ADD instructions. Hence, the transformation as implemented would not apply. Or am I missing something here?
https://github.com/llvm/llvm-project/pull/121350
More information about the llvm-commits
mailing list