Go to file
Michael Kruse beffdb9daa [ScopDetect] Reject loop with multiple exit blocks.
The current statement domain derivation algorithm does not (always)
consider that different exit blocks of a loop can have different
conditions to be reached.

From the code

      for (int i = n; ; i-=2) {
        if (i <= 0) goto even;
        if (i <= 1) goto odd;
        A[i] = i;
      }
    even:
      A[0] = 42;
      return;
    odd:
      A[1] = 21;
      return;

Polly currently derives the following domains:

        Stmt_even_critedge
            Domain :=
                [n] -> { Stmt_even_critedge[] };
        Stmt_odd
            Domain :=
                [n] -> { Stmt_odd[] : (1 + n) mod 2 = 0 and n > 0 };

while the domain for the odd case is correct, Stmt_even is assumed to be
executed unconditionally, which is obviously wrong. While projecting out
the loop dimension in `adjustDomainDimensions`, it does not consider
that there are other exit condition that have matched before.

I don't know a how to fix this without changing a lot of code. Therefore
This patch rejects loops with multiple exist blocks to fix the
miscompile of test-suite's uuencode.

The odd condition is transformed by LLVM to

    %cmp1 = icmp eq i64 %indvars.iv, 1

such that the project_out in adjustDomainDimensions() indeed only
matches for odd n (using this condition only, we'd have an infinite loop
otherwise).

The even condition manifests as

    %cmp = icmp slt i64 %indvars.iv, 3

Because buildDomainsWithBranchConstraints() does not consider other exit
conditions, it has to assume that the induction variable will eventually
be lower than 3 and taking this exit.

IMHO we need to reuse the algorithm that determines the number of
iterations (addLoopBoundsToHeaderDomain) to determine which exit
condition applies first. It has to happen in
buildDomainsWithBranchConstraints() because the result will need to
propagate to successor BBs. Currently addLoopBoundsToHeaderDomain() just
look for union of all backedge conditions (which means leaving not the
loop here). The patch in llvm.org/PR35465 changes it to look for exit
conditions instead. This is required because there might be other exit
conditions that do not alternatively go back to the loop header.

Differential Revision: https://reviews.llvm.org/D45649

llvm-svn: 330858
2018-04-25 18:53:33 +00:00
clang [CMake] Enable libc++ for Fuchsia toolchain on Darwin 2018-04-25 18:30:55 +00:00
clang-tools-extra [clangd] Add "str()" method to SymbolID. 2018-04-25 15:27:09 +00:00
compiler-rt [scudo] Adding an interface function to print allocator stats 2018-04-25 18:52:29 +00:00
debuginfo-tests [Darwin] Specify DWARF 2/4 when running apple accelerator tests. 2018-02-26 20:56:45 +00:00
libclc relational/select: Condition types for half are short/ushort, not char/uchar 2018-04-25 17:36:36 +00:00
libcxx Disable the test I just added when testing C++03. 2018-04-25 16:09:47 +00:00
libcxxabi [libc++abi] Replace __sync_* functions with __libcpp_atomic_* functions. 2018-04-16 22:00:14 +00:00
libunwind [cmake] Remove duplicate command line options from build 2018-04-05 20:27:50 +00:00
lld [ELF] - Eliminate the AssertCommand. 2018-04-25 11:16:31 +00:00
lldb Fix -Wswitch warning after r330790. 2018-04-25 13:22:47 +00:00
llgo irgen: Create functions instead of global variables for builtin hash and equal algorithms. 2017-06-04 22:11:28 +00:00
llvm IWYU llvm-config.h for LLVM_VERSION_STRING 2018-04-25 18:34:00 +00:00
openmp [OpenMP] Make bc file compilation sensitive to LIBOMPTARGET_NVPTX_DEBUG flag 2018-04-20 20:41:00 +00:00
parallel-libs [Axccel] Remove -Wno-missing-braces in build 2016-12-19 21:34:07 +00:00
polly [ScopDetect] Reject loop with multiple exit blocks. 2018-04-25 18:53:33 +00:00
README.md Add an svn project to contain the files that appear at the root of the 2017-10-19 21:09:49 +00:00

README.md

Low Level Virtual Machine (LLVM)

This directory and its subdirectories contain source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and runtime environments.