[PATCH] D75008: [InstCombine] DCE instructions earlier

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 22 02:07:01 PST 2020


nikic created this revision.
nikic added reviewers: spatel, lebedev.ri, xbolva00.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75008

Files:
  llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h
  llvm/lib/Transforms/InstCombine/InstCombineInternal.h
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
  llvm/test/Transforms/InstCombine/demorgan-sink-not-into-xor.ll
  llvm/test/Transforms/InstCombine/logical-select.ll
  llvm/test/Transforms/InstCombine/pr44245.ll
  llvm/test/Transforms/InstCombine/select-imm-canon.ll
  llvm/test/Transforms/InstCombine/sub-ashr-and-to-icmp-select.ll
  llvm/test/Transforms/InstCombine/sub-ashr-or-to-icmp-select.ll
  llvm/test/Transforms/InstCombine/vec_sext.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75008.246065.patch
Type: text/x-patch
Size: 19453 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200222/b983a099/attachment.bin>


More information about the llvm-commits mailing list