commit | a704e6587bfd974af053712c6da01fa04d74c31b | [log] [tgz] |
---|---|---|
author | Slava Zakharin <szakharin@nvidia.com> | Mon Mar 03 09:58:20 2025 -0800 |
committer | GitHub <noreply@github.com> | Mon Mar 03 09:58:20 2025 -0800 |
tree | 038114cbbc68422eef3bf59639ae05a8ef5f5007 | |
parent | d2c4d1ec48b7c723307121164099fb2fa7d959a9 [diff] |
[flang] Added alternative inlining code for hlfir.cshift. (#129176) Flang generates slower code for `CSHIFT(CSHIFT(PTR(:,:,I),sh1,1),sh2,2)` pattern in facerec than other compilers. The first CSHIFT can be done as two memcpy's wrapped in a loop for the second dimension. This does require creating a temporary array, but it seems to be faster, than the current hlfir.elemental inlining. I started with modifying the new index computation in hlfir.elemental inlining: the new arith.select approach does enable some vectorization in LLVM, but on x86 it is using gathers/scatters and does not give much speed-up. I also experimented with LoopBoundSplitPass and InductiveRangeCheckElimination for a simple (not chained) CSHIFT case, but I could not adjust them to split the loop with a condition on the value of the IV into two loops with disjoint iteration spaces. I thought if I could do it, I would be able to keep the hlfir.elemental inlining mostly untouched, and then adjust the hlfir.elemental inlining heuristics for the facerec case. Since I was not able to make these pass work for me, I added a special case inlining for CSHIFT(ARRAY,SH,DIM=1) via hlfir.eval_in_mem. If ARRAY is not statically known to have the contiguous leading dimension, there is a dynamic check for contiguity, which allows exposing it to LLVM and enabling the rewrite of the copy loops into memcpys. This approach is stepping on the toes of LoopVersioning, but it is helpful in facerec case. I measured ~6% speed-up on grace, and ~4% on zen4.
Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.