[all-commits] [llvm/llvm-project] 3d42d5: [ConstraintElimination] Add constraint elimination...

Florian Hahn via All-commits all-commits at lists.llvm.org
Tue Sep 15 11:32:14 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 3d42d549554889ca182e1f3d31b23fa1383c6678
      https://github.com/llvm/llvm-project/commit/3d42d549554889ca182e1f3d31b23fa1383c6678
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2020-09-15 (Tue, 15 Sep 2020)

  Changed paths:
    M llvm/include/llvm/Analysis/ConstraintSystem.h
    M llvm/include/llvm/InitializePasses.h
    M llvm/include/llvm/Transforms/Scalar.h
    M llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
    M llvm/lib/Transforms/Scalar/CMakeLists.txt
    A llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
    M llvm/lib/Transforms/Scalar/Scalar.cpp
    M llvm/test/Transforms/ConstraintElimination/dom.ll
    M llvm/test/Transforms/ConstraintElimination/geps.2d.ll
    M llvm/test/Transforms/ConstraintElimination/geps.ll
    M llvm/test/Transforms/ConstraintElimination/i128.ll
    M llvm/test/Transforms/ConstraintElimination/loops.ll
    M llvm/test/Transforms/ConstraintElimination/mixed.ll
    M llvm/test/Transforms/ConstraintElimination/uge.ll
    M llvm/test/Transforms/ConstraintElimination/ugt-ule.ll
    M llvm/test/Transforms/ConstraintElimination/ule.ll

  Log Message:
  -----------
  [ConstraintElimination] Add constraint elimination pass.

This patch is a first draft of a new pass that adds a more flexible way
to eliminate compares based on more complex constraints collected from
dominating conditions.

In particular, it aims at simplifying conditions of the forms below
using a forward propagation approach, rather than instcomine-style
ad-hoc backwards walking of def-use chains.

    if (x < y)
      if (y < z)
        if (x < z) <- simplify

or

    if (x + 2 < y)
        if (x + 1 < y) <- simplify assuming no wraps

The general approach is to collect conditions and blocks, sort them by
dominance and then iterate over the sorted list. Conditions are turned
into a linear inequality and add it to a system containing the linear
inequalities that hold on entry to the block. For blocks, we check each
compare against the system and see if it is implied by the constraints
in the system.

We also keep a stack of processed conditions and remove conditions from
the stack and the constraint system once they go out-of-scope (= do not
dominate the current block any longer).

Currently there still are the least the following areas for improvements

* Currently large unsigned constants cannot be added to the system
  (coefficients must be represented as integers)
* The way constraints are managed currently is not very optimized.

Reviewed By: spatel

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




More information about the All-commits mailing list