[flang-commits] [flang] [flang][HLFIR] Relax InlineElementals to support more than two users (PR #186916)

via flang-commits flang-commits at lists.llvm.org
Tue Mar 31 18:04:37 PDT 2026


anoopkg6 wrote:

This patch includes memory-effect and dataflow analysis. It uses worklist-based dataflow traversal to trace hlfir.elemental results through intermediate users (hfir.declare and fir.convert) to identify application site. 'isSafeToInline' then performs a recursive, region-aware dominance walk to ensure no conflicting writes exist between the producer and consumer.
By using a worklist to trace results enables more cases to be inlined.  Cases involving complex control-flow boundaries(cross-block/loop-exits) that the worklist does not yet traverse remain unaffected (worklist currently results in applyCount=0, which causes the pass to safely skip inlining without regressing existing behavior).

Adding original Fortran loop from exchange2 that corresponds to IR I had previously included in this pr. IR is for 
pos1 = minloc(block(row, :, :), mask=block(row, :, :) == val)
`subroutine specific
!
integer :: row, col, val, boxr, boxc, pos1(2), pos2(2), row1, col1, rmin, rmax , cmin, cmax
!
! fix single value in row all in same block
do row = 1, rank2
v1: do val = 1, rank2
      if(any(part(row, :) == val)) cycle
       if(count(block(row, :, val) == val) == 0) cycle
       pos1 = minloc(block(row, :, :), mask=block(row, :, :) == val)
       pos2 = minloc(block(row, rank2:1:-1, :), mask=block(row, rank2:1:-1, :) == val)
       pos2(1) = rank2 + 1 - pos2(1)
       if(pos1(1) == pos2(1)) cycle
       if( (pos1(1)-1)/rank == (pos2(1)-1)/rank) then
          col = pos1(1)
           do row1 = ((row-1)/rank)*rank+1, ((row-1)/rank)*rank+rank
              if(row1 == row) cycle
               clear_out = clear_out +                                                         &
               count (block(row1, ((col-1)/rank)*rank+1:((col-1)/rank)*rank+rank, val) == val)
              where (block(row1, ((col-1)/rank)*rank+1:((col-1)/rank)*rank+rank, val) == val)   &
                   block(row1, ((col-1)/rank)*rank+1:((col-1)/rank)*rank+rank, val) = 0
           end do
      end if
   end do v1
end do
`

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


More information about the flang-commits mailing list