This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by lebedev.ri on Jul 19 2019, 6:27 AM.

Details

Summary

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

Diff Detail

Event Timeline

lebedev.ri created this revision.Jul 19 2019, 6:27 AM
lebedev.ri abandoned this revision.Jul 25 2019, 1:38 PM

This is wrong solution.
Superseded by https://reviews.llvm.org/D65298