@@ -81,17 +81,17 @@
# .MEM_22 = VDEF <.MEM_35>
A[i_31][j_32] = 0;
# .MEM_7 = VDEF <.MEM_22>
- Commutative_Associative_Reduction.5[0] = 0;
+ A[i_31][j_32] = 0;
}
bb_7 (preds = {bb_5 }, succs = {bb_17 })
{
<bb 7>:
# VUSE <.MEM_38>
- D.2738_23 = Commutative_Associative_Reduction.5[0];
- A_I_I_lsm.4_44 = D.2738_23;
+ D.2737_23 = A[i_31][j_32];
+ A_I_I_lsm.4_44 = D.2737_23;
# .MEM_54 = VDEF <.MEM_38>
- Cross_BB_scalar_dependence.6[0] = A_I_I_lsm.4_44;
+ Cross_BB_scalar_dependence.5[0] = A_I_I_lsm.4_44;
}
bb_17 (preds = {bb_7 }, succs = {bb_14 })
@@ -103,7 +103,7 @@
{
<bb 14>:
# VUSE <.MEM_54>
- A_I_I_lsm.4_52 = Cross_BB_scalar_dependence.6[0];
+ A_I_I_lsm.4_52 = Cross_BB_scalar_dependence.5[0];
# .MEM_43 = VDEF <.MEM_54>
A[i_31][j_32] = A_I_I_lsm.4_52;
j_13 = j_32 + 1;
@@ -121,7 +121,7 @@
# k_33 = PHI <k_12(6), 0(4)>
# .MEM_34 = PHI <.MEM_38(6), .MEM_7(4)>
# VUSE <.MEM_34>
- prephitmp.3_37 = Commutative_Associative_Reduction.5[0];
+ prephitmp.3_37 = A[i_31][j_32];
# VUSE <.MEM_34>
D.2722_8 = B[i_31][k_33];
# VUSE <.MEM_34>
@@ -129,7 +129,7 @@
D.2724_10 = D.2722_8 * D.2723_9;
D.2725_11 = D.2724_10 + prephitmp.3_37;
# .MEM_38 = VDEF <.MEM_34>
- Commutative_Associative_Reduction.5[0] = D.2725_11;
+ A[i_31][j_32] = D.2725_11;
k_12 = k_33 + 1;
if (k_12 != 200)
goto <bb 6>;
We now use the data reference A instead of creating the one-element
array Commutative_Associative_Reduction, and now we can interchange
the two loops as we know the access function for the data reference.
The problem occurs in 3 SPEC benchmarks reduced to:
SUBROUTINE CAMB(RX2,RTX,NUM)
DIMENSION RX2(NUM,NUM),RTX(NUM,NUM)
DO I=1,NUM
DO J=1,I
DO M=1,NUM
RX2(I,J)=RX2(I,J)+RTX(M,I)
END DO
END DO
END DO
IF (RX2(I,1).LE.EIGCT2) THEN
RTX(I,1)=4.0D+00
END IF
END
For some reason (unimportant for now), the scop is bounded to the
innermost loop M. RX2(I,J) is first scalar optimized such that the
reduction happens into a scalar:
DO J=1,I
t = RX2(I,J)
DO M=1,NUM
t=t+RTX(M,I)
END DO
RX2(I,J)=t
END DO
and then when we rewrite the commutative associative reductions out of
SSA, we reintroduce the data reference RX2(I,J) in the loop nest. The
access functions for RX2(I,J) are parameters of the scop, as they do
not variate in the scop (bounded to the innermost loop here). As we
rewrite out-of-SSA quite late in the polyhedral translation, after the
parameters of the scop have already been determined, we fail in this
specific case because we introduce new parameters that are not
registered yet in the representation. The first part of the patch to fix
this is to move the rewrite of reductions before parameters analysis:
@@ -3159,6 +3159,9 @@ build_poly_scop (scop_p scop)
if (!scop_ivs_can_be_represented (scop))
return;
+ if (flag_associative_math)
+ rewrite_commutative_reductions_out_of_ssa (scop);
+
build_sese_loop_nests (region);
build_sese_conditions (region);
find_scop_parameters (scop);
@@ -3175,8 +3178,6 @@ build_poly_scop (scop_p scop)
representation to the polyhedral representation to avoid scev
analysis failures. That means that these functions will insert
new data references that they create in the right place. */
- if (flag_associative_math)
- rewrite_commutative_reductions_out_of_ssa (scop);
rewrite_reductions_out_of_ssa (scop);
rewrite_cross_bb_scalar_deps_out_of_ssa (scop);