This is an archive of the discontinued LLVM Phabricator instance.

[LoopPredication] Support ule, sle latch predicates
ClosedPublic

Authored by apilipenko on Sep 22 2017, 6:20 AM.

Details

Summary

This is a follow up for the loop predication change D37569 to support ule, sle latch predicates.

Diff Detail

Repository
rL LLVM

Event Timeline

apilipenko created this revision.Sep 22 2017, 6:20 AM
mkazantsev added inline comments.Oct 3 2017, 2:00 AM
test/Transforms/LoopPredication/basic.ll
158 ↗(On Diff #116341)

Consider case %n = 10, %length = -100. The original code will successfully pass through the guard (because 0 <u -100 is true) and then executes normally. After the loop is predicated, the condition icmp slt i32 %n, %length becomes false, and we don't go to the loop and deoptimize. Is it a problem?

apilipenko added inline comments.Oct 6 2017, 9:02 AM
test/Transforms/LoopPredication/basic.ll
158 ↗(On Diff #116341)

From correctness standpoint it's OK since guards are allowed to fail spuriously.

As of why it is happening, we find the first value the guard will fail (-100) and then check that the backedge condition doesn't allow this value. We are not using the information about the backedge IV start, so we end up with an overly conservative check.

It should not be a problem in practice as long as your language doesn't use arrays longer that max signed int.

This revision is now accepted and ready to land.Oct 8 2017, 9:23 PM
This revision was automatically updated to reflect the committed changes.