1; RUN: opt %loadPolly -polly-stmt-granularity=bb -polly-optree -analyze < %s | FileCheck %s -match-full-lines
2;
3; Rematerialize a load even in case two writes of identical values are in
4; one scop statement.
5;
6define void @func(i32 %n, double* noalias nonnull %A, double* noalias nonnull %B) {
7entry:
8  br label %for
9
10for:
11  %j = phi i32 [0, %entry], [%j.inc, %inc]
12  %j.cmp = icmp slt i32 %j, %n
13  br i1 %j.cmp, label %bodyA, label %exit
14
15    bodyA:
16      %B_idx = getelementptr inbounds double, double* %B, i32 %j
17      %val = load double, double* %B_idx
18      br label %bodyB
19
20    bodyB:
21      %A_idx = getelementptr inbounds double, double* %A, i32 %j
22      store double %val, double* %A_idx
23      store double %val, double* %A_idx
24      br label %inc
25
26inc:
27  %j.inc = add nuw nsw i32 %j, 1
28  br label %for
29
30exit:
31  br label %return
32
33return:
34  ret void
35}
36
37
38; CHECK: Statistics {
39; CHECK:     Known loads forwarded: 1
40; CHECK:     Operand trees forwarded: 1
41; CHECK:     Statements with forwarded operand trees: 1
42; CHECK: }
43
44; CHECK:      Stmt_bodyB
45; CHECK-NEXT:         ReadAccess :=       [Reduction Type: NONE] [Scalar: 0]
46; CHECK-NEXT:             ;
47; CHECK-NEXT:        new: [n] -> { Stmt_bodyB[i0] -> MemRef_B[i0] };
48; CHECK-NEXT:         MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 0]
49; CHECK-NEXT:             [n] -> { Stmt_bodyB[i0] -> MemRef_A[i0] };
50; CHECK-NEXT:         MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 0]
51; CHECK-NEXT:             [n] -> { Stmt_bodyB[i0] -> MemRef_A[i0] };
52; CHECK-NEXT:         Instructions {
53; CHECK-NEXT:               %val = load double, double* %B_idx, align 8
54; CHECK-NEXT:               store double %val, double* %A_idx, align 8
55; CHECK-NEXT:               store double %val, double* %A_idx, align 8
56; CHECK-NEXT:         }
57