[llvm-commits] [llvm] r155884 - in /llvm/trunk: lib/Transforms/Scalar/LICM.cpp test/Transforms/LICM/speculate.ll

Eli Friedman eli.friedman at gmail.com
Mon Apr 30 21:16:55 PDT 2012


On Mon, Apr 30, 2012 at 9:03 PM, Nick Lewycky <nicholas at mxc.ca> wrote:
> Author: nicholas
> Date: Mon Apr 30 23:03:01 2012
> New Revision: 155884
>
> URL: http://llvm.org/viewvc/llvm-project?rev=155884&view=rev
> Log:
> An instruction in a loop is not guaranteed to be executed just because the loop
> has no exit blocks. Fixes PR12706!
>
> Modified:
>    llvm/trunk/lib/Transforms/Scalar/LICM.cpp
>    llvm/trunk/test/Transforms/LICM/speculate.ll
>
> Modified: llvm/trunk/lib/Transforms/Scalar/LICM.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LICM.cpp?rev=155884&r1=155883&r2=155884&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/LICM.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp Mon Apr 30 23:03:01 2012
> @@ -618,6 +618,11 @@
>     if (!DT->dominates(Inst.getParent(), ExitBlocks[i]))
>       return false;
>
> +  // As a degenerate case, if the loop is statically infinite then we haven't
> +  // proven anything since there are no exit blocks.
> +  if (ExitBlocks.empty())
> +    return false;

Even if there are exit blocks, you still haven't proven anything; take
something like the following, assuming the compiler doesn't know
anything about exit():

int f(int x, int y) {
  int n = 0;
  for (int i = 0; i < 10; i++) {
    exit(0);
    n += x / (y+i);
  }
  return n;
}

-Eli




More information about the llvm-commits mailing list