[all-commits] [llvm/llvm-project] 02077d: Add jump-threading optimization for deterministic ...

Danilo Carvalho Grael via All-commits all-commits at lists.llvm.org
Tue Jul 27 11:36:08 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 02077da7e7a8ff76c0576bb33adb462c337013f5
      https://github.com/llvm/llvm-project/commit/02077da7e7a8ff76c0576bb33adb462c337013f5
  Author: Alexey Zhikhartsev <alex.zhi at huawei.com>
  Date:   2021-07-27 (Tue, 27 Jul 2021)

  Changed paths:
    M llvm/include/llvm/InitializePasses.h
    M llvm/include/llvm/LinkAllPasses.h
    M llvm/include/llvm/Transforms/Scalar.h
    A llvm/include/llvm/Transforms/Scalar/DFAJumpThreading.h
    M llvm/lib/Passes/PassBuilder.cpp
    M llvm/lib/Passes/PassRegistry.def
    M llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
    M llvm/lib/Transforms/Scalar/CMakeLists.txt
    A llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
    M llvm/lib/Transforms/Scalar/Scalar.cpp
    A llvm/test/Transforms/DFAJumpThreading/dfa-constant-propagation.ll
    A llvm/test/Transforms/DFAJumpThreading/dfa-jump-threading-analysis.ll
    A llvm/test/Transforms/DFAJumpThreading/dfa-jump-threading-transform.ll
    A llvm/test/Transforms/DFAJumpThreading/dfa-unfold-select.ll
    A llvm/test/Transforms/DFAJumpThreading/max-path-length.ll
    A llvm/test/Transforms/DFAJumpThreading/negative.ll

  Log Message:
  -----------
  Add jump-threading optimization for deterministic finite automata

The current JumpThreading pass does not jump thread loops since it can
result in irreducible control flow that harms other optimizations. This
prevents switch statements inside a loop from being optimized to use
unconditional branches.

This code pattern occurs in the core_state_transition function of
Coremark. The state machine can be implemented manually with goto
statements resulting in a large runtime improvement, and this transform
makes the switch implementation match the goto version in performance.

This patch specifically targets switch statements inside a loop that
have the opportunity to be threaded. Once it identifies an opportunity,
it creates new paths that branch directly to the correct code block.
For example, the left CFG could be transformed to the right CFG:

```
          sw.bb                        sw.bb
        /   |   \                    /   |   \
   case1  case2  case3          case1  case2  case3
        \   |   /                /       |       \
        latch.bb             latch.2  latch.3  latch.1
         br sw.bb              /         |         \
                           sw.bb.2     sw.bb.3     sw.bb.1
                            br case2    br case3    br case1
```

Co-author: Justin Kreiner @jkreiner
Co-author: Ehsan Amiri @amehsan

Reviewed By: SjoerdMeijer

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




More information about the All-commits mailing list