[all-commits] [llvm/llvm-project] af7edf: [flang] Keep original data type for do-variable va...

Slava Zakharin via All-commits all-commits at lists.llvm.org
Tue Aug 23 15:57:00 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: af7edf1557d87026bb4dd4783f60e766538e923c
      https://github.com/llvm/llvm-project/commit/af7edf1557d87026bb4dd4783f60e766538e923c
  Author: Slava Zakharin <szakharin at nvidia.com>
  Date:   2022-08-23 (Tue, 23 Aug 2022)

  Changed paths:
    M flang/lib/Lower/Bridge.cpp
    M flang/test/Lower/OpenMP/omp-parallel-private-clause-fixes.f90
    M flang/test/Lower/OpenMP/omp-wsloop-variable.f90
    M flang/test/Lower/array-expression-slice-1.f90
    M flang/test/Lower/do_loop.f90
    M flang/test/Lower/do_loop_unstructured.f90
    M flang/test/Lower/infinite_loop.f90
    M flang/test/Lower/loops.f90
    M flang/test/Lower/loops2.f90
    M flang/test/Lower/mixed_loops.f90

  Log Message:
  -----------
  [flang] Keep original data type for do-variable value.

Keep the original data type of integer do-variables
for structured loops. When do-variable's data type
is an integer type shorter than IndexType, processing
the do-variable separately from the DoLoop's iteration index
allows getting rid of type casts, which can make backend
optimizations easier.

For example,
```
  do i = 2, n-1
    do j = 2, n-1
      ... = a(j-1, i)
    end do
  end do
```

If value of 'j' is computed by casting the DoLoop's iteration
index to 'i32', then Flang will produce the following LLVM IR:
```
  %1 = trunc i64 %iter_index to i32
  %2 = sub i32 %1, 1
  %3 = sext i32 %2 to i64
```

LLVM's InstCombine may try to get rid of the sign extension,
and may transform this into:
```
  %1 = shl i64 %iter_index, 32
  %2 = add i64 %1, -4294967296
  %3 = ashr exact i64 %2, 32
```

The extra computations for the element address applied on top
of this awkward pattern confuse LLVM vectorizer so that
it does not recognize the unit-strided access of 'a'.

Measured performance improvements on `SPEC CPU2000 at IceLake`:
```
168.wupwise:    11.96%
171.swim:       11.22%
172.mrgid:      56.38%
178.galgel:      7.29%
301.apsi:        8.32%
```

Differential Revision: https://reviews.llvm.org/D132176




More information about the All-commits mailing list