This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Canonicalize "A /u C1 /u C2" to "A /u (C1*C2)".
ClosedPublic

Authored by timshen on Jun 8 2018, 4:34 PM.

Details

Summary

FWIW InstCombine already folds this. Also avoid the case where C1*C2 overflows.

Event Timeline

timshen created this revision.Jun 8 2018, 4:34 PM
timshen updated this revision to Diff 150587.Jun 8 2018, 4:45 PM

Don't generate the multiply, as we get the result for free anyway (we need to check overflow by using umul_ov).

timshen removed a reviewer: jlebar.
timshen added a subscriber: jlebar.
sanjoy accepted this revision.Jun 8 2018, 7:32 PM
sanjoy added inline comments.
llvm/lib/Analysis/ScalarEvolution.cpp
3072

LLVM usually prefers auto * for pointers.

3076

If it does overflow then we can just return 0 here right?

[Up to you if you want to handle that case or just add a TODO]

This revision is now accepted and ready to land.Jun 8 2018, 7:32 PM
sanjoy added inline comments.Jun 8 2018, 7:33 PM
llvm/test/Analysis/ScalarEvolution/fold.ll
106

These should be written as CHECK: <var name> followed by CHECK-NEXT: <expression> like in @test7.

timshen updated this revision to Diff 150800.Jun 11 2018, 11:47 AM

Added folding to 0 when denominator overflows.

timshen marked 2 inline comments as done.Jun 11 2018, 11:48 AM
This revision was automatically updated to reflect the committed changes.