[PATCH] D38313: [InstCombine] Introducing Pattern Instruction Combine plug-in into InstCombine pass

Amjad Aboud via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 05:19:51 PDT 2017


aaboud created this revision.
Herald added a subscriber: mgorny.

This new approach is a replacement for https://reviews.llvm.org/D37195.

**Motivation:**
InstCombine algorithm runs with high complexity (as it keeps running till there is no change to the code), thus it requires that each piece inside the outer loop, have a very small complexity (preferable O(1)).

**Problem**
There are instruction patterns that costs more than O(1) to identify and modify, thus it cannot be added to the InstCombine algorithm.

**Solution**
PatternInstCombiner class, which will run once per invocation to InstCombine pass, and can run all instruction patterns, which might take each up to O(n) complexity, where n is number of instructions in the function.

I introduced in this patch:

1. The PatternInstCombiner class as a plug-in to InstCombine pass.
2. The TruncInstCombine class, first added pattern.

  TruncInstCombine currently supports only simple instructions such as: add, sub, and, or, xor and mul.

The main difference between this and the canEvaluateTruncated from InstCombine is that this one supports:

1. Instructions with multi-use, as long as all are dominated by the truncated instruction.
2. Truncating to different width than the original trunc instruction requires. (this is useful if we reduce the expression width, even if we are not eliminating any instruction).

Next I will add to this TruncInstCombine class the following support, each in a separate patch:

1. select, shufflevector, extractelement, insertelement
2. udiv, urem
3. shl, lshr, ashr
4. phi node (and loop handling)


https://reviews.llvm.org/D38313

Files:
  lib/Transforms/InstCombine/CMakeLists.txt
  lib/Transforms/InstCombine/InstCombineInternal.h
  lib/Transforms/InstCombine/InstCombinePatterns.cpp
  lib/Transforms/InstCombine/InstructionCombining.cpp
  test/Transforms/InstCombine/trunc_pattern.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38313.116794.patch
Type: text/x-patch
Size: 25990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170927/725b94de/attachment.bin>


More information about the llvm-commits mailing list