[flang-commits] [flang] [flang] Clean-up for fir.do_loop generation in lowering. (PR #160630)

via flang-commits flang-commits at lists.llvm.org
Thu Sep 25 00:56:35 PDT 2025


================
@@ -977,9 +977,9 @@ static void genIoLoop(Fortran::lower::AbstractConverter &converter,
     fir::StoreOp::create(builder, loc, lcv, loopVar);
     genItemList(ioImpliedDo);
     builder.setInsertionPointToEnd(doLoopOp.getBody());
-    mlir::Value result = mlir::arith::AddIOp::create(
-        builder, loc, doLoopOp.getInductionVar(), doLoopOp.getStep(), iofAttr);
-    fir::ResultOp::create(builder, loc, result);
+    // fir.do_loop's induction variable's increment is implied,
+    // so we do not need to increment it explicitly.
+    fir::ResultOp::create(builder, loc, doLoopOp.getInductionVar());
----------------
jeanPerier wrote:

Do you think it would be possible to align the IO case with the normal do Loop case and have a loop argument/result with the user type + explicit increment and `finalCountValue=false`?

It seems to be the only remaining case where `finalCountValue=true`, and I wonder if it would not be best to just remove this attribute if it is not really needed to have a more uniform and simpler IR (no need to do the removal in this patch that is already touching many files).

https://github.com/llvm/llvm-project/pull/160630


More information about the flang-commits mailing list