[PATCH] D29107: Fix a bug when unswitching on partial LIV for SwitchInst

Xin Tong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 26 21:38:59 PST 2017


trentxintong added a comment.

In https://reviews.llvm.org/D29107#658375, @david2050 wrote:

> Hi Xin, let me make sure I understand given:
>
>     
>
>   for(...;...;++i)
>      switch (f(i) & c) 
>           case 11:
>           case 12:
>
>
> we might unswitch this too
>
>   if (c) 
>      for(...;...;++i)
>        switch (f(i) & c) 
>            case 11:
>            case 12:
>   else
>     for(...;...;++i)
>      switch (0) 
>           case 11:
>           case 12:
>
>
> and we achieve no simplification in one loop.
>
> How does restricting to a single bit change this?


Hi David

We are trying to pick a value for c such that f(i) & c can be simplified to either a loop _variant_ value which we will not try to unswitch on again, or a constant which we will not unswitch either. The problem is when c is more than 1 bit, we can not pick a value that will guarantee such simplifications.  Lets say c is a signed int here and we pick a random value, then we do not know what f(i) & c will simplify to, maybe it will not simplify at all. In such cases, given the way loop unswitching is implemented, it will try to unswitch this loop again (It records what case value has been unswitched and will not unswitch on that case-value again).

In your case, we picked c==0, we get simplification in the else-loop and no simplification in the if-loop as what you have in the example. However, the way loop unswitching is implemented is that we try to keep unswitching the current loop (the if-loop in this case) until it cant be unswitched anymore or no quota left.  We know c is not 0, but we do not know what c is and thus f(i) & c can not be simplified, so we do not know whats unswitched out ...

If c is one bit, it can only be true or false, we are guaranteed to either reach a constant or a loop _variant_ input value for the switch for the current loop and the cloned loop.


https://reviews.llvm.org/D29107





More information about the llvm-commits mailing list