This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fold icmp eq/ne (udiv i32 A, B), 0 -> icmp ugt/ule B, A
ClosedPublic

Authored by mcrosier on May 6 2016, 3:25 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

mcrosier updated this revision to Diff 56474.May 6 2016, 3:25 PM
mcrosier updated this revision to Diff 56475.
mcrosier retitled this revision from to [InstCombine] Fold icmp eq/ne (udiv i32 CI2, A), 0 -> icmp ugt/ule A, CI2.
mcrosier updated this object.
mcrosier added a reviewer: majnemer.
mcrosier added a subscriber: llvm-commits.

Add full context.

majnemer added inline comments.May 6 2016, 4:23 PM
lib/Transforms/InstCombine/InstCombineCompares.cpp
1549 ↗(On Diff #56475)

Why do you need to do this ConstantInt::get call? Shouldn't A and CI2 have the same type?

majnemer added inline comments.May 6 2016, 4:29 PM
lib/Transforms/InstCombine/InstCombineCompares.cpp
1543–1550 ↗(On Diff #56475)

This transform is valid regardless of what value CI2 holds. We should require it to be a ConstantInt.

test/Transforms/InstCombine/compare-udiv.ll
3–9 ↗(On Diff #56475)

This transform is valid, regardless of what value the numerator is. We shouldn't require a constant here.

11–17 ↗(On Diff #56475)

It'd be good to have a version of this test where the numerator is -1.

mcrosier updated this revision to Diff 56578.May 9 2016, 7:36 AM
mcrosier retitled this revision from [InstCombine] Fold icmp eq/ne (udiv i32 CI2, A), 0 -> icmp ugt/ule A, CI2 to [InstCombine] Fold icmp eq/ne (udiv i32 A, B), 0 -> icmp ugt/ule B, A.
mcrosier updated this object.

Address David's comments:
-Handle both constant and non-constant numerator.
-Add test with -1 numerator.

mcrosier marked 4 inline comments as done.May 9 2016, 7:37 AM
majnemer accepted this revision.May 9 2016, 7:49 AM
majnemer edited edge metadata.

LGTM

This revision is now accepted and ready to land.May 9 2016, 7:49 AM
This revision was automatically updated to reflect the committed changes.

Committed in r268960. I did have to move the optimizations after visitICmpInstWithInstAndIntCst() in order to not regress udiv_icmp1 in exact.ll. Also, I added an additional test case, udiv_icmp2, to provide more context and to improve coverage.