Do actual DCE in LoopUnroll (try 4)
authorPhilip Reames <listmail@philipreames.com>
Wed, 19 May 2021 16:50:21 +0000 (09:50 -0700)
committerPhilip Reames <listmail@philipreames.com>
Wed, 19 May 2021 17:25:31 +0000 (10:25 -0700)
commit449d14ebd23b80bbc8bb5a1ba7979b0e4092a2fc
tree1cf85b3296542796ef3e22af420599bc19b61e7c
parent76b8754d1bba6a8490c0f7e8a9e2fb3d181f0b03
Do actual DCE in LoopUnroll (try 4)

Turns out simplifyLoopIVs sometimes returns a non-dead instruction in it's DeadInsts out param.  I had done a bit of NFC cleanup which was only NFC if simplifyLoopIVs obeyed it's documentation.  I'm simplfy dropping that part of the change.

Commit message from try 3:

Recommitting after fixing a bug found post commit. Amusingly, try 1 had been correct, and by reverting to incorporate last minute review feedback, I introduce the bug. Oops. :)

Original commit message:

The problem was that recursively deleting an instruction can delete instructions beyond the current iterator (via a dead phi), thus invalidating iteration. Test case added in LoopUnroll/dce.ll to cover this case.

LoopUnroll does a limited DCE pass after unrolling, but if you have a chain of dead instructions, it only deletes the last one. Improve the code to recursively delete all trivially dead instructions.

Differential Revision: https://reviews.llvm.org/D102511
llvm/lib/Transforms/Utils/LoopUnroll.cpp
llvm/test/Transforms/LoopUnroll/AArch64/full-unroll-trip-count-upper-bound.ll
llvm/test/Transforms/LoopUnroll/dce.ll [new file with mode: 0644]
llvm/test/Transforms/LoopUnroll/full-unroll-invariant.ll
llvm/test/Transforms/LoopUnroll/nonlatchcondbr.ll
llvm/test/Transforms/LoopUnroll/optsize-loop-size.ll
llvm/test/Transforms/LoopUnroll/pr45939-peel-count-and-complete-unroll.ll
llvm/test/Transforms/LoopUnroll/scevunroll.ll
llvm/test/Transforms/LoopUnroll/unroll-header-exiting-with-phis.ll
llvm/test/Transforms/LoopUnroll/unroll-unconditional-latch.ll
llvm/test/Transforms/LoopUnrollAndJam/unroll-and-jam.ll