llvm-project/polly/test/DependenceInfo/different_schedule_dimensio...

62 lines
2.2 KiB
LLVM
Raw Normal View History

; RUN: opt -S %loadPolly -polly-dependences \
; RUN: -analyze < %s | FileCheck %s
; RUN: opt -S %loadPolly -polly-function-dependences \
; RUN: -analyze < %s | FileCheck %s -check-prefix=FUNC
; CHECK: RAW dependences:
; CHECK: { Stmt_bb9[0] -> Stmt_bb10[0] }
; CHECK: WAR dependences:
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics = Change of WAR, WAW generation: = - `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form `sink <- may source <- must source` as a *may* dependence. - we used to call: ```lang=cpp, name=old-flow-call.cpp Flow = buildFlow(MustWrite, MustWrite, Read, Schedule); WAW = isl_union_flow_get_must_dependence(Flow); WAR = isl_union_flow_get_may_dependence(Flow); ``` - This caused some WAW dependences to be treated as WAR dependences. - Incorrect semantics. - Now, we call WAR and WAW correctly. == Correct WAW: == ```lang=cpp, name=new-waw-call.cpp Flow = buildFlow(Write, MustWrite, MayWrite, Schedule); WAW = isl_union_flow_get_may_dependence(Flow); isl_union_flow_free(Flow); ``` == Correct WAR: == ```lang=cpp, name=new-war-call.cpp Flow = buildFlow(Write, Read, MustaWrite, Schedule); WAR = isl_union_flow_get_must_dependence(Flow); isl_union_flow_free(Flow); ``` - We want the "shortest" WAR possible (exact dependences). - We mark all the *must-writes* as may-source, reads as must-souce. - Then, we ask for *must* dependence. - This removes all the reads that flow through a *must-write* before reaching a sink. - Note that we only block ealier writes with *must-writes*. This is intuitively correct, as we do not want may-writes to block must-writes. - Leaves us with direct (R -> W). - This affects reduction generation since RED is built using WAW and WAR. = New StrictWAW for Reductions: = - We used to call: ```lang=cpp,name=old-waw-war-call.cpp Flow = buildFlow(MustWrite, MustWrite, Read, Schedule); WAW = isl_union_flow_get_must_dependence(Flow); WAR = isl_union_flow_get_may_dependence(Flow); ``` - This *is* the right model of WAW we need for reductions, just not in general. - Reductions need to track only *strict* WAW, without any interfering reductions. = Explanation: Why the new WAR dependences in tests are correct: = - We no longer set WAR = WAR - WAW - Hence, we will have WAR dependences that were originally removed. - These may look incorrect, but in fact make sense. == Code: == ```lang=llvm, name=new-war-dependence.ll ; void manyreductions(long *A) { ; for (long i = 0; i < 1024; i++) ; for (long j = 0; j < 1024; j++) ; S0: *A += 42; ; ; for (long i = 0; i < 1024; i++) ; for (long j = 0; j < 1024; j++) ; S1: *A += 42; ; ``` === WAR dependence: === { S0[1023, 1023] -> S1[0, 0] } - Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences: ```lang=cpp, name=dependence-incorrect, counterexample S0[1023, 1023]: *-- tmp = *A (load0)--* WAR 2 add = tmp + 42 | *-> *A = add (store0) | WAR 1 S1[0, 0]: | tmp = *A (load1) | add = tmp + 42 | A = add (store1)<-* ``` - One may assume that WAR2 *hides* WAR1 (since store0 happens before store1). However, within a statement, Polly has no idea about the ordering of loads and stores. - Hence, according to Polly, the code may have looked like this: ```lang=cpp, name=dependence-correct S0[1023, 1023]: A = add (store0) tmp = A (load0) ---* add = A + 42 | WAR 1 S1[0, 0]: | tmp = A (load1) | add = A + 42 | A = add (store1) <-* ``` - So, Polly generates (correct) WAR dependences. It does not make sense to remove these dependences, since they are correct with respect to Polly's model. Reviewers: grosser, Meinersbur tags: #polly Differential revision: https://reviews.llvm.org/D31386 llvm-svn: 299429
2017-04-04 21:08:23 +08:00
; CHECK: { Stmt_bb3[0] -> Stmt_bb10[0] }
; CHECK: WAW dependences:
; CHECK: { Stmt_bb3[0] -> Stmt_bb10[0] }
; CHECK: Reduction dependences:
; CHECK: { }
; FUNC: RAW dependences:
; FUNC-NEXT: { Stmt_bb9[0] -> Stmt_bb10[0]; [Stmt_bb9[0] -> Stmt_bb9_Write0[]] -> [Stmt_bb10[0] -> Stmt_bb10_Read0[]] }
; FUNC-NEXT: WAR dependences:
; FUNC-NEXT: { }
; FUNC-NEXT: WAW dependences:
; FUNC-NEXT: { Stmt_bb3[0] -> Stmt_bb10[0]; [Stmt_bb3[0] -> Stmt_bb3_Write1[]] -> [Stmt_bb10[0] -> Stmt_bb10_Write1[]] }
; FUNC-NEXT: Reduction dependences:
; FUNC-NEXT: { }
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
define void @hoge(i32 %arg, [1024 x double]* %arg1) {
bb:
br label %bb2
bb2: ; preds = %bb
br label %bb3
bb3: ; preds = %bb10, %bb2
%tmp = phi i64 [ 0, %bb10 ], [ 0, %bb2 ]
%tmp4 = icmp sgt i32 %arg, 0
%tmp5 = getelementptr inbounds [1024 x double], [1024 x double]* %arg1, i64 0, i64 0
%tmp6 = load double, double* %tmp5, align 8
%tmp7 = fadd double undef, %tmp6
store double %tmp7, double* %tmp5, align 8
br i1 false, label %bb8, label %bb9
bb8: ; preds = %bb3
br label %bb10
bb9: ; preds = %bb3
br label %bb10
bb10: ; preds = %bb9, %bb8
%tmp11 = phi double [ undef, %bb8 ], [ undef, %bb9 ]
%tmp12 = getelementptr inbounds [1024 x double], [1024 x double]* %arg1, i64 %tmp, i64 0
store double %tmp11, double* %tmp12, align 8
%tmp13 = add nuw nsw i64 0, 1
%tmp14 = trunc i64 %tmp13 to i32
br i1 false, label %bb3, label %bb15
bb15: ; preds = %bb10
br label %bb16
bb16: ; preds = %bb15
ret void
}