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

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Thu Sep 25 08:06:34 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());
----------------
vzakhari wrote:

I thought about that, and was not sure if limiting `fir.do_loop` that way is reasonable. I suppose it should be okay to use the final value of the counter, in general. For example, [HL]FIR optimization passes may want to generate such a `fir.do_loop` without introducing another loop-carried value. Of course, the final value may be computed as a function of the lower and upper bound of the loop, so we can indeed limit the operation to never return the final counter.

I have no strong opinion about this.

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


More information about the flang-commits mailing list