Index: lib/CodeGen/IslAst.cpp =================================================================== --- lib/CodeGen/IslAst.cpp +++ lib/CodeGen/IslAst.cpp @@ -416,6 +416,13 @@ buildRunCondition(Build); + // The assumed context restricts the dependence analysis, hence it also has + // to restrict the AST generation otherwise the scalar code generation can + // become unstable. However, we need to do this after we generated the runtime + // checks as the context we use to restrict the AST generation with only holds + // if the runtime checks are true. + Build = isl_ast_build_restrict(Build, S->getAssumedContext()); + Root = isl_ast_build_node_from_schedule(Build, S->getScheduleTree()); isl_ast_build_free(Build); Index: test/Isl/CodeGen/assumed_context_empty_domain_restriction.ll =================================================================== --- test/Isl/CodeGen/assumed_context_empty_domain_restriction.ll +++ test/Isl/CodeGen/assumed_context_empty_domain_restriction.ll @@ -1,18 +1,19 @@ -; RUN: opt %loadPolly -S -polly-opt-isl -polly-codegen < %s +; RUN: opt %loadPolly -S -polly-opt-isl -polly-ast -analyze < %s | FileCheck --check-prefix=AST %s +; RUN: opt %loadPolly -S -polly-opt-isl -polly-codegen < %s | FileCheck %s ; -; TODO: This test will crash the scalar code generation. The problem step by step: -; 1) The assumed context is empty because of the out-of-bounds array access. -; 2) The dependence analysis will use the assumed context and determine -; that there are not iterations executed, hence no dependences. -; 3) The scheduler will transform the program somehow according to -; the orginal domains and empty dependences but not the assumed context. -; The new ast is shown below. -; 4) The code generation will look for the new value of %0 when the -; for_body_328_lr_ph statement is copied, however it has not yet seen %0 -; as the for_end_310 statement has been moved after for_body_328_lr_ph. -; 5) Crash as no new value of %0 can be found. +; This test crashed the scalar code generation. The problem step by step: +; 1) The assumed context is empty because of the out-of-bounds array access. +; 2) The dependence analysis will use the assumed context and determine +; that there are not iterations executed, hence no dependences. +; 3) The scheduler will transform the program somehow according to +; the orginal domains and empty dependences but not the assumed context. +; The new and the old ast is shown below. +; 4) The code generation will look for the new value of %0 when the +; for_body_328_lr_ph statement is copied, however it has not yet seen %0 +; as the for_end_310 statement has been moved after for_body_328_lr_ph. +; 5) Crash as no new value of %0 can be found. ; -; AST: +; AST old: ; ; if (0) ; { @@ -24,11 +25,12 @@ ; else ; { /* original code */ } ; -; CHECK: polly.start -; -; TODO: This test should not crash Polly. +; AST new: +; AST: if (0) +; AST: { +; AST: } ; -; XFAIL: * +; CHECK: polly.start ; @endposition = external global i32, align 4 @Bit = external global [0 x i32], align 4