[PATCH] D63950: [Codegen][SelectionDAG] X u% C == 0 fold: non-splat vectors, accept urem-by-one lines too

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 28 11:55:21 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 a subscriber: javed.absar.
lebedev.ri added a parent revision: D63930: [Codegen][SelectionDAG] X u% C == 0 fold: non-splat vectors, accept power-of-two constants.

No integer exists for which there is remainder after division by `1`.
Incidentally, this fold is only valid for `D u> 1`. (power-of-two is ok.)
While we could just bailout and let it constant-fold for scalars and
splat vectors, we *do* want to handle non-splat vectors where at least
one divisor happens to be `1`.

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`, let's pick `0`,
because there's no point in rotating, and because `(X * 0)` most
obviously "discards" of the value of `X`.


Repository:
  rL LLVM

https://reviews.llvm.org/D63950

Files:
  lib/CodeGen/SelectionDAG/TargetLowering.cpp
  test/CodeGen/AArch64/urem-seteq-vec-nonsplat.ll
  test/CodeGen/X86/urem-seteq-vec-nonsplat.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63950.207121.patch
Type: text/x-patch
Size: 31157 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190628/44b1e7d2/attachment.bin>


More information about the llvm-commits mailing list