This is an archive of the discontinued LLVM Phabricator instance.

[Aarch64] Materialize immediates with 64-bit ORR + EOR if shorter
DraftPublic

Authored by dougallj on Nov 6 2021, 7:20 PM.
This is a draft revision that has not yet been submitted for review.

Details

Reviewers
None
Summary

A number of useful constants can be encoded with a 64-bit ORR followed
by a 64-bit EOR, including all remaining repeated byte patterns, some
useful repeated 16-bit patterns, and some irregular masks. This patch
prioritizes that encoding over three or four instruction encodings.
Encoding with MOV + MOVK or ORR + MOVK is still preferred for fast
literal generation and readability respectively.

The method devises three candidate values, and checks if both Candidate
and (Imm ^ Candidate) are valid logical immediates. If so, Imm is
materialized with:

ORR Xd, XZR, #(Imm ^ Candidate)
EOR Xd, Xd, #(Candidate)

The method has been exhaustively tested to ensure it can solve all
possible values (excluding 0, ~0, and plain logical immediates, which
are handled earlier).

Diff Detail

Event Timeline

dougallj created this revision.Nov 6 2021, 7:20 PM
dougallj updated this revision to Diff 385319.Nov 6 2021, 7:56 PM
dougallj retitled this revision from [Aarch64] Materialize 64-bit immediates with ORR + EOR when possible to [Aarch64] Materialize immediates with 64-bit ORR + EOR if shorter.
dougallj edited the summary of this revision. (Show Details)

Reordering and minor text/name edits

Reordered tests to simplify diff, and updated commit message, comments and function name
to not imply this handles 32-bit ORR + 64-bit EOR.

dougallj updated this revision to Diff 385321.Nov 6 2021, 8:09 PM

Edited comment for clarity