Index: lib/Support/ScopHelper.cpp =================================================================== --- lib/Support/ScopHelper.cpp +++ lib/Support/ScopHelper.cpp @@ -399,25 +399,6 @@ if (DominatesAllPredecessors) return false; - // FIXME: This is a simple heuristic to determine if the load is executed - // in a conditional. However, we actually would need the control - // condition, i.e., the post dominance frontier. Alternatively we - // could walk up the dominance tree until we find a block that is - // not post dominated by the load and check if it is a conditional - // or a loop header. - auto *DTNode = DT.getNode(&BB); - if (!DTNode) - return false; - - DTNode = DTNode->getIDom(); - - if (!DTNode) - return false; - - auto *IDomBB = DTNode->getBlock(); - if (LI.isLoopHeader(IDomBB)) - return false; - for (Instruction &Inst : BB) if (CallInst *CI = dyn_cast(&Inst)) { if (isIgnoredIntrinsic(CI)) Index: test/ScopDetect/mod_ref_read_pointer.ll =================================================================== --- test/ScopDetect/mod_ref_read_pointer.ll +++ test/ScopDetect/mod_ref_read_pointer.ll @@ -3,8 +3,8 @@ ; RUN: opt %loadPolly -basicaa -polly-detect -analyze \ ; RUN: < %s | FileCheck %s ; -; CHECK-NOT: Valid Region for Scop: for.cond => for.end -; MODREF: Valid Region for Scop: for.cond => for.end +; CHECK-NOT: Valid Region for Scop: for.body => for.end +; MODREF: Valid Region for Scop: for.body => for.end ; ; #pragma readonly ; int func(int *A); @@ -20,25 +20,22 @@ define void @jd(i32* %A) { entry: - br label %for.cond + br label %for.body -for.cond: ; preds = %for.inc, %entry - %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ] - %exitcond = icmp ne i64 %indvars.iv, 1024 - br i1 %exitcond, label %for.body, label %for.end - -for.body: ; preds = %for.cond +for.body: ; preds = %entry, %for.inc + %i = phi i64 [ 0, %entry ], [ %i.next, %for.inc ] %call = call i32 @func(i32* %A) - %tmp = add nsw i64 %indvars.iv, 2 + %tmp = add nsw i64 %i, 2 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %tmp store i32 %call, i32* %arrayidx, align 4 br label %for.inc for.inc: ; preds = %for.body - %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 - br label %for.cond + %i.next = add nuw nsw i64 %i, 1 + %exitcond = icmp ne i64 %i.next, 1024 + br i1 %exitcond, label %for.body, label %for.end -for.end: ; preds = %for.cond +for.end: ; preds = %for.inc ret void } Index: test/ScopInfo/max-loop-depth.ll =================================================================== --- test/ScopInfo/max-loop-depth.ll +++ test/ScopInfo/max-loop-depth.ll @@ -18,62 +18,56 @@ define void @foo(i32* %A, i32* %B, i64 %N, i64 %M) { entry: - br label %for.cond + %cmp1 = icmp slt i64 0, %M + br i1 %cmp1, label %for.body1, label %for.end1 -for.cond: ; preds = %for.inc13, %entry - %j.0 = phi i64 [ 0, %entry ], [ %inc14, %for.inc13 ] - %cmp = icmp slt i64 %j.0, %M - br i1 %cmp, label %for.body, label %for.end15 + for.body1: ; preds = %entry, %for.inc1 + %j.0 = phi i64 [ 0, %entry ], [ %j.next, %for.inc1 ] + call void (...) @bar() #0 + %cmp2 = icmp slt i64 0, %N + br i1 %cmp2, label %for.body2, label %for.end2 -for.body: ; preds = %for.cond - call void (...) @bar() #2 - br label %for.cond1 + for.body2: ; preds = %for.body1, %for.inc2 + %i.1 = phi i64 [ 0, %for.body1 ], [ %i.next.1, %for.inc2 ] + %arrayidx = getelementptr inbounds i32, i32* %A, i64 %i.1 + %tmp = load i32, i32* %arrayidx, align 4 + %add = add nsw i32 %tmp, 1 + store i32 %add, i32* %arrayidx, align 4 + br label %for.inc2 -for.cond1: ; preds = %for.inc, %for.body - %i.0 = phi i64 [ 0, %for.body ], [ %inc, %for.inc ] - %cmp2 = icmp slt i64 %i.0, %N - br i1 %cmp2, label %for.body3, label %for.end + for.inc2: ; preds = %for.body2 + %i.next.1 = add nuw nsw i64 %i.1, 1 + %cmp3 = icmp slt i64 %i.next.1, %N + br i1 %cmp3, label %for.body2, label %for.end2 -for.body3: ; preds = %for.cond1 - %arrayidx = getelementptr inbounds i32, i32* %A, i64 %i.0 - %tmp = load i32, i32* %arrayidx, align 4 - %add = add nsw i32 %tmp, 1 - store i32 %add, i32* %arrayidx, align 4 - br label %for.inc -for.inc: ; preds = %for.body3 - %inc = add nuw nsw i64 %i.0, 1 - br label %for.cond1 + for.end2: ; preds = %for.inc2, %for.body1 + %cmp4 = icmp slt i64 0, %N + br i1 %cmp4, label %for.body3, label %for.end3 -for.end: ; preds = %for.cond1 - br label %for.cond5 + for.body3: ; preds = %for.end2 + %i.2 = phi i64 [ 0, %for.end2 ], [ %i.next.2, %for.inc3 ] + %arrayidx1 = getelementptr inbounds i32, i32* %A, i64 %i.2 + %tmp1 = load i32, i32* %arrayidx1, align 4 + %add1 = add nsw i32 %tmp1, 1 + store i32 %add1, i32* %arrayidx1, align 4 + br label %for.inc3 -for.cond5: ; preds = %for.inc10, %for.end - %i4.0 = phi i64 [ 0, %for.end ], [ %inc11, %for.inc10 ] - %cmp6 = icmp slt i64 %i4.0, %N - br i1 %cmp6, label %for.body7, label %for.end12 + for.inc3: ; preds = %for.body3 + %i.next.2 = add nuw nsw i64 %i.2, 1 + %cmp5 = icmp slt i64 %i.next.2, %N + br i1 %cmp5, label %for.body3, label %for.end3 -for.body7: ; preds = %for.cond5 - %arrayidx8 = getelementptr inbounds i32, i32* %A, i64 %i4.0 - %tmp1 = load i32, i32* %arrayidx8, align 4 - %add9 = add nsw i32 %tmp1, 1 - store i32 %add9, i32* %arrayidx8, align 4 - br label %for.inc10 + for.end3: ; preds = %for.inc3, %for.end2 + br label %for.inc1 -for.inc10: ; preds = %for.body7 - %inc11 = add nuw nsw i64 %i4.0, 1 - br label %for.cond5 + for.inc1: ; preds = %for.end3 + %j.next = add nuw nsw i64 %j.0, 1 + %cmp6 = icmp slt i64 %j.next, %M + br i1 %cmp6, label %for.body1, label %for.end1 -for.end12: ; preds = %for.cond5 - br label %for.inc13 - -for.inc13: ; preds = %for.end12 - %inc14 = add nuw nsw i64 %j.0, 1 - br label %for.cond - -for.end15: ; preds = %for.cond - ret void -} - -declare void @bar(...) #1 + for.end1: ; preds = %entry, %for.inc1 + ret void + } +declare void @bar(...) #0 Index: test/ScopInfo/mod_ref_access_pointee_arguments.ll =================================================================== --- test/ScopInfo/mod_ref_access_pointee_arguments.ll +++ test/ScopInfo/mod_ref_access_pointee_arguments.ll @@ -29,27 +29,24 @@ define void @jd(i32* noalias %A, i32* noalias %B) { entry: - br label %for.cond + br label %for.body -for.cond: ; preds = %for.inc, %entry - %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ] - %exitcond = icmp ne i64 %indvars.iv, 1024 - br i1 %exitcond, label %for.body, label %for.end - -for.body: ; preds = %for.cond - %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv - %arrayidx2 = getelementptr inbounds i32, i32* %B, i64 %indvars.iv +for.body: ; preds = %entry, %for.inc + %i = phi i64 [ 0, %entry ], [ %i.next, %for.inc ] + %arrayidx = getelementptr inbounds i32, i32* %A, i64 %i + %arrayidx1 = getelementptr inbounds i32, i32* %B, i64 %i %bc = bitcast i32* %arrayidx to i8* call void @f(i8* %bc, i32 1, i32 1, i32 1) - %tmp = load i32, i32* %arrayidx2 + %tmp = load i32, i32* %arrayidx1 store i32 %tmp, i32* %arrayidx, align 4 br label %for.inc for.inc: ; preds = %for.body - %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 - br label %for.cond + %i.next = add nuw nsw i64 %i, 1 + %exitcond = icmp ne i64 %i.next, 1024 + br i1 %exitcond, label %for.body, label %for.end -for.end: ; preds = %for.cond +for.end: ; preds = %for.inc ret void } Index: test/ScopInfo/mod_ref_read_pointee_arguments.ll =================================================================== --- test/ScopInfo/mod_ref_read_pointee_arguments.ll +++ test/ScopInfo/mod_ref_read_pointee_arguments.ll @@ -36,29 +36,26 @@ %dummyloc = alloca i8* br label %entry.split -entry.split: - br label %for.cond +entry.split: ; preds = %entry + br label %for.body -for.cond: ; preds = %for.inc, %entry.split - %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry.split ] - %exitcond = icmp ne i64 %indvars.iv, 1024 - br i1 %exitcond, label %for.body, label %for.end - -for.body: ; preds = %for.cond - %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv - %arrayidx2 = getelementptr inbounds i32, i32* %B, i64 %indvars.iv +for.body: ; preds = %entry.split, %for.inc + %i = phi i64 [ 0, %entry.split ], [ %i.next, %for.inc ] + %arrayidx = getelementptr inbounds i32, i32* %A, i64 %i + %arrayidx1 = getelementptr inbounds i32, i32* %B, i64 %i %bc = bitcast i32* %arrayidx to i8* %dummy = call i8* @f(i8* %bc, i8** null) store i8* %dummy, i8** %dummyloc, align 4 - %tmp = load i32, i32* %arrayidx2 + %tmp = load i32, i32* %arrayidx1 store i32 %tmp, i32* %arrayidx, align 4 br label %for.inc for.inc: ; preds = %for.body - %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 - br label %for.cond + %i.next = add nuw nsw i64 %i, 1 + %exitcond = icmp ne i64 %i.next, 1024 + br i1 %exitcond, label %for.body, label %for.end -for.end: ; preds = %for.cond +for.end: ; preds = %for.inc ret void } Index: test/ScopInfo/mod_ref_read_pointer.ll =================================================================== --- test/ScopInfo/mod_ref_read_pointer.ll +++ test/ScopInfo/mod_ref_read_pointer.ll @@ -27,28 +27,25 @@ define void @jd(i32* %A) { entry: - br label %for.cond + br label %for.body -for.cond: ; preds = %for.inc, %entry - %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ] - %exitcond = icmp ne i64 %indvars.iv, 1024 - br i1 %exitcond, label %for.body, label %for.end - -for.body: ; preds = %for.cond +for.body: ; preds = %entry, %for.inc + %i = phi i64 [ 0, %entry ], [ %i.next, %for.inc ] %call = call i32 @func(i32* %A) #2 - %tmp = add nsw i64 %indvars.iv, 2 + %tmp = add nsw i64 %i, 2 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %tmp store i32 %call, i32* %arrayidx, align 4 br label %for.inc for.inc: ; preds = %for.body - %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 - br label %for.cond + %i.next = add nuw nsw i64 %i, 1 + %exitcond = icmp ne i64 %i.next, 1024 + br i1 %exitcond, label %for.body, label %for.end -for.end: ; preds = %for.cond +for.end: ; preds = %for.inc ret void } -declare i32 @func(i32*) #1 +declare i32 @func(i32*) #0 -attributes #1 = { nounwind readonly } +attributes #0 = { nounwind readonly } Index: test/ScopInfo/mod_ref_read_pointers.ll =================================================================== --- test/ScopInfo/mod_ref_read_pointers.ll +++ test/ScopInfo/mod_ref_read_pointers.ll @@ -32,31 +32,28 @@ define void @jd(i32* noalias %A, i32* noalias %B) { entry: - br label %for.cond + br label %for.body -for.cond: ; preds = %for.inc, %entry - %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ] - %exitcond = icmp ne i64 %indvars.iv, 1024 - br i1 %exitcond, label %for.body, label %for.end - -for.body: ; preds = %for.cond +for.body: ; preds = %entry, %for.inc + %i = phi i64 [ 0, %entry ], [ %i.next, %for.inc ] %call = call i32 @func(i32* %A) - %arrayidx = getelementptr inbounds i32, i32* %B, i64 %indvars.iv + %arrayidx = getelementptr inbounds i32, i32* %B, i64 %i %tmp = load i32, i32* %arrayidx, align 4 %add = add nsw i32 %call, %tmp - %tmp2 = add nsw i64 %indvars.iv, 2 - %arrayidx3 = getelementptr inbounds i32, i32* %A, i64 %tmp2 - store i32 %add, i32* %arrayidx3, align 4 + %tmp1 = add nsw i64 %i, 2 + %arrayidx1 = getelementptr inbounds i32, i32* %A, i64 %tmp1 + store i32 %add, i32* %arrayidx1, align 4 br label %for.inc for.inc: ; preds = %for.body - %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 - br label %for.cond + %i.next = add nuw nsw i64 %i, 1 + %exitcond = icmp ne i64 %i.next, 1024 + br i1 %exitcond, label %for.body, label %for.end -for.end: ; preds = %for.cond +for.end: ; preds = %for.inc ret void } -declare i32 @func(i32*) #1 +declare i32 @func(i32*) #0 -attributes #1 = { nounwind readonly } +attributes #0 = { nounwind readonly }