This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Generate a BFI/BFXIL from 'or (and X, MaskImm), OrImm' iff the value being inserted only sets known zero bits.
ClosedPublic

Authored by mcrosier on May 18 2016, 2:42 PM.

Details

Summary

This combine transforms things like

and     w8, w0, #0xfffffff0
movz    w9, #5
orr             w0, w8, w9

to

movz    w8, #5
bfxil   w0, w8, #0, #4

The combine is tuned to make sure we always reduce the number of instructions. We avoid churning code for what is expected to be performance neutral changes (e.g., converted AND+OR to OR+BFI).

Please take a look,
Chad

Diff Detail

Repository
rL LLVM

Event Timeline

mcrosier updated this revision to Diff 57681.May 18 2016, 2:42 PM
mcrosier retitled this revision from to [AArch64] Generate a BFI/BFXIL from 'or (and X, MaskImm), OrImm' iff the value being inserted only sets known zero bits..
mcrosier updated this object.
mcrosier added reviewers: t.p.northover, jmolloy, gberry.
mcrosier added subscribers: bmakam, junbuml, llvm-commits.
mcrosier updated this revision to Diff 57714.May 18 2016, 5:04 PM

Rebase patch and fix a few spelling errors.

gberry added inline comments.May 23 2016, 3:12 PM
lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
2019 ↗(On Diff #57846)

NotKnownZero might be a clearer name for this, or just get rid of it and use ~KnownZeroBits instead.

2023 ↗(On Diff #57846)

I think this is too conservative. It should be okay to have bits that are 1 in the OrImm that are not KnownZero, since you know they will be 1 in the final result. E.g. (or (and x, 0xfffffff0), 0xf5). Essentially the known bits in the final result are KnownZero | OrImm.

Actually, maybe none of the above matters since the IR seems to be canonicalized in this case to widen the and mask to cover all of the 1 bits in the or mask as well.

test/CodeGen/AArch64/bitfield-insert.ll
381 ↗(On Diff #57846)

You might want to change the hard-coded x8/w8 to a regex in these tests to make them a little less brittle w.r.t. future changes.

449 ↗(On Diff #57846)

requires -> require

mcrosier updated this revision to Diff 58479.May 25 2016, 12:57 PM

Address Geoff's feedback.

mcrosier marked 3 inline comments as done.May 25 2016, 12:58 PM
mcrosier added inline comments.
lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
2023 ↗(On Diff #58479)

I agree this may be conservative, but I'm going to defer this improvement for the moment.

jmolloy accepted this revision.May 26 2016, 2:47 AM
jmolloy edited edge metadata.

LGTM!

This revision is now accepted and ready to land.May 26 2016, 2:47 AM
This revision was automatically updated to reflect the committed changes.