Index: include/polly/ScopInfo.h =================================================================== --- include/polly/ScopInfo.h +++ include/polly/ScopInfo.h @@ -1399,6 +1399,9 @@ return getRegion()->contains(L); } + /// Check if the statement contains boxed loops. + bool hasBoxedLoops() const; + /// Return whether this statement represents @p BB. bool represents(BasicBlock *BB) const { if (isCopyStmt()) @@ -1601,7 +1604,6 @@ /// Insert an instruction before all other instructions in this statement. void prependInstruction(Instruction *Inst) { - assert(isBlockStmt() && "Only block statements support instruction lists"); Instructions.insert(Instructions.begin(), Inst); } @@ -1927,9 +1929,6 @@ Scop(Region &R, ScalarEvolution &SE, LoopInfo &LI, ScopDetection::DetectionContext &DC, OptimizationRemarkEmitter &ORE); - /// Return the LoopInfo used for this Scop. - LoopInfo *getLI() const { return Affinator.getLI(); } - //@} /// Initialize this ScopBuilder. @@ -2370,6 +2369,9 @@ Scop &operator=(const Scop &) = delete; ~Scop(); + /// Return the LoopInfo used for this Scop. + LoopInfo *getLI() const { return Affinator.getLI(); } + /// Get the count of copy statements added to this Scop. /// /// @return The count of copy statements added to this Scop. Index: lib/Analysis/ScopInfo.cpp =================================================================== --- lib/Analysis/ScopInfo.cpp +++ lib/Analysis/ScopInfo.cpp @@ -1737,6 +1737,24 @@ return getRegion()->getEntry(); } +bool ScopStmt::hasBoxedLoops() const { + Loop *L = getSurroundingLoop(); + + if (L) { + for (Loop *L : L->getSubLoops()) + if (contains(L)) + return true; + } + + LoopInfo *LI = getParent()->getLI(); + + for (Loop *L : make_range(LI->begin(), LI->end())) + if (contains(L)) + return true; + + return false; +} + unsigned ScopStmt::getNumIterators() const { return NestLoops.size(); } const char *ScopStmt::getBaseName() const { return BaseName.c_str(); } Index: lib/Transform/ForwardOpTree.cpp =================================================================== --- lib/Transform/ForwardOpTree.cpp +++ lib/Transform/ForwardOpTree.cpp @@ -767,10 +767,6 @@ /// to forward them into the statement. bool forwardOperandTrees() { for (ScopStmt &Stmt : *S) { - // Currently we cannot modify the instruction list of region statements. - if (!Stmt.isBlockStmt()) - continue; - bool StmtModified = false; // Because we are modifying the MemoryAccess list, collect them first to Index: lib/Transform/ZoneAlgo.cpp =================================================================== --- lib/Transform/ZoneAlgo.cpp +++ lib/Transform/ZoneAlgo.cpp @@ -376,7 +376,7 @@ // In region statements the order is less clear, eg. the load and store // might be in a boxed loop. - if (Stmt->isRegionStmt() && + if (Stmt->hasBoxedLoops() && !isl_union_map_is_disjoint(Loads.keep(), AccRel.keep())) { DEBUG(dbgs() << "WRITE in non-affine subregion not supported\n"); OptimizationRemarkMissed R(PassName, "StoreInSubregion", Index: test/DeLICM/reject_storeinsubregion.ll =================================================================== --- test/DeLICM/reject_storeinsubregion.ll +++ test/DeLICM/reject_storeinsubregion.ll @@ -75,5 +75,11 @@ ret void } - -; CHECK: store is in a non-affine subregion +; CHECK: DeLICM result: +; CHECK-NEXT: Statistics { +; CHECK-NEXT: Compatible overwrites: 1 +; CHECK-NEXT: Overwrites mapped to: 0 +; CHECK-NEXT: Value scalars mapped: 0 +; CHECK-NEXT: PHI scalars mapped: 0 +; CHECK-NEXT: } +; CHECK-NEXT: No modification has been made Index: test/ForwardOpTree/forward_region.ll =================================================================== --- /dev/null +++ test/ForwardOpTree/forward_region.ll @@ -0,0 +1,71 @@ +; RUN: opt %loadPolly -polly-optree -analyze < %s | FileCheck %s -match-full-lines +; +; Move instructions to region statements. +; +; for (int j = 0; j < n; j += 1) { +; bodyA: +; double val = 21.0 + 21.0; +; +; bodyB_entry: +; if (undef) +; body_true: +; A[0] = val; +; } +; +define void @func(i32 %n, double* noalias nonnull %A) { +entry: + br label %for + +for: + %j = phi i32 [0, %entry], [%j.inc, %inc] + %j.cmp = icmp slt i32 %j, %n + br i1 %j.cmp, label %bodyA, label %exit + + bodyA: + %val = fadd double 21.0, 21.0 + br label %bodyB + + bodyB: + %cond = fcmp oeq double 21.0, 21.0 + br i1 %cond, label %bodyB_true, label %bodyB_exit + + bodyB_true: + store double %val, double* %A + br label %bodyB_exit + + bodyB_exit: + br label %inc + +inc: + %j.inc = add nuw nsw i32 %j, 1 + br label %for + +exit: + br label %return + +return: + ret void +} + +; CHECK: Statistics { +; CHECK-NEXT: Instructions copied: 1 +; CHECK-NEXT: Known loads forwarded: 0 +; CHECK-NEXT: Read-only accesses copied: 0 +; CHECK-NEXT: Operand trees forwarded: 1 +; CHECK-NEXT: Statements with forwarded operand trees: 1 +; CHECK-NEXT: } +; CHECK-NEXT: After statements { +; CHECK-NEXT: Stmt_bodyA +; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] +; CHECK-NEXT: [n] -> { Stmt_bodyA[i0] -> MemRef_val[] }; +; CHECK-NEXT: Instructions { +; CHECK-NEXT: %val = fadd double 2.100000e+01, 2.100000e+01 +; CHECK-NEXT: } +; CHECK-NEXT: Stmt_bodyB__TO__bodyB_exit +; CHECK-NEXT: MayWriteAccess := [Reduction Type: NONE] [Scalar: 0] +; CHECK-NEXT: [n] -> { Stmt_bodyB__TO__bodyB_exit[i0] -> MemRef_A[0] }; +; CHECK-NEXT: Instructions { +; CHECK-NEXT: %val = fadd double 2.100000e+01, 2.100000e+01 +; CHECK-NEXT: %cond = fcmp oeq double 2.100000e+01, 2.100000e+01 +; CHECK-NEXT: } +; CHECK-NEXT: } Index: test/ForwardOpTree/noforward_region.ll =================================================================== --- test/ForwardOpTree/noforward_region.ll +++ /dev/null @@ -1,51 +0,0 @@ -; RUN: opt %loadPolly -polly-optree -analyze < %s | FileCheck %s -match-full-lines -; -; Do not move instructions to region statements. -; -; for (int j = 0; j < n; j += 1) { -; bodyA: -; double val = 21.0 + 21.0; -; -; bodyB_entry: -; if (undef) -; body_true: -; A[0] = val; -; } -; -define void @func(i32 %n, double* noalias nonnull %A) { -entry: - br label %for - -for: - %j = phi i32 [0, %entry], [%j.inc, %inc] - %j.cmp = icmp slt i32 %j, %n - br i1 %j.cmp, label %bodyA, label %exit - - bodyA: - %val = fadd double 21.0, 21.0 - br label %bodyB - - bodyB: - %cond = fcmp oeq double 21.0, 21.0 - br i1 %cond, label %bodyB_true, label %bodyB_exit - - bodyB_true: - store double %val, double* %A - br label %bodyB_exit - - bodyB_exit: - br label %inc - -inc: - %j.inc = add nuw nsw i32 %j, 1 - br label %for - -exit: - br label %return - -return: - ret void -} - - -; CHECK: ForwardOpTree executed, but did not modify anything