This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Optimize patterns where AND's on same operand with multiple masks can be combined.
AbandonedPublic

Authored by bipmis on Apr 4 2022, 6:30 AM.

Details

Summary

The patch simplifies some of the patterns as below

or(or(and(a, mask1), and(b, mask)), and(a, mask2)) -> or(and(a, mask1|mask2), and(b, mask))

or(or(or(x, and(a,mask1)), and(b,mask)), and(a,mask2)) -> or(or(x, and(a,mask1|mask2)), and(b,mask))

The simplifications allows for generation of single instruction like rev16 on AArch64 when there is a code pattern which does a half word byte swaps on a 64 bit.

Diff Detail

Event Timeline

bipmis created this revision.Apr 4 2022, 6:30 AM
bipmis requested review of this revision.Apr 4 2022, 6:30 AM

Are these patterns actually appearing in the DAG?

bipmis added a comment.Apr 4 2022, 8:14 AM

Yes for some of the examples provided, the pattern is actually seen in the DAG.

can you start by committing the tests to trunk with current codegen and then rebase the patch to show the codegen diff please?

bipmis updated this revision to Diff 420486.Apr 5 2022, 6:39 AM

The patch has been rebased after committing the tests.

RKSimon added inline comments.Apr 7 2022, 2:59 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
6951

This all feels likes it should be performed a lot more generally in a lot less code tbh - you're adding a lot of code just to hit a couple of patterns.

bipmis updated this revision to Diff 422027.Apr 11 2022, 1:33 PM

Adding additional simple tests to show simple scenarios where this optimization will be useful.

Also reduced the code needed to implement it. There are some some additional code sections to maintain the natural ordering of the operands. Also all possible operand ordering has been handled. This is to target a generic implementation.

An alternate implementation with InstCombine IR Pass is at https://reviews.llvm.org/D124119.

@bipmis Whats the plan for this patch? Can the IR pattern appear in DAG or will D124119 handle it in InstCombine?

bipmis abandoned this revision.Jun 20 2022, 2:30 AM

@RKSimon The InstCombine patch D124119 can now handle this and the pattern should not appear in the DAG. We can abandon this review. Thanks.