[PATCH] D50222: [CodeGen] [SelectionDAG] More efficient code for X % C == 0

Dmytro Shynkevych via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 2 20:58:34 PDT 2018


hermord created this revision.
hermord added reviewers: MatzeB, kparzysz, efriedma.

This implements an optimization described in Hacker's Delight 10-17: when C is constant, the result of X % C == 0 can be computed more cheaply without actually calculating the remainder. The motivation is discussed here: https://bugs.llvm.org/show_bug.cgi?id=35479.

Notes:

- In principle, it's possible to also handle the X % C1 == C2 case, as discussed on bugzilla. This seems to require an extra branch on overflow, so I refrained from implementing this for now.
- An explicit check for when the REM can be reduced to just its LHS is included: the X % C == 0 optimization breaks `test1` in `test/CodeGen/X86/jump_sign.ll` otherwise. I hadn't managed to find a better way to not generate worse output in this case.
- I haven't contributed to LLVM before, so I tried to select reviewers based on who I saw in other reviews. In particular, @kparzysz: a Hexagon test is modified and I have no familiarity with the architecture; hopefully my changes are valid.


Repository:
  rL LLVM

https://reviews.llvm.org/D50222

Files:
  include/llvm/CodeGen/TargetLowering.h
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  lib/CodeGen/SelectionDAG/TargetLowering.cpp
  test/CodeGen/Hexagon/swp-const-tc2.ll
  test/CodeGen/X86/jump_sign.ll
  test/CodeGen/X86/rem.ll
  test/CodeGen/X86/vselect-avx.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50222.158905.patch
Type: text/x-patch
Size: 14499 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180803/e7b9f8b4/attachment.bin>


More information about the llvm-commits mailing list