[flang] Make use of do variable more consistent.

Instead of using the IV block argument of the do-loop we will use
the do-variable value loaded from its location. This usage is consistent
with other uses of the do-variable inside the loop.

Differential Revision: https://reviews.llvm.org/D133140
This commit is contained in:
Slava Zakharin 2022-09-01 12:33:39 -07:00
parent f6d6e33abc
commit 8fbc7e0869
7 changed files with 32 additions and 23 deletions

View File

@ -119,11 +119,6 @@ struct IncrementLoopInfo {
// Data members for structured loops.
fir::DoLoopOp doLoop = nullptr;
// Do loop block argument holding the current value
// of the do-variable. It has the same data type as the original
// do-variable. It is non-null after genFIRIncrementLoopBegin()
// iff doVarIsALoopArg() returns true.
mlir::Value doVarValue = nullptr;
// Data members for unstructured loops.
bool hasRealControl = false;
@ -1275,7 +1270,6 @@ private:
// The loop variable value is the region's argument rather
// than the DoLoop's index value.
value = info.doLoop.getRegionIterArgs()[0];
info.doVarValue = value;
}
builder->create<fir::StoreOp>(loc, value, info.loopVariable);
if (info.maskExpr) {
@ -1377,8 +1371,10 @@ private:
// type, so we need to cast it, first.
mlir::Value stepCast = builder->createConvert(
loc, info.getLoopVariableType(), info.doLoop.getStep());
mlir::Value doVarValue =
builder->create<fir::LoadOp>(loc, info.loopVariable);
results.push_back(builder->create<mlir::arith::AddIOp>(
loc, info.doVarValue, stepCast));
loc, doVarValue, stepCast));
}
builder->create<fir::ResultOp>(loc, results);
}

View File

@ -31,7 +31,8 @@
! CHECK: fir.store %[[VAL_16]] to %[[PRIV_X]] : !fir.ref<i32>
! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_13]], %[[VAL_11]] : index
! CHECK: %[[STEPCAST:.*]] = fir.convert %[[VAL_11]] : (index) -> i32
! CHECK: %[[IVINC:.*]] = arith.addi %[[IV]], %[[STEPCAST]]
! CHECK: %[[IVLOAD:.*]] = fir.load %[[PRIV_J]] : !fir.ref<i32>
! CHECK: %[[IVINC:.*]] = arith.addi %[[IVLOAD]], %[[STEPCAST]]
! CHECK: fir.result %[[VAL_17]], %[[IVINC]] : index, i32
! CHECK: }
! CHECK: fir.store %[[VAL_12]]#1 to %[[PRIV_J]] : !fir.ref<i32>

View File

@ -112,7 +112,8 @@ end program wsloop_variable
!CHECK: fir.store %[[VAL_25]] to %[[VAL_6]] : !fir.ref<f32>
!CHECK: %[[VAL_26:.*]] = arith.addi %[[VAL_20]], %[[VAL_18]] : index
!CHECK: %[[STEPCAST:.*]] = fir.convert %[[VAL_18]] : (index) -> i64
!CHECK: %[[IVINC:.*]] = arith.addi %[[IV]], %[[STEPCAST]]
!CHECK: %[[IVLOAD:.*]] = fir.load %[[VAL_5]] : !fir.ref<i64>
!CHECK: %[[IVINC:.*]] = arith.addi %[[IVLOAD]], %[[STEPCAST]]
!CHECK: fir.result %[[VAL_26]], %[[IVINC]] : index, i64
!CHECK: }
!CHECK: fir.store %[[VAL_19]]#1 to %[[VAL_5]] : !fir.ref<i64>

View File

@ -25,14 +25,14 @@
! CHECK-DAG: %[[VAL_30:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFEj"}
! CHECK-DAG: %[[VAL_31:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFEk"}
! CHECK: fir.store %[[VAL_24]] to %[[VAL_31]] : !fir.ref<i32>
! CHECK: %[[LB:.*]] = fir.convert %[[VAL_5]] : (index) -> i32
! CHECK: br ^bb1(%[[LB]], %[[VAL_0]] : i32, index)
! CHECK: %[[STEP:.*]] = fir.convert %[[VAL_5]] : (index) -> i32
! CHECK: br ^bb1(%[[STEP]], %[[VAL_0]] : i32, index)
! CHECK: ^bb1(%[[VAL_32:.*]]: i32, %[[VAL_33:.*]]: index):
! CHECK: %[[VAL_34:.*]] = arith.cmpi sgt, %[[VAL_33]], %[[VAL_6]] : index
! CHECK: cond_br %[[VAL_34]], ^bb2, ^bb6
! CHECK: ^bb2:
! CHECK: fir.store %[[VAL_32]] to %[[VAL_30]] : !fir.ref<i32>
! CHECK: br ^bb3(%[[LB]], %[[VAL_0]] : i32, index)
! CHECK: br ^bb3(%[[STEP]], %[[VAL_0]] : i32, index)
! CHECK: ^bb3(%[[VAL_36:.*]]: i32, %[[VAL_37:.*]]: index):
! CHECK: %[[VAL_38:.*]] = arith.cmpi sgt, %[[VAL_37]], %[[VAL_6]] : index
! CHECK: cond_br %[[VAL_38]], ^bb4, ^bb5
@ -52,7 +52,8 @@
! CHECK: %[[VAL_50:.*]] = arith.subi %[[VAL_49]], %[[VAL_20]] : i64
! CHECK: %[[VAL_51:.*]] = fir.coordinate_of %[[VAL_25]], %[[VAL_47]], %[[VAL_50]] : (!fir.ref<!fir.array<10x10xf32>>, i64, i64) -> !fir.ref<f32>
! CHECK: fir.store %[[VAL_44]] to %[[VAL_51]] : !fir.ref<f32>
! CHECK: %[[VAL_52:.*]] = arith.addi %[[VAL_36]], %[[LB]] : i32
! CHECK: %[[LOADI:.*]] = fir.load %[[VAL_28]] : !fir.ref<i32>
! CHECK: %[[VAL_52:.*]] = arith.addi %[[LOADI]], %[[STEP]] : i32
! CHECK: %[[VAL_53:.*]] = arith.subi %[[VAL_37]], %[[VAL_5]] : index
! CHECK: br ^bb3(%[[VAL_52]], %[[VAL_53]] : i32, index)
! CHECK: ^bb5:
@ -65,7 +66,8 @@
! CHECK: %[[VAL_60:.*]] = arith.subi %[[VAL_59]], %[[VAL_20]] : i64
! CHECK: %[[VAL_61:.*]] = fir.coordinate_of %[[VAL_27]], %[[VAL_60]] : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
! CHECK: fir.store %[[VAL_57]] to %[[VAL_61]] : !fir.ref<f32>
! CHECK: %[[VAL_62:.*]] = arith.addi %[[VAL_32]], %[[LB]] : i32
! CHECK: %[[LOADJ:.*]] = fir.load %[[VAL_30]] : !fir.ref<i32>
! CHECK: %[[VAL_62:.*]] = arith.addi %[[LOADJ]], %[[STEP]] : i32
! CHECK: %[[VAL_63:.*]] = arith.subi %[[VAL_33]], %[[VAL_5]] : index
! CHECK: br ^bb1(%[[VAL_62]], %[[VAL_63]] : i32, index)
! CHECK: ^bb6:

View File

@ -24,7 +24,8 @@ subroutine simple_loop
! CHECK: fir.store %[[IV]] to %[[I_REF]] : !fir.ref<i32>
! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[C1]] : index
! CHECK: %[[STEPCAST:.*]] = fir.convert %[[C1]] : (index) -> i32
! CHECK: %[[IVINC:.*]] = arith.addi %[[IV]], %[[STEPCAST]] : i32
! CHECK: %[[IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
! CHECK: %[[IVINC:.*]] = arith.addi %[[IVLOAD]], %[[STEPCAST]] : i32
! CHECK: fir.result %[[LI_NEXT]], %[[IVINC]] : index, i32
! CHECK: }
end do
@ -82,14 +83,16 @@ subroutine nested_loop
asum = asum + arr(i,j)
! CHECK: %[[LJ_NEXT:.*]] = arith.addi %[[LJ]], %[[ST_J]] : index
! CHECK: %[[J_STEPCAST:.*]] = fir.convert %[[ST_J]] : (index) -> i32
! CHECK: %[[J_IVINC:.*]] = arith.addi %[[J_IV]], %[[J_STEPCAST]] : i32
! CHECK: %[[J_IVLOAD:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
! CHECK: %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST]] : i32
! CHECK: fir.result %[[LJ_NEXT]], %[[J_IVINC]] : index, i32
! CHECK: }
end do
! CHECK: fir.store %[[J_RES]]#1 to %[[J_REF]] : !fir.ref<i32>
! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_I]] : index
! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[ST_I]] : (index) -> i32
! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IV]], %[[I_STEPCAST]] : i32
! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i32
! CHECK: fir.result %[[LI_NEXT]], %[[I_IVINC]] : index, i32
! CHECK: }
end do
@ -116,7 +119,8 @@ subroutine down_counting_loop()
! CHECK: fir.store %[[I_IV]] to %[[I_REF]] : !fir.ref<i32>
! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[CMINUS1_STEP_CVT]] : index
! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[CMINUS1_STEP_CVT]] : (index) -> i32
! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IV]], %[[I_STEPCAST]] : i32
! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i32
! CHECK: fir.result %[[LI_NEXT]], %[[I_IVINC]] : index, i32
! CHECK: }
end do
@ -142,7 +146,8 @@ subroutine loop_with_variable_step(s,e,st)
! CHECK: fir.store %[[I_IV]] to %[[I_REF]] : !fir.ref<i32>
! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT]] : index
! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[ST_CVT]] : (index) -> i32
! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IV]], %[[I_STEPCAST]] : i32
! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i32
! CHECK: fir.result %[[LI_NEXT]], %[[I_IVINC]] : index, i32
! CHECK: }
end do
@ -193,7 +198,8 @@ subroutine loop_with_pointer_variables(s,e,st)
! CHECK: fir.store %[[I_IV]] to %[[I_PTR]] : !fir.ptr<i32>
! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT]] : index
! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[ST_CVT]] : (index) -> i32
! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IV]], %[[I_STEPCAST]] : i32
! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_PTR]] : !fir.ptr<i32>
! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i32
! CHECK: fir.result %[[LI_NEXT]], %[[I_IVINC]] : index, i32
end do
! CHECK: }
@ -222,7 +228,8 @@ subroutine loop_with_non_default_integer(s,e,st)
! CHECK: fir.store %[[I_IV]] to %[[I_REF]] : !fir.ref<i64>
! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT]] : index
! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[ST_CVT]] : (index) -> i64
! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IV]], %[[I_STEPCAST]] : i64
! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i64>
! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i64
! CHECK: fir.result %[[LI_NEXT]], %[[I_IVINC]] : index, i64
end do
! CHECK: }

View File

@ -97,7 +97,8 @@ end subroutine
! CHECK: fir.store %[[J_IV]] to %[[J_REF]] : !fir.ref<i32>
! CHECK: %[[J_NEXT:.*]] = arith.addi %[[J]], %[[C1_1]] : index
! CHECK: %[[J_STEPCAST:.*]] = fir.convert %[[C1_1]] : (index) -> i32
! CHECK: %[[J_IVINC:.*]] = arith.addi %[[J_IV]], %[[J_STEPCAST]] : i32
! CHECK: %[[J_IVLOAD:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
! CHECK: %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST]] : i32
! CHECK: fir.result %[[J_NEXT]], %[[J_IVINC]] : index, i32
! CHECK: }
! CHECK: fir.store %[[J_FINAL]]#1 to %[[J_REF]] : !fir.ref<i32>

View File

@ -101,7 +101,8 @@ subroutine do_inside_while_loop
! CHECK: fir.store %[[JINC]] to %[[J_REF]] : !fir.ref<i32>
! CHECK: %[[IINC:.*]] = arith.addi %[[IDX]], %[[C1]] : index
! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[C1]] : (index) -> i32
! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IV]], %[[I_STEPCAST]] : i32
! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i32
! CHECK: fir.result %[[IINC]], %[[I_IVINC]] : index, i32
do i=8,13
j=j*2