Index: lib/Analysis/ScopInfo.cpp =================================================================== --- lib/Analysis/ScopInfo.cpp +++ lib/Analysis/ScopInfo.cpp @@ -3975,12 +3975,39 @@ ArrayRef(), ScopArrayInfo::MK_Value); } void ScopInfo::ensureValueRead(Value *Value, BasicBlock *UserBB) { + + // There cannot be an "access" for constants. + if (isa(Value) || isa(Value) || + isa(Value)) + return; + + // If the instruction can be synthesized and the user is in the region we do + // not need to add a value dependences. + Region &ScopRegion = scop->getRegion(); + if (canSynthesize(Value, LI, SE, &ScopRegion)) + return; + + // Determine the ScopStmt containing the value's definition and use. There is + // no defining ScopStmt if the value is a function argument, a global value, + // or defined outside the SCoP. + Instruction *ValueInst = dyn_cast(Value); + ScopStmt *ValueStmt = + ValueInst ? scop->getStmtForBasicBlock(ValueInst->getParent()) : nullptr; + ScopStmt *UserStmt = scop->getStmtForBasicBlock(UserBB); // We do not model uses outside the scop. if (!UserStmt) return; + // Add MemoryAccess for invariant values only if requested. + if (!ModelReadOnlyScalars && !ValueStmt) + return; + + // Ignore use-def chains within the same ScopStmt. + if (ValueStmt == UserStmt) + return; + // Do not create another MemoryAccess for reloading the value if one already // exists. if (UserStmt->lookupValueReadOf(Value)) Index: test/Isl/CodeGen/phi-defined-before-scop.ll =================================================================== --- test/Isl/CodeGen/phi-defined-before-scop.ll +++ test/Isl/CodeGen/phi-defined-before-scop.ll @@ -4,8 +4,7 @@ ; CHECK-NEXT: %tmp7.ph.merge = phi %struct.wibble* [ %tmp7.ph.final_reload, %polly.exiting ], [ %tmp7.ph, %bb6.region_exiting ] ; CHECK-LABEL: polly.stmt.bb3: -; CHECK-NEXT: %tmp2.s2a.reload = load %struct.wibble*, %struct.wibble** %tmp2.s2a -; CHECK-NEXT: store %struct.wibble* %tmp2.s2a.reload, %struct.wibble** %tmp7.s2a +; CHECK-NEXT: store %struct.wibble* %tmp2, %struct.wibble** %tmp7.s2a target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" Index: test/Isl/CodeGen/synthesizable_phi_write_after_loop.ll =================================================================== --- test/Isl/CodeGen/synthesizable_phi_write_after_loop.ll +++ test/Isl/CodeGen/synthesizable_phi_write_after_loop.ll @@ -8,17 +8,11 @@ ; In this case the Loop passed to the expander must NOT be the loop ; - Overwriting the same alloca in each iteration s.t. the last value will ; retain in %i.inc.s2a -; The latter is currently generated by Polly and tested here. +; The the first is currently generated by Polly and tested here. ; CHECK: polly.stmt.next: -; CHECK-NEXT: %i.inc.s2a.reload = load i32, i32* %i.inc.s2a -; CHECK-NEXT: store i32 %i.inc.s2a.reload, i32* %phi.phiops +; CHECK-NEXT: store i32 2, i32* %phi.phiops ; CHECK-NEXT: br label %polly.stmt.join -; -; CHECK: polly.stmt.loop: -; CHECK: %0 = trunc i64 %polly.indvar to i32 -; CHECK: %1 = add i32 %0, 1 -; CHECK: store i32 %1, i32* %i.inc.s2a define i32 @func() { entry: Index: test/Isl/CodeGen/uninitialized_scalar_memory.ll =================================================================== --- test/Isl/CodeGen/uninitialized_scalar_memory.ll +++ test/Isl/CodeGen/uninitialized_scalar_memory.ll @@ -5,7 +5,6 @@ ; ; CHECK: polly.start: ; CHECK-NEXT: store float %ebig.0, float* %ebig.0.s2a -; CHECK-NEXT: store i32 %iebig.0, i32* %iebig.0.s2a ; CHECK-NEXT: br label %polly.stmt.if.end.entry ; ; int g(void); Index: test/ScopInfo/NonAffine/non_affine_loop_used_later.ll =================================================================== --- test/ScopInfo/NonAffine/non_affine_loop_used_later.ll +++ test/ScopInfo/NonAffine/non_affine_loop_used_later.ll @@ -25,7 +25,6 @@ ; CHECK-NEXT: i32 MemRef_j_0__phi; // Element size 4 ; CHECK-NEXT: i32 MemRef_j_0; // Element size 4 ; CHECK-NEXT: i32 MemRef_A[*]; // Element size 4 -; CHECK-NEXT: i32 MemRef_smax; // Element size 4 ; CHECK-NEXT: i32 MemRef_j_2__phi; // Element size 4 ; CHECK-NEXT: i32 MemRef_j_2; // Element size 4 ; CHECK-NEXT: } @@ -33,7 +32,6 @@ ; CHECK-NEXT: i32 MemRef_j_0__phi; // Element size 4 ; CHECK-NEXT: i32 MemRef_j_0; // Element size 4 ; CHECK-NEXT: i32 MemRef_A[*]; // Element size 4 -; CHECK-NEXT: i32 MemRef_smax; // Element size 4 ; CHECK-NEXT: i32 MemRef_j_2__phi; // Element size 4 ; CHECK-NEXT: i32 MemRef_j_2; // Element size 4 ; CHECK-NEXT: } @@ -60,8 +58,6 @@ ; CHECK-NEXT: [N] -> { Stmt_bb4__TO__bb18[i0] -> MemRef_A[i0] }; ; CHECK-NEXT: MayWriteAccess := [Reduction Type: NONE] [Scalar: 0] ; CHECK-NEXT: [N] -> { Stmt_bb4__TO__bb18[i0] -> MemRef_A[i0] }; -; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] -; CHECK-NEXT: [N] -> { Stmt_bb4__TO__bb18[i0] -> MemRef_smax[] }; ; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] ; CHECK-NEXT: [N] -> { Stmt_bb4__TO__bb18[i0] -> MemRef_j_2__phi[] }; ; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] Index: test/ScopInfo/non_affine_region_1.ll =================================================================== --- test/ScopInfo/non_affine_region_1.ll +++ test/ScopInfo/non_affine_region_1.ll @@ -41,8 +41,6 @@ ; CHECK-NEXT: [b] -> { Stmt_bb8[0] : b = 0 }; ; CHECK-NEXT: Schedule := ; CHECK-NEXT: [b] -> { Stmt_bb8[i0] -> [0, 0] }; -; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] -; CHECK-NEXT: [b] -> { Stmt_bb8[i0] -> MemRef_b[] }; ; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] ; CHECK-NEXT: [b] -> { Stmt_bb8[i0] -> MemRef_x_1__phi[] }; ; CHECK-NEXT: Stmt_bb10__TO__bb18 Index: test/ScopInfo/non_affine_region_3.ll =================================================================== --- test/ScopInfo/non_affine_region_3.ll +++ test/ScopInfo/non_affine_region_3.ll @@ -31,8 +31,6 @@ ; CHECK-NEXT: { Stmt_bb3__TO__bb18[i0] -> MemRef_A[i0] }; ; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] ; CHECK-NEXT: { Stmt_bb3__TO__bb18[i0] -> MemRef_x_2__phi[] }; -; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] -; CHECK-NEXT: { Stmt_bb3__TO__bb18[i0] -> MemRef_b[] }; ; CHECK-NEXT: Stmt_bb18 ; CHECK-NEXT: Domain := ; CHECK-NEXT: { Stmt_bb18[i0] : 0 <= i0 <= 1023 }; Index: test/ScopInfo/pointer-used-as-base-pointer-and-scalar-read.ll =================================================================== --- test/ScopInfo/pointer-used-as-base-pointer-and-scalar-read.ll +++ test/ScopInfo/pointer-used-as-base-pointer-and-scalar-read.ll @@ -6,16 +6,12 @@ ; CHECK: Arrays { ; CHECK-NEXT: float MemRef_A[*]; // Element size 4 -; CHECK-NEXT: float* MemRef_A; // Element size 8 ; CHECK-NEXT: float* MemRef_x__phi; // Element size 8 -; CHECK-NEXT: float* MemRef_B; // Element size 8 ; CHECK-NEXT: float* MemRef_C[*]; // Element size 8 ; CHECK-NEXT: } ; CHECK: Arrays (Bounds as pw_affs) { ; CHECK-NEXT: float MemRef_A[*]; // Element size 4 -; CHECK-NEXT: float* MemRef_A; // Element size 8 ; CHECK-NEXT: float* MemRef_x__phi; // Element size 8 -; CHECK-NEXT: float* MemRef_B; // Element size 8 ; CHECK-NEXT: float* MemRef_C[*]; // Element size 8 ; CHECK-NEXT: } ; CHECK: Alias Groups (0): @@ -28,8 +24,6 @@ ; CHECK-NEXT: [p] -> { Stmt_then[i0] -> [i0, 1] }; ; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 0] ; CHECK-NEXT: [p] -> { Stmt_then[i0] -> MemRef_A[0] }; -; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] -; CHECK-NEXT: [p] -> { Stmt_then[i0] -> MemRef_A[] }; ; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] ; CHECK-NEXT: [p] -> { Stmt_then[i0] -> MemRef_x__phi[] }; ; CHECK-NEXT: Stmt_else @@ -39,8 +33,6 @@ ; CHECK-NEXT: [p] -> { Stmt_else[i0] -> [i0, 0] : p >= 33 or p <= 31 }; ; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 0] ; CHECK-NEXT: [p] -> { Stmt_else[i0] -> MemRef_A[0] }; -; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] -; CHECK-NEXT: [p] -> { Stmt_else[i0] -> MemRef_B[] }; ; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] ; CHECK-NEXT: [p] -> { Stmt_else[i0] -> MemRef_x__phi[] }; ; CHECK-NEXT: Stmt_bb8 Index: test/ScopInfo/same-base-address-scalar-and-array.ll =================================================================== --- test/ScopInfo/same-base-address-scalar-and-array.ll +++ test/ScopInfo/same-base-address-scalar-and-array.ll @@ -4,7 +4,6 @@ ; as it is used as a memory base pointer (%0) but also as a scalar (%out.addr.0.lcssa). ; ; CHECK: Arrays { -; CHECK-NEXT: float* MemRef_out; // Element size 8 ; CHECK-NEXT: float* MemRef_out_addr_0_lcssa; // Element size 8 ; CHECK-NEXT: float MemRef_out[*]; // Element size 4 ; CHECK-NEXT: }