[PATCH] D64988: [InstCombine] 'Rem' formation from subtraction of rounded-down value (PR42673)

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 19 06:28:50 PDT 2019


lebedev.ri created this revision.
lebedev.ri added reviewers: RKSimon, spatel, ZaMaZaN4iK.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.

We can fold
`x - ((x / y) * y)`
to
`x % y`

https://rise4fun.com/Alive/8Rp

To be noted, we also prefer `x - (x % y)` to `(x / y) * y`,
and these tests show that we miss this transform
if division is not one-use. The caveat is that we could
still transform if we know that there already is `(x % y)`;
but unlike back-end's `SelectionDAG::getNodeIfExists()`,
i'm not sure how to nicely check that in middle-end.

https://godbolt.org/z/rWjNl4
https://bugs.llvm.org/show_bug.cgi?id=42673


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64988

Files:
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/test/Transforms/InstCombine/srem-via-sdiv-mul-sub.ll
  llvm/test/Transforms/InstCombine/urem-via-udiv-mul-sub.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64988.210816.patch
Type: text/x-patch
Size: 5527 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190719/86924074/attachment.bin>


More information about the llvm-commits mailing list