Index: lib/CodeGen/PPCGCodeGeneration.cpp =================================================================== --- lib/CodeGen/PPCGCodeGeneration.cpp +++ lib/CodeGen/PPCGCodeGeneration.cpp @@ -2732,12 +2732,7 @@ /// @param PPCGArray The array to compute bounds for. /// @param Array The polly array from which to take the information. void setArrayBounds(gpu_array_info &PPCGArray, ScopArrayInfo *Array) { - isl_pw_aff_list *BoundsList = - isl_pw_aff_list_alloc(S->getIslCtx(), PPCGArray.n_index); - std::vector PwAffs; - - isl_space *AlignSpace = S->getParamSpace(); - AlignSpace = isl_space_add_dims(AlignSpace, isl_dim_set, 1); + std::vector PwAffs; if (PPCGArray.n_index > 0) { if (isl_set_is_empty(PPCGArray.extent)) { @@ -2746,9 +2741,7 @@ isl_space_params(isl_set_get_space(Dom))); isl_set_free(Dom); isl_pw_aff *Zero = isl_pw_aff_from_aff(isl_aff_zero_on_domain(LS)); - Zero = isl_pw_aff_align_params(Zero, isl_space_copy(AlignSpace)); - PwAffs.push_back(isl::manage(isl_pw_aff_copy(Zero))); - BoundsList = isl_pw_aff_list_insert(BoundsList, 0, Zero); + PwAffs.push_back(Zero); } else { isl_set *Dom = isl_set_copy(PPCGArray.extent); Dom = isl_set_project_out(Dom, isl_dim_set, 1, PPCGArray.n_index - 1); @@ -2761,9 +2754,7 @@ One = isl_aff_add_constant_si(One, 1); Bound = isl_pw_aff_add(Bound, isl_pw_aff_alloc(Dom, One)); Bound = isl_pw_aff_gist(Bound, S->getContext()); - Bound = isl_pw_aff_align_params(Bound, isl_space_copy(AlignSpace)); - PwAffs.push_back(isl::manage(isl_pw_aff_copy(Bound))); - BoundsList = isl_pw_aff_list_insert(BoundsList, 0, Bound); + PwAffs.push_back(Bound); } } @@ -2772,13 +2763,29 @@ auto LS = isl_pw_aff_get_domain_space(Bound); auto Aff = isl_multi_aff_zero(LS); Bound = isl_pw_aff_pullback_multi_aff(Bound, Aff); - Bound = isl_pw_aff_align_params(Bound, isl_space_copy(AlignSpace)); - PwAffs.push_back(isl::manage(isl_pw_aff_copy(Bound))); - BoundsList = isl_pw_aff_list_insert(BoundsList, i, Bound); + PwAffs.push_back(Bound); + } + + isl_space *AlignSpace = S->getParamSpace(); + AlignSpace = isl_space_add_dims(AlignSpace, isl_dim_set, 1); + for (isl_pw_aff *PwAff : PwAffs) { + isl_space *PwAffSpace = isl_pw_aff_get_domain_space(PwAff); + AlignSpace = isl_space_align_params(AlignSpace, PwAffSpace); + } + + isl_pw_aff_list *BoundsList = + isl_pw_aff_list_alloc(S->getIslCtx(), PPCGArray.n_index); + + for (unsigned i = 0; i < PwAffs.size(); i++) { + isl_pw_aff *Adjusted = PwAffs[i]; + Adjusted = isl_pw_aff_align_params(Adjusted, isl_space_copy(AlignSpace)); + BoundsList = isl_pw_aff_list_insert(BoundsList, i, Adjusted); } - isl_space_free(AlignSpace); isl_space *BoundsSpace = isl_set_get_space(PPCGArray.extent); + BoundsSpace = + isl_space_align_params(BoundsSpace, isl_space_copy(AlignSpace)); + isl_space_free(AlignSpace); assert(BoundsSpace && "Unable to access space of array."); assert(BoundsList && "Unable to access list of bounds."); @@ -2786,6 +2793,9 @@ PPCGArray.bound = isl_multi_pw_aff_from_pw_aff_list(BoundsSpace, BoundsList); assert(PPCGArray.bound && "PPCGArray.bound was not constructed correctly."); + + errs() << "Bound: "; + isl_multi_pw_aff_dump(PPCGArray.bound); } /// Create the arrays for @p PPCGProg. Index: test/GPGPU/bounds-construction-with-ignore-param-bounds.ll =================================================================== --- /dev/null +++ test/GPGPU/bounds-construction-with-ignore-param-bounds.ll @@ -0,0 +1,54 @@ +; RUN: opt %loadPolly -S -polly-codegen-ppcg \ +; RUN: -polly-ignore-parameter-bounds \ +; RUN: -polly-invariant-load-hoisting < %s| FileCheck %s -check-prefix=HOST-IR + +; When we have `-polly-ignore-parameter-bounds`, `Scop::Context` does not contain +; all the parameters present in the program. +; +; The construction of the `isl_multi_pw_aff` requires all the indivisual `pw_aff` +; to have the same parameter dimensions. To achieve this, we used to realign +; every `pw_aff` with `Scop::Context`. However, in conjunction with +; `-polly-ignore-parameter-bounds`, this is now incorrect, since `Scop::Context` +; does not contain all parameters. +; +; We check that Polly does the right thing in this case and sets up the parameter +; dimensions correctly. + + +; Check that kernel launch is generated in host IR. +; the declare would not be generated unless a call to a kernel exists. +; HOST-IR: declare void @polly_launchKernel(i8*, i32, i32, i32, i32, i32, i8*) + +target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: nounwind +declare noalias i8* @malloc() #0 + +; Function Attrs: nounwind uwtable +define void @__meteo_utilities_MOD_calps(i32* noalias %je) unnamed_addr #1 { +entry: + %0 = select i1 undef, i64 undef, i64 0 + %1 = load i32, i32* %je, align 4 + %2 = sext i32 %1 to i64 + %3 = tail call noalias i8* @malloc() #0 + br label %"13" + +"13": ; preds = %"13", %entry + %4 = phi i64 [ 1, %entry ], [ %10, %"13" ] + %5 = mul nuw nsw i64 %4, %0 + %6 = add i64 %5, 0 + %7 = add nsw i64 %6, 1 + %8 = bitcast i8* %3 to i32* + %9 = getelementptr i32, i32* %8, i64 %7 + store i32 1, i32* %9, align 4 + %10 = add nuw nsw i64 %4, 1 + %11 = icmp sgt i64 %10, %2 + br i1 %11, label %"12.17.loopexit_crit_edge", label %"13" + +"12.17.loopexit_crit_edge": ; preds = %"13" + ret void +} + +attributes #0 = { nounwind } +attributes #1 = { nounwind uwtable }