[llvm-commits] Patch to improve loop-simplify

Dan Gohman dan433584 at gmail.com
Mon Nov 5 12:47:41 PST 2012


On Sat, Nov 3, 2012 at 10:13 AM, Andrew Clinton <ajclinto at gmail.com> wrote:

> It's not clear to me how LICM would provide any benefit in hoisting
> redundancies out of conditional control flow - isn't the point of LICM
> to extract expressions from a loop so they can be executed once
> outside the loop?  If the contents of the loop are already expressed
> with conditionals, there wouldn't be any benefit to this optimization.
>
> If there was an invariant in the original loop that could be extracted
> by LICM, I can't see that splitting into an outer/inner loop would
> make this any easier to find.
>
> Do you have a test case that I could use to verify?
>

This is artificial, but it demonstrates my idea, and we are talking about
canonicalizing:

long test(long *z)
{
  long val = 0;
  long foo = 0;
  long i = 0;

  while (z[i++])
  {
    foo += val * 19;

    if (z[i++])
    {
      val += z[i++];
    }
  }
  return val ^ foo;
}

TOT currently creates two loops and hoists the "val*19" out of the inner
loop. With your patch, there's one loop, and the "val*19" is executed
redundantly each time the if body is not executed.

Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121105/fe12d84a/attachment.html>


More information about the llvm-commits mailing list