This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Added transformation from sdiv to ashr
Needs ReviewPublic

Authored by IlyaKrotov on May 8 2015, 7:45 AM.

Details

Reviewers
majnemer
resistor
Summary

Replace division of positive signed integer by power of 2 with a simple shift.

Diff Detail

Event Timeline

IlyaKrotov updated this revision to Diff 25327.May 8 2015, 7:45 AM
IlyaKrotov retitled this revision from to [InstCombine] Added transformation from sdiv to ashr.
IlyaKrotov updated this object.
IlyaKrotov edited the test plan for this revision. (Show Details)
IlyaKrotov added reviewers: majnemer, resistor.
IlyaKrotov added a subscriber: Unknown Object (MLST).
majnemer edited edge metadata.May 8 2015, 10:19 PM

You don't have any testcases.

What stops you from transforming sdiv i32 %x, 2 into ashr i32 %x, 1 ? Such a transform wouldn't be correct because the two are not equivalent when %x is -1.

The transform on line 1215 already tries to turn signed division into unsigned division when it is safe to do so. From there, unsigned division will be canonicalized into a shift when we can.

lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
1138–1139

This doesn't look correctly formatted, please use clang-format.