[all-commits] [llvm/llvm-project] 3dbb05: [flang] Generate valid IR on GOTO DO body (#66084)

Leandro Lupori via All-commits all-commits at lists.llvm.org
Thu Sep 21 06:59:49 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3dbb055f54e705d125e1fd30db463e7aff8bbeff
      https://github.com/llvm/llvm-project/commit/3dbb055f54e705d125e1fd30db463e7aff8bbeff
  Author: Leandro Lupori <leandro.lupori at linaro.org>
  Date:   2023-09-21 (Thu, 21 Sep 2023)

  Changed paths:
    M flang/lib/Lower/Bridge.cpp
    A flang/test/Lower/HLFIR/goto-do-body.f90
    M flang/test/Lower/do_loop.f90
    M flang/test/Lower/do_loop_unstructured.f90
    A flang/test/Lower/goto-do-body.f90
    M flang/test/Lower/loops2.f90
    M flang/test/Lower/mixed_loops.f90

  Log Message:
  -----------
  [flang] Generate valid IR on GOTO DO body (#66084)

Flang was generating invalid IR when there was a GOTO to the body
of a DO loop. This happened because the value of step, computed at
the beginning of the loop, was being reused at the end of the loop,
that, for unstructured loops, is in another basic block. Because of
this, a GOTO could skip the beginning of the loop, that defined
step, and yet try to use it at the end of the loop, which is
invalid.

Instead of reusing the step value, it can be recomputed if it is a
constant, or stored and loaded to/from a temporary variable, for
non-constant step expressions.

Note that, while this change prevents the generation of invalid IR
on the presence of jumps to DO loop bodies, what happens if the
program reaches the end of a DO loop without ever passing through
its beginning is undefined behavior, as some control variables,
such as trip, will be uninitialized. It doesn't seem worth the
effort and overhead to ensure this legacy extension will behave
correctly in this case. This is consistent with at least gfortran,
that doesn't behave correctly if step is not equal to one.

Fixes: https://github.com/llvm/llvm-project/issues/65036




More information about the All-commits mailing list