This is an archive of the discontinued LLVM Phabricator instance.

[IRCE][Test] Add test to constrain a loop bounded by phi
AcceptedPublic

Authored by aleksandr.popov on Feb 27 2023, 12:30 AM.

Details

Summary

Added an example when IRCE can't parse a loop bounded by phi, due to
unsafe loop bounds. But it's possible to prove that bounds are safe, by
improving ScalarEvolution

phi(a,b) != 0
a >= 0
b >= 0
------>
phi(a,b) > 0

Diff Detail

Unit TestsFailed

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2023, 12:30 AM
Herald added a subscriber: javed.absar. · View Herald Transcript
aleksandr.popov requested review of this revision.Feb 27 2023, 12:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2023, 12:30 AM
mkazantsev added inline comments.Feb 27 2023, 12:39 AM
llvm/unittests/Analysis/ScalarEvolutionTest.cpp
1749 ↗(On Diff #500682)

addrspace(1) is not needed here.

1787 ↗(On Diff #500682)

(void) LHS, RHS to avoid dead code warning?

Is there any way to make this an analysis / IR test instead?

mkazantsev added a comment.EditedFeb 27 2023, 12:42 AM

High-level comment: if you expect that SCEV is able to prove equivalence of loads, you need it to be able to prove aliasing facts, which I belive it cannot do. It need to somehow know that no one stores to this memory on any posible path from one load to another. Or maybe it can, but I've never seen it doing things like this.

Is there any way to make this an analysis / IR test instead?

I believe there is a motivating example coming from IRCE. @aleksandr.popov can we add it too?

Yep, that's true, will try to add IR test instead

aleksandr.popov retitled this revision from [SCEV][Test] Add test to prove block's guardering condition to [IRCE][Test] Add test to constrain a loop bounded by phi.
aleksandr.popov edited the summary of this revision. (Show Details)

I've updated the test in IR form

mkazantsev added inline comments.Mar 10 2023, 12:58 AM
llvm/test/Transforms/IRCE/constrain_loop_with_phi_bound.ll
2

; REQUIRES: asserts

7

I don't quite understand the example here. Call can return different values every time. IRCE is supposed to generate a loop-invariant check. How it would look like?

mkazantsev accepted this revision.Mar 10 2023, 2:03 AM
mkazantsev added inline comments.
llvm/test/Transforms/IRCE/constrain_loop_with_phi_bound.ll
7

Ok, we are IRCEing inner loop. Looks fine then.

Maybe auto-generated checks instead or IRCE's output? Use update_test_checks.py.

This revision is now accepted and ready to land.Mar 10 2023, 2:03 AM
aleksandr.popov added inline comments.
llvm/test/Transforms/IRCE/constrain_loop_with_phi_bound.ll
7

Thanks, done