Index: lib/Analysis/ScopInfo.cpp =================================================================== --- lib/Analysis/ScopInfo.cpp +++ lib/Analysis/ScopInfo.cpp @@ -2142,6 +2142,15 @@ } } + for (int i = 0, e = isl_set_dim(Set, isl_dim_out); i != e; ++i) { + if (!isl_set_dim_has_lower_bound(Set, isl_dim_out, i) || + !isl_set_dim_has_upper_bound(Set, isl_dim_out, i)) { + DEBUG(dbgs() << "Non-affine set with unknown bounds\n"); + isl_set_free(Set); + return isl_stat_error; + } + } + MinPMA = isl_set_lexmin_pw_multi_aff(isl_set_copy(Set)); MaxPMA = isl_set_lexmax_pw_multi_aff(isl_set_copy(Set)); @@ -3021,20 +3030,12 @@ // Check if we have non-affine accesses left, if so bail out as we cannot // generate a good access range yet. for (auto *MA : AG) { - if (!MA->isAffine()) { - invalidate(ALIASING, MA->getAccessInstruction()->getDebugLoc()); - return false; - } if (auto *BasePtrMA = lookupBasePtrAccess(MA)) addRequiredInvariantLoad( cast(BasePtrMA->getAccessInstruction())); } for (auto &ReadOnlyPair : ReadOnlyPairs) for (auto *MA : ReadOnlyPair.second) { - if (!MA->isAffine()) { - invalidate(ALIASING, MA->getAccessInstruction()->getDebugLoc()); - return false; - } if (auto *BasePtrMA = lookupBasePtrAccess(MA)) addRequiredInvariantLoad( cast(BasePtrMA->getAccessInstruction())); Index: test/ScopInfo/aliasing_with_non_affine_access.ll =================================================================== --- test/ScopInfo/aliasing_with_non_affine_access.ll +++ test/ScopInfo/aliasing_with_non_affine_access.ll @@ -1,18 +1,18 @@ -; RUN: opt %loadPolly -analyze -polly-scops < %s | FileCheck %s -; RUN: opt %loadPolly -analyze -polly-scops -pass-remarks-analysis="polly-scops" 2>&1 < %s | FileCheck %s --check-prefix=REMARK +; RUN: opt %loadPolly -analyze -polly-ast -polly-process-unprofitable -polly-allow-nonaffine < %s | FileCheck %s ; -; This test case has a non-affine access (the memset call) that aliases with -; other accesses. Thus, we bail out. -; -; CHECK-NOT: Statements -; -; REMARK: remark: :0:0: SCoP begins here. -; REMARK-NEXT: remark: :0:0: Possibly aliasing pointer, use restrict keyword. -; REMARK-NEXT: remark: :0:0: Possibly aliasing pointer, use restrict keyword. -; REMARK-NEXT: remark: :0:0: No-aliasing assumption: { : 1 = 0 } -; REMARK-NEXT: remark: :0:0: SCoP ends here but was dismissed. +; @test1 +; Make sure we generate the correct aliasing check for a fixed-size memset operation. +; CHECK: if (1 && (&MemRef_0[15] <= &MemRef_1[0] || &MemRef_1[32] <= &MemRef_0[14])) + +; @test2 +; Make sure we generate the correct aliasing check for a variable-size memset operation. +; CHECK: if (1 && (&MemRef_0[15] <= &MemRef_1[0] || &MemRef_1[n] <= &MemRef_0[14])) ; -; ModuleID = 'bugpoint-reduced-simplified.bc' +; @test3 +; FIXME: We should reject this. The runtime check is in some sense correct, +; but it's impossible to satisfy. +; CHECK: if (1 && (&MemRef_A[2305843009213693952] <= &MemRef_B[0] || &MemRef_B[n] <= &MemRef_A[-2305843009213693952])) + target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" %struct.info = type { i32, %struct.ctr*, i32, %struct.ord*, %struct.ctr*, i32, i8*, i32, i32, double } @@ -22,8 +22,7 @@ ; Function Attrs: argmemonly nounwind declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) #0 -; Function Attrs: nounwind uwtable -define void @bestVirtualIndex(%struct.info** %ppIdxInfo) { +define void @test(%struct.info** %ppIdxInfo) { entry: %0 = load %struct.info*, %struct.info** %ppIdxInfo, align 8 br label %if.end125 @@ -46,4 +45,60 @@ unreachable } +define void @test2(%struct.info** %ppIdxInfo, i64 %n) { +entry: + %0 = load %struct.info*, %struct.info** %ppIdxInfo, align 8 + br label %if.end125 + +if.end125: ; preds = %entry + %1 = load %struct.ctr*, %struct.ctr** undef, align 8 + br label %for.end143 + +for.end143: ; preds = %if.end125 + %2 = bitcast %struct.ctr* %1 to i8* + tail call void @llvm.memset.p0i8.i64(i8* %2, i8 0, i64 %n, i32 4, i1 false) + %needToFreeIdxStr = getelementptr inbounds %struct.info, %struct.info* %0, i64 0, i32 7 + %3 = load i32, i32* %needToFreeIdxStr, align 8 + br i1 false, label %if.end149, label %if.then148 + +if.then148: ; preds = %for.end143 + br label %if.end149 + +if.end149: ; preds = %if.then148, %for.end143 + unreachable +} + +define void @test3(i32* nocapture readonly %A, i32* nocapture %B, i32 %n) local_unnamed_addr #0 { +entry: + br label %entry.split + +entry.split: ; preds = %entry + %conv = zext i32 %n to i64 + %cmp8 = icmp eq i32 %n, 0 + br i1 %cmp8, label %for.cond.cleanup, label %for.body.preheader + +for.body.preheader: ; preds = %entry.split + br label %for.body + +for.cond.cleanup.loopexit: ; preds = %for.body + br label %for.cond.cleanup + +for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry.split + ret void + +for.body: ; preds = %for.body.preheader, %for.body + %i.09 = phi i64 [ %inc, %for.body ], [ 0, %for.body.preheader ] + %mul = mul nsw i64 %i.09, %i.09 + %arrayidx = getelementptr inbounds i32, i32* %A, i64 %mul + %0 = load i32, i32* %arrayidx, align 4 + %arrayidx2 = getelementptr inbounds i32, i32* %B, i64 %i.09 + %1 = load i32, i32* %arrayidx2, align 4 + %add = add nsw i32 %1, %0 + store i32 %add, i32* %arrayidx2, align 4 + %inc = add nuw nsw i64 %i.09, 1 + %exitcond = icmp eq i64 %inc, %conv + br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body +} + + attributes #0 = { argmemonly nounwind }