[PATCH] D41692: [Polly][WIP] Remove immediate dominator heuristic for error block detection.
Michael Kruse via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 30 11:53:54 PDT 2018
Meinersbur added a comment.
If a function is `readnone`, `CI->doesNotAccessMemory()` already returns true, i.e. `isErrorBlock` does not care about it.
If a function is `readonly`, it can read from any address. Therefore there might be a dependency from and to any memory-writing instruction. But by itself, it does not hinder us from transforming a loop if there is no write to memory in it (which probably is rare). Also, the `-polly-allow-modref-calls` is required to allow it.
In any case, if such a call is only executed conditionally, we may assume that the condition is never true so the function is never called and we can optimize the loop as if the call wasn't there.
With the test case, I think I understand what the heuristic was trying to do. It tries to identify the loop exit condition because the assumption that the loop is never executed is not an optimistic one.
However, after `-loop-rotate` (Polly always runs after loop-rotate), the loop exit condition is moved away from the loop header:
define void @jd(i32* %A) {
entry:
br label %for.body
for.body: ; preds = %entry, %for.inc
%indvars.iv1 = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.inc ]
%call = call i32 @func(i32* %A)
%tmp = add nsw i64 %indvars.iv1, 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.iv1, 1
%exitcond = icmp ne i64 %indvars.iv.next, 1024
br i1 %exitcond, label %for.body, label %for.end
for.end: ; preds = %for.inc
ret void
}
This is the form of code we should expect in heuristics.
I can think of three possibilities on how to fix the test cases:
1. Detect whether loop rotation has taken place (e.g.: all outgoing edges of the header point to BBs inside the loop)
2. Modify the heuristic such that it applies only if it is the only way through the loop without leaving it (The postdominance frontier solution suggested by Johannes).
3. Run `-loop-rotate` over the failing test-cases.
Michael
Repository:
rPLO Polly
https://reviews.llvm.org/D41692
More information about the llvm-commits
mailing list