[all-commits] [llvm/llvm-project] 4ef272: [InstCombine] DCE instructions earlier

Nikita Popov via All-commits all-commits at lists.llvm.org
Thu Feb 27 09:46:11 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 4ef272ec9c5f737b8d63a3cc8870d8d63bf0385e
      https://github.com/llvm/llvm-project/commit/4ef272ec9c5f737b8d63a3cc8870d8d63bf0385e
  Author: Nikita Popov <nikita.ppv at gmail.com>
  Date:   2020-02-27 (Thu, 27 Feb 2020)

  Changed paths:
    M llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h
    M llvm/lib/Transforms/InstCombine/InstCombineInternal.h
    M llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
    M llvm/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
    M llvm/test/Transforms/InstCombine/demorgan-sink-not-into-xor.ll
    M llvm/test/Transforms/InstCombine/logical-select.ll
    M llvm/test/Transforms/InstCombine/pr44245.ll
    M llvm/test/Transforms/InstCombine/select-imm-canon.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/vec_sext.ll
    M llvm/test/Transforms/SimplifyCFG/merge-cond-stores.ll

  Log Message:
  -----------
  [InstCombine] DCE instructions earlier

When InstCombine initially populates the worklist, it already
performs constant folding and DCE. However, as the instructions
are initially visited in program order, this DCE can pick up only
the last instruction of a dead chain, the rest would only get
picked up in the main InstCombine run.

To avoid this, we instead perform the DCE in separate pass over the
collected instructions in reverse order, which will allow us to
pick up full dead instruction chains. We already need to do this
reverse iteration anyway to populate the worklist, so this
shouldn't add extra cost.

This by itself only fixes a small part of the problem though:
The same basic issue also applies during the main InstCombine loop.
We generally always want DCE to occur as early as possible,
because it will allow one-use folds to happen. Address this by also
performing DCE while adding deferred instructions to the main worklist.

This drops the number of tests that perform more than 2 InstCombine
iterations from ~80 to ~40. There's some spurious test changes due
to operand order / icmp toggling.

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




More information about the All-commits mailing list