Index: include/polly/TempScopInfo.h =================================================================== --- include/polly/TempScopInfo.h +++ include/polly/TempScopInfo.h @@ -268,12 +268,14 @@ /// @brief Analyze and extract the cross-BB scalar dependences (or, /// dataflow dependencies) of an instruction. /// - /// @param Inst The instruction to be analyzed - /// @param R The SCoP region + /// @param Inst The instruction to be analyzed + /// @param R The SCoP region + /// @param Functions The access functions of the current BB /// /// @return True if the Instruction is used in other BB and a scalar write /// Access is required. - bool buildScalarDependences(Instruction *Inst, Region *R); + bool buildScalarDependences(Instruction *Inst, Region *R, + AccFuncSetType &Functions); /// @brief Create IRAccesses for the given PHI node in the given region. /// Index: lib/Analysis/TempScopInfo.cpp =================================================================== --- lib/Analysis/TempScopInfo.cpp +++ lib/Analysis/TempScopInfo.cpp @@ -140,10 +140,14 @@ Functions.push_back(std::make_pair(ScalarAccess, PHI)); } -bool TempScopInfo::buildScalarDependences(Instruction *Inst, Region *R) { +bool TempScopInfo::buildScalarDependences(Instruction *Inst, Region *R, + AccFuncSetType &Functions) { // No need to translate these scalar dependences into polyhedral form, because - // synthesizable scalars can be generated by the code generator. - if (canSynthesize(Inst, LI, SE, R)) + // synthesizable scalars can be generated by the code generator. However, only + // if the statement is non-trivial, hence there is at least one access in the + // statement. + bool canSynthesizeInst = canSynthesize(Inst, LI, SE, R); + if (canSynthesizeInst && !Functions.empty()) return false; if (isIgnoredIntrinsic(Inst)) return false; @@ -164,20 +168,28 @@ if (UseParent == ParentBB) continue; + // Check whether or not the use is in the SCoP. + bool inRegion = R->contains(UseParent); + + // If the instruction can be synthesized and the user is in the region + // we do not need to add scalar dependences. + if (inRegion && canSynthesizeInst) + continue; + // No need to translate these scalar dependences into polyhedral form, // because synthesizable scalars can be generated by the code generator. - if (canSynthesize(UI, LI, SE, R)) + if (inRegion && canSynthesize(UI, LI, SE, R)) continue; - // Skip PHI nodes as they handle their operands on their own. - if (isa(UI)) + // Skip PHI nodes in the region as they handle their operands on their own. + if (inRegion && isa(UI)) continue; // Now U is used in another statement. AnyCrossStmtUse = true; // Do not build a read access that is not in the current SCoP - if (!R->contains(UseParent)) + if (!inRegion) continue; // Use the def instruction as base address of the IRAccess, so that it will @@ -244,7 +256,7 @@ if (PHINode *PHI = dyn_cast(Inst)) buildPHIAccesses(PHI, R, Functions); - if (!isa(Inst) && buildScalarDependences(Inst, &R)) { + if (!isa(Inst) && buildScalarDependences(Inst, &R, Functions)) { // If the Instruction is used outside the statement, we need to build the // write access. IRAccess ScalarAccess(IRAccess::MUST_WRITE, Inst, ZeroOffset, 1, true); Index: test/ScopInfo/escaping_empty_scop.ll =================================================================== --- /dev/null +++ test/ScopInfo/escaping_empty_scop.ll @@ -0,0 +1,41 @@ +; RUN: opt %loadPolly -polly-scops -disable-polly-intra-scop-scalar-to-array -polly-model-phi-nodes -analyze < %s | FileCheck %s +; +; void g(); +; int f(int *A) { +; int a = 0; +; for (int i = 0; i < 1000; i++) +; a = 2 * i; +; g(); +; return a; +; } +; +; CHECK: Stmt_bb1 +; CHECK: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] +; CHECK: { Stmt_bb1[i0] -> MemRef_a_0[] }; + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +define i32 @f(i32* %A) { +bb: + br label %bb1 + +bb1: ; preds = %bb3, %bb + %i.0 = phi i32 [ 0, %bb ], [ %tmp4, %bb3 ] + %a.0 = mul i32 %i.0, 2 + %exitcond = icmp ne i32 %i.0, 1000 + br i1 %exitcond, label %bb2, label %bb5 + +bb2: ; preds = %bb1 + br label %bb3 + +bb3: ; preds = %bb2 + %tmp = shl nsw i32 %i.0, 1 + %tmp4 = add nuw nsw i32 %i.0, 1 + br label %bb1 + +bb5: ; preds = %bb1 + call void (...)* @g() #2 + ret i32 %a.0 +} + +declare void @g(...) #1