[PATCH] D50030: [ARM] Adjust AND immediates to make them cheaper to select.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 30 17:18:32 PDT 2018


efriedma created this revision.
efriedma added reviewers: dmgreen, samparker, SjoerdMeijer, t.p.northover.
Herald added a reviewer: javed.absar.
Herald added subscribers: chrib, kristof.beyls.

LLVM normally prefers to minimize the number of bits set in an AND immediate, but that doesn't always match the available ARM instructions.    In Thumb1 mode, prefer uxtb or uxth where possible; otherwise, prefer a two-instruction sequence movs+ands or movs+bics where possible.

Some potential improvements outlined in ARMTargetLowering::targetShrinkDemandedConstant, but seems to work pretty well already.

The ARMISelDAGToDAG fix ensures we don't generate an invalid UBFX instruction due to a larger-than-expected mask. (It's orthogonal, in some sense, but as far as I can tell it's either impossible or nearly impossible to reproduce the bug without this change.)

According to my testing, this seems to consistently improve codesize by a small amount by forming bic more often for ISD::AND with an immediate.


Repository:
  rL LLVM

https://reviews.llvm.org/D50030

Files:
  lib/Target/ARM/ARMISelDAGToDAG.cpp
  lib/Target/ARM/ARMISelLowering.cpp
  lib/Target/ARM/ARMISelLowering.h
  test/CodeGen/ARM/Windows/alloca.ll
  test/CodeGen/ARM/Windows/vla.ll
  test/CodeGen/ARM/and-cmpz.ll
  test/CodeGen/ARM/illegal-bitfield-loadstore.ll
  test/CodeGen/ARM/select_const.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50030.158133.patch
Type: text/x-patch
Size: 7077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180731/4a69c32d/attachment.bin>


More information about the llvm-commits mailing list