Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hoist do concurrent nest bounds/steps outside the nest (#114020) #198

Merged
merged 1 commit into from
Oct 31, 2024

Commits on Oct 31, 2024

  1. Hoist do concurrent nest bounds/steps outside the nest (llvm#114020)

    If you have the following multi-range `do concurrent` loop:
    
    ```fortran
      do concurrent(i=1:n, j=1:bar(n*m, n/m))
        a(i) = n
      end do
    ```
    
    Currently, flang generates the following IR:
    
    ```mlir
        fir.do_loop %arg1 = %42 to %44 step %c1 unordered {
          ...
          %53:3 = hlfir.associate %49 {adapt.valuebyref} : (i32) -> (!fir.ref<i32>, !fir.ref<i32>, i1)
          %54:3 = hlfir.associate %52 {adapt.valuebyref} : (i32) -> (!fir.ref<i32>, !fir.ref<i32>, i1)
          %55 = fir.call @_QFPbar(%53#1, %54#1) fastmath<contract> : (!fir.ref<i32>, !fir.ref<i32>) -> i32
          hlfir.end_associate %53#1, %53#2 : !fir.ref<i32>, i1
          hlfir.end_associate %54#1, %54#2 : !fir.ref<i32>, i1
          %56 = fir.convert %55 : (i32) -> index
          ...
          fir.do_loop %arg2 = %46 to %56 step %c1_4 unordered {
            ...
          }
        }
    ```
    
    However, if `bar` is impure, then we have a direct violation of the
    standard:
    
    ```
    C1143 A reference to an impure procedure shall not appear within a DO CONCURRENT construct.
    ```
    
    Moreover, the standard describes the execution of `do concurrent`
    construct in multiple stages:
    
    ```
    11.1.7.4 Execution of a DO construct
    ...
    11.1.7.4.2 DO CONCURRENT loop control
    The concurrent-limit and concurrent-step expressions in the concurrent-control-list are evaluated. ...
    
    11.1.7.4.3 The execution cycle
    ...
    The block of a DO CONCURRENT construct is executed for every active combination of the index-name values.
    Each execution of the block is an iteration. The executions may occur in any order.
    ```
    
    From the above 2 points, it seems to me that execution is divided in
    multiple consecutive stages: 11.1.7.4.2 is the stage where we evaluate
    all control expressions including the step and then 11.1.7.4.3 is the
    stage to execute the block of the concurrent loop itself using the
    combination of possible iteration values.
    ergawy committed Oct 31, 2024
    Configuration menu
    Copy the full SHA
    dd4629e View commit details
    Browse the repository at this point in the history