[all-commits] [llvm/llvm-project] 805819: [InstCombine] Process newly inserted instructions ...

Nikita Popov via All-commits all-commits at lists.llvm.org
Thu Jan 30 00:40:21 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 80581966771a6d705daddbbf640a91c94652ceb5
      https://github.com/llvm/llvm-project/commit/80581966771a6d705daddbbf640a91c94652ceb5
  Author: Nikita Popov <nikita.ppv at gmail.com>
  Date:   2020-01-30 (Thu, 30 Jan 2020)

  Changed paths:
    M llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h
    M llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
    M llvm/test/Transforms/InstCombine/canonicalize-clamp-like-pattern-between-negative-and-positive-thresholds.ll
    M llvm/test/Transforms/InstCombine/canonicalize-clamp-like-pattern-between-zero-and-positive-threshold.ll
    M llvm/test/Transforms/InstCombine/demorgan.ll
    M llvm/test/Transforms/InstCombine/div.ll
    M llvm/test/Transforms/InstCombine/getelementptr.ll
    M llvm/test/Transforms/InstCombine/load.ll
    M llvm/test/Transforms/InstCombine/logical-select.ll
    M llvm/test/Transforms/InstCombine/max-of-nots.ll
    M llvm/test/Transforms/InstCombine/or.ll
    M llvm/test/Transforms/InstCombine/pr38915.ll
    M llvm/test/Transforms/InstCombine/pr44245.ll
    M llvm/test/Transforms/InstCombine/select-cmp-br.ll
    M llvm/test/Transforms/InstCombine/select-pr39595.ll
    M llvm/test/Transforms/InstCombine/sub-ashr-and-to-icmp-select.ll
    M llvm/test/Transforms/InstCombine/sub-ashr-or-to-icmp-select.ll
    M llvm/test/Transforms/InstCombine/sub-gep.ll
    M llvm/test/Transforms/InstCombine/sub-minmax.ll
    M llvm/test/Transforms/InstCombine/vec_sext.ll
    M llvm/test/Transforms/InstCombine/xor.ll

  Log Message:
  -----------
  [InstCombine] Process newly inserted instructions in the correct order

InstCombine operates on the basic premise that the operands of the
currently processed instruction have already been simplified. It
achieves this by pushing instructions to the worklist in reverse
program order, so that instructions are popped off in program order.
The worklist management in the main combining loop also makes sure
to uphold this invariant.

However, the same is not true for all the code that is performing
manual worklist management. The largest problem (addressed in this
patch) are instructions inserted by InstCombine's IRBuilder. These
will be pushed onto the worklist in order of insertion (generally
matching program order), which means that a) the users of the
original instruction will be visited first, as they are pushed later
in the main loop and b) the newly inserted instructions will be
visited in reverse program order.

This causes a number of problems: First, folds operate on instructions
that have not had their operands simplified, which may result in
optimizations being missed (ran into this in
https://reviews.llvm.org/D72048#1800424, which was the original
motivation for this patch). Additionally, this increases the amount
of folds InstCombine has to perform, both within one iteration, and
by increasing the number of total iterations.

This patch addresses the issue by adding a Worklist.AddDeferred()
method, which is used for instructions inserted by IRBuilder. These
will only be added to the real worklist after the combine finished,
and in reverse order, so they will end up processed in program order.
I should note that the same should also be done to nearly all other
uses of Worklist.Add(), but I'm starting with just this occurrence,
which has by far the largest test fallout.

Most of the test changes are due to
https://bugs.llvm.org/show_bug.cgi?id=44521 or other cases where
we don't canonicalize something. These are neutral. One regression
has been addressed in D73575 and D73647. The remaining regression
in an shl+sdiv fold can't really be fixed without dropping another
transform, but does not seem particularly problematic in the first
place.

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




More information about the All-commits mailing list