[PATCH] D63963: [Codegen][SelectionDAG] X u% C == 0 fold: non-splat vector improvements

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 28 16:15:17 PDT 2019


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

Four things here:

1. Generalize the fold to handle non-splat divisors. Reasonably trivial.
2. Unban power-of-two divisors. I don't see any reason why they should be illegal.
  - There is no ban in Hacker's Delight
  - I think the ban came from the same bug that caused the miscompile - in `floor((2^W - 1) / D)` we were dividing by `D0` instead of `D`, and we **were** ensuring that `D0` is not `1`, which made sense.
3. Unban `1` divisors. I no longer believe Hacker's Delight actually says that the fold is invalid for `D = 0`. Further considerations:
  - We know that
    - `(X u% 1) == 0`  can be constant-folded to `1`,
    - `(X u% 1) != 0`  can be constant-folded to `0`,
  - Also, we know that
    - `X u<= -1` can be constant-folded to `1`,
    - `X u>  -1` can be constant-folded to `0`,
  - https://godbolt.org/z/7jnZJX https://rise4fun.com/Alive/oF6p
  - We know will end up with the following: `(setule/setugt (rotr (mul N, P), K), Q)`
  - Therefore, for given new DAG nodes and comparison predicates (`ule`/`ugt`), we will still produce the correct answer if: `Q` is a all-ones constant; and both `P` and `K` are *anything* other than `undef`.
  - The fold will indeed produce `Q = all-ones`.
4. Try to re-splat the `P` and `K` vectors - we don't care about their values for the lines where divisor was `1`.


Repository:
  rL LLVM

https://reviews.llvm.org/D63963

Files:
  include/llvm/CodeGen/SelectionDAG.h
  include/llvm/CodeGen/TargetLowering.h
  lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  lib/CodeGen/SelectionDAG/TargetLowering.cpp
  test/CodeGen/AArch64/urem-seteq-vec-nonsplat.ll
  test/CodeGen/X86/urem-seteq-vec-nonsplat.ll
  unittests/ADT/APIntTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63963.207171.patch
Type: text/x-patch
Size: 68676 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190628/7de25f19/attachment-0001.bin>


More information about the llvm-commits mailing list