This is an archive of the discontinued LLVM Phabricator instance.

Convert a signed remainder instruction to unsigned remainder
ClosedPublic

Authored by SjoerdMeijer on Jul 11 2016, 5:34 AM.

Details

Summary

This converts a signed remainder instruction to unsigned remainder, which enables the code size optimisation to fold a rem and div into a single aeabi_uidivmod call. This was not happening before because sdiv was converted but srem not, and instructions with different signedness are not combined.

Diff Detail

Event Timeline

SjoerdMeijer retitled this revision from to Convert a signed remainder instruction to unsigned remainder.
SjoerdMeijer updated this object.
SjoerdMeijer added a subscriber: llvm-commits.
jmolloy added inline comments.Jul 11 2016, 6:54 AM
lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
343–344

You can simplify this by using "auto"

352

All of these checks can be combined into one if with ||.

Addressed James' comments

mehdi_amini added inline comments.Jul 11 2016, 12:14 PM
test/Transforms/CorrelatedValuePropagation/srem.ll
26

Do you need all these basic blocks and instructions? (i.e: is this test minimal?)

Simplified the regression test. The transformation triggers when value range can determine that the operands are >= 0. This is accomplished with and if-statement instead of a while loop, which simplifies the test.

jmolloy accepted this revision.Jul 14 2016, 5:22 AM
jmolloy edited edge metadata.

LGTM now!

This revision is now accepted and ready to land.Jul 14 2016, 5:22 AM
This revision was automatically updated to reflect the committed changes.