This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Select BFI/BFXIL to ORR with shifted operand when one operand is the left or right shift of another operand
ClosedPublic

Authored by mingmingl on Nov 8 2022, 10:48 PM.

Details

Summary

Use right shift [1] as an example

  • Before, bfxil is generated (https://godbolt.org/z/EfzWMszPn)
  • After, orr with right-shifted operand is generated (added test cases in CodeGen/AArch64/bitfield-insert.ll)

[1]

define i64 @test_orr_not_bfxil_i64(i64 %0) {
  %2 = and i64 %0, 1044480 ; 0xff000
  %3 = lshr i64 %2, 12
  %4 = or i64 %2, %3
  ret i64 %4
}

Diff Detail

Event Timeline

mingmingl created this revision.Nov 8 2022, 10:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 8 2022, 10:48 PM
mingmingl requested review of this revision.Nov 8 2022, 10:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 8 2022, 10:49 PM
mingmingl updated this revision to Diff 474159.Nov 8 2022, 10:50 PM

run git clang-format HEAD~1

dmgreen added inline comments.Nov 10 2022, 1:24 AM
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
2946

Should this go through getShifterImm, for consistency even if LSL == 0?

khchen added a subscriber: khchen.Nov 10 2022, 9:44 AM
khchen added inline comments.
llvm/test/CodeGen/AArch64/bitfield-insert.ll
641

seem we could update the comments as well.

mingmingl marked 2 inline comments as done.

resolve comments.

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
2946
llvm/test/CodeGen/AArch64/bitfield-insert.ll
641

I realize it could be confusing to say "orr is better than a instruction that wouldn't be generated going forward", so rephrased to 'orr is generated, not bfi/bfxil'. Let me know if I miss what should be updated, thanks!

dmgreen accepted this revision.Nov 11 2022, 12:04 AM
dmgreen added reviewers: t.p.northover, efriedma.

You may want to rebase on top of D137797, but otherwise LGTM.

This revision is now accepted and ready to land.Nov 11 2022, 12:04 AM

thanks for reviews! Diff3 and diff4 (in "History" tab of "Revision Contents") have no diff (meaning rebase doesn't introduce unintended diff), going to submit.

This revision was landed with ongoing or failed builds.Nov 11 2022, 2:01 PM
This revision was automatically updated to reflect the committed changes.