[PATCH] D84547: [ConstraintElimination] Add constraint elimination pass (WIP).

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 24 12:34:33 PDT 2020


fhahn created this revision.
fhahn added reviewers: efriedma, nikic, lebedev.ri, spatel.
Herald added subscribers: kerbowa, hiraditya, mgorny, nhaehnle, jvesely.
Herald added a project: LLVM.

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 issues

- Checking the system requires multiplications/additions on potentially large numbers and could overflow. I guess we would need to detect and bail out when that happens
- 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.

The last 2 don't need to be addressed immediately, but I think the first
one would need to be addressed to start with.

But for now, I'd like to share the approach to get some initial
thoughts/feedback.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84547

Files:
  llvm/include/llvm/Analysis/ConstraintSystem.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Transforms/Scalar.h
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/lib/Transforms/Scalar/CMakeLists.txt
  llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
  llvm/lib/Transforms/Scalar/Scalar.cpp
  llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
  llvm/test/Other/opt-O2-pipeline.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/opt-Os-pipeline.ll
  llvm/test/Transforms/ConstraintElimination/dom.ll
  llvm/test/Transforms/ConstraintElimination/geps.ll
  llvm/test/Transforms/ConstraintElimination/i128.ll
  llvm/test/Transforms/ConstraintElimination/loops.ll
  llvm/test/Transforms/ConstraintElimination/mixed.ll
  llvm/test/Transforms/ConstraintElimination/uge.ll
  llvm/test/Transforms/ConstraintElimination/ugt-ule.ll
  llvm/test/Transforms/ConstraintElimination/ule.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84547.280555.patch
Type: text/x-patch
Size: 37337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200724/3777b1fa/attachment.bin>


More information about the llvm-commits mailing list