[PATCH] D63391: [CodeGen] [SelectionDAG] More efficient code for X % C == 0 (UREM case) (try 2)

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 16 15:25:08 PDT 2019


lebedev.ri created this revision.
lebedev.ri added reviewers: RKSimon, craig.topper, spatel, hermord.
lebedev.ri added a project: LLVM.
Herald added a subscriber: javed.absar.

I'm submitting a new revision since i don't understand how to reclaim/reopen/take over the existing one, D50222 <https://reviews.llvm.org/D50222>.
There is no such action in "Add Action" menu...
Original patch D50222 <https://reviews.llvm.org/D50222> by @hermord (Dmytro Shynkevych)

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.

Original patch author: @hermord (Dmytro Shynkevych)!

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.
- The `test/CodeGen/X86/jump_sign.ll` regresses, and is being fixed by a followup patch D63390 <https://reviews.llvm.org/D63390>.


Repository:
  rL LLVM

https://reviews.llvm.org/D63391

Files:
  include/llvm/CodeGen/TargetLowering.h
  lib/CodeGen/SelectionDAG/TargetLowering.cpp
  test/CodeGen/AArch64/urem-seteq-optsize.ll
  test/CodeGen/AArch64/urem-seteq-vec-splat.ll
  test/CodeGen/AArch64/urem-seteq.ll
  test/CodeGen/X86/jump_sign.ll
  test/CodeGen/X86/urem-seteq-optsize.ll
  test/CodeGen/X86/urem-seteq-vec-splat.ll
  test/CodeGen/X86/urem-seteq.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63391.204970.patch
Type: text/x-patch
Size: 32146 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190616/b3b912a4/attachment.bin>


More information about the llvm-commits mailing list