This is an archive of the discontinued LLVM Phabricator instance.

[SimpleLoopUnswitch] partial unswitch needs to be careful when replacing invariants with constants
ClosedPublic

Authored by fedor.sergeev on Nov 7 2018, 8:23 AM.

Details

Summary

When partial unswitch operates on multiple conditions at once, .e.g:

if (Cond1 || Cond2 || NonInv) ...

it should infer (and replace) values for individual conditions only on one
side of unswitch and not another.

More precisely only these derivations hold true:

(Cond1 || Cond2) == false  =>  Cond1 == Cond2 == false
(Cond1 && Cond2) == true   =>  Cond1 == Cond2 == true

By the way we organize unswitching it means only replacing on "continue" blocks
and never on "unswitched" ones. Since trivial unswitch does not have "unswitched"
blocks it does not have this problem.

Fixes PR 39568.

Diff Detail

Event Timeline

fedor.sergeev created this revision.Nov 7 2018, 8:23 AM
asbirlea accepted this revision.Nov 7 2018, 10:11 AM

Great catch, thank you for fixing this and for the additional tests.

This revision is now accepted and ready to land.Nov 7 2018, 10:11 AM

Could you not introduce all the separate test files?

If the main test (which you did enhance) still doesn't cover the cases, just add more variants there?

Could you not introduce all the separate test files?

I was editting this comemnt and end up editting it into something that reads passive aggressively and not very politely. Really sorry about that, it was not at all my intention.

I was trying to much more genuinely ask "is there a problem with doing this that I'm not seeing?" not being rhetorical or hyperbolic.

Anyways, just felt bad on re-reading my comment and seeing that it ended up very different from my intent / mental process.

Could you not introduce all the separate test files?

I was trying to much more genuinely ask "is there a problem with doing this that I'm not seeing?" not being rhetorical or hyperbolic.

No prob :) I tend to be rather direct in such cases myself, sometimes getting into the trouble...

Honestly, I first did my tests and then figured out that original nontrivial tests do catch 'AND' case.
So yes, with my addition of 'OR' case there in test27 I can freely dump new nontrivial-unswitch test.
And as I have just discovered trivial-unswitch version is covered by existing trivial-unswitch.ll test.

So I'll keep the change in existing tests and dump the new ones.

removing the unnecessary tests

chandlerc accepted this revision.Nov 7 2018, 11:58 AM

LGTM too (but always feel free to submit w/ Alina's review)

This revision was automatically updated to reflect the committed changes.