Roman Lebedev 676594305a [CodeGen][SelectionDAG] More efficient code for X % C == 0 (SREM case)
Summary:
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.

One huge caveat: this signed case is only valid for positive divisors.

While we can freely negate negative divisors, we can't negate `INT_MIN`,
so for now if `INT_MIN` is encountered, we bailout.
As a follow-up, it should be possible to handle that more gracefully
via extra `and`+`setcc`+`select`.

This passes llvm's test-suite, and from cursory(!) cross-examination
the folds (the assembly) match those of GCC, and manual checking via alive
did not reveal any issues (other than the `INT_MIN` case)

Reviewers: RKSimon, spatel, hermord, craig.topper, xbolva00

Reviewed By: RKSimon, xbolva00

Subscribers: xbolva00, thakis, javed.absar, hiraditya, dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65366

llvm-svn: 368702
2019-08-13 14:57:37 +00:00
..
2019-08-09 21:11:20 +00:00
2019-06-27 20:37:12 +00:00
2019-04-08 13:58:50 +00:00
2019-05-06 09:46:50 +00:00
2019-05-06 09:46:50 +00:00
2019-05-06 09:46:50 +00:00
2019-05-06 09:46:50 +00:00
2019-05-06 09:46:50 +00:00
2019-05-06 09:46:50 +00:00
2019-05-06 09:46:50 +00:00
2019-02-21 15:30:28 +00:00
2019-02-26 16:55:10 +00:00
2019-08-12 01:29:46 +00:00
2019-06-25 14:46:52 +00:00
2019-03-15 21:17:53 +00:00
2019-03-15 21:17:53 +00:00
2019-04-15 17:38:47 +00:00
2019-04-15 17:38:47 +00:00
2019-04-15 17:38:47 +00:00
2019-04-03 12:33:16 +00:00
2019-02-26 16:55:10 +00:00
2019-05-06 09:46:50 +00:00
2019-05-06 09:46:50 +00:00
2019-03-29 17:35:56 +00:00
2019-06-17 09:13:29 +00:00
2019-05-06 19:29:24 +00:00
2019-03-15 21:17:53 +00:00
2019-03-08 19:16:26 +00:00
2019-06-17 09:13:29 +00:00
2019-04-08 13:58:50 +00:00
2019-03-15 21:17:53 +00:00
2019-03-02 02:44:16 +00:00
2019-06-18 23:31:10 +00:00