[PATCH] A bit-tracking DCE Pass

hfinkel at anl.gov hfinkel at anl.gov
Tue Feb 10 03:48:02 PST 2015


Hi chandlerc, nicholas, majnemer, reames, sanjoy, atrick,

This patch introduces a bit-tracking dead code elimination pass, it is based on ADCE (the "aggressive DCE" pass), with the added capability to track dead bits of integer valued instructions and remove those instructions when all of the bits are dead.

Currently, it does not actually do this all-bits-dead removal, but rather replaces the instruction's uses with a constant zero, and lets instcombine (and the later run of ADCE) do the rest. Because we essentially get a run of ADCE "for free" while tracking the dead bits, we also do what ADCE does and removes actually-dead instructions as well.

The motivation for this is a case like:

  int __attribute__((const)) foo(int i);
  int bar(int x) {
    x |= (4 & foo(5));
    x |= (8 & foo(3));
    x |= (16 & foo(2));
    x |= (32 & foo(1));
    x |= (64 & foo(0));
    x |= (128& foo(4));
    return x >> 4;
  }

As it turns out, if you order the bit-field insertions so that all of the dead ones come last, then instcombine will remove them. However, if you pick some other order (such as the one above), the fact that some of the calls to foo() are useless is not locally obvious, and we don't remove them. I could not think of any current pass that "should" remove them, and so I created this one.

It is also possible to do other things with this pass, like "shrink" constant operands to or/and/xor when not all of the bits are required (this might not always be profitable, and we'd probably need to use TTI to make sure we were actually making the constant cheaper).

I did a quick compile-time overhead check using sqlite from the test suite (Release+Asserts). BDCE took ~0.4% of the compilation time (making it about twice as expensive as ADCE).

I've not looked at why yet, but we eliminate instructions due to having all-dead bits in:
External/SPEC/CFP2006/447.dealII/447.dealII
External/SPEC/CINT2006/400.perlbench/400.perlbench
External/SPEC/CINT2006/403.gcc/403.gcc
MultiSource/Applications/ClamAV/clamscan
MultiSource/Benchmarks/7zip/7zip-benchmark

P.S. I hacked this together in one day; criticism is expected. ;) [and more regression tests are certainly needed].

http://reviews.llvm.org/D7531

Files:
  include/llvm-c/Transforms/Scalar.h
  include/llvm/InitializePasses.h
  include/llvm/LinkAllPasses.h
  include/llvm/Transforms/Scalar.h
  lib/Transforms/IPO/PassManagerBuilder.cpp
  lib/Transforms/Scalar/BDCE.cpp
  lib/Transforms/Scalar/CMakeLists.txt
  lib/Transforms/Scalar/Scalar.cpp
  test/Transforms/BDCE/basic.ll

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7531.19660.patch
Type: text/x-patch
Size: 20477 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150210/9c6bbd31/attachment.bin>


More information about the llvm-commits mailing list