[flang-commits] [flang] 8fbc7e0 - [flang] Make use of do variable more consistent.
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Thu Sep 1 15:47:05 PDT 2022
Author: Slava Zakharin
Date: 2022-09-01T15:46:19-07:00
New Revision: 8fbc7e0869293b9b61b7bce3edfa4de05b1c549d
URL: https://github.com/llvm/llvm-project/commit/8fbc7e0869293b9b61b7bce3edfa4de05b1c549d
DIFF: https://github.com/llvm/llvm-project/commit/8fbc7e0869293b9b61b7bce3edfa4de05b1c549d.diff
LOG: [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
Added:
Modified:
flang/lib/Lower/Bridge.cpp
flang/test/Lower/OpenMP/omp-parallel-private-clause-fixes.f90
flang/test/Lower/OpenMP/omp-wsloop-variable.f90
flang/test/Lower/array-expression-slice-1.f90
flang/test/Lower/do_loop.f90
flang/test/Lower/infinite_loop.f90
flang/test/Lower/mixed_loops.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index df4634dca737d..7ec4a219ff605 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -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 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// 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 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// 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);
}
diff --git a/flang/test/Lower/OpenMP/omp-parallel-private-clause-fixes.f90 b/flang/test/Lower/OpenMP/omp-parallel-private-clause-fixes.f90
index 0d91c06a33921..0b8bb7ff41c8a 100644
--- a/flang/test/Lower/OpenMP/omp-parallel-private-clause-fixes.f90
+++ b/flang/test/Lower/OpenMP/omp-parallel-private-clause-fixes.f90
@@ -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>
diff --git a/flang/test/Lower/OpenMP/omp-wsloop-variable.f90 b/flang/test/Lower/OpenMP/omp-wsloop-variable.f90
index 10a7dded9209f..bc92a87fb570b 100644
--- a/flang/test/Lower/OpenMP/omp-wsloop-variable.f90
+++ b/flang/test/Lower/OpenMP/omp-wsloop-variable.f90
@@ -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>
diff --git a/flang/test/Lower/array-expression-slice-1.f90 b/flang/test/Lower/array-expression-slice-1.f90
index 9ce28f033cf92..b7eb6a73e6984 100644
--- a/flang/test/Lower/array-expression-slice-1.f90
+++ b/flang/test/Lower/array-expression-slice-1.f90
@@ -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:
diff --git a/flang/test/Lower/do_loop.f90 b/flang/test/Lower/do_loop.f90
index de21f0b174148..2439e28c19879 100644
--- a/flang/test/Lower/do_loop.f90
+++ b/flang/test/Lower/do_loop.f90
@@ -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: }
diff --git a/flang/test/Lower/infinite_loop.f90 b/flang/test/Lower/infinite_loop.f90
index e56a57979965b..7bca44f17413c 100644
--- a/flang/test/Lower/infinite_loop.f90
+++ b/flang/test/Lower/infinite_loop.f90
@@ -97,7 +97,8 @@ subroutine structured_loop_in_infinite(i)
! 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>
diff --git a/flang/test/Lower/mixed_loops.f90 b/flang/test/Lower/mixed_loops.f90
index e1a1c8b8f458f..e5d0bc8266969 100644
--- a/flang/test/Lower/mixed_loops.f90
+++ b/flang/test/Lower/mixed_loops.f90
@@ -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
More information about the flang-commits
mailing list