[PATCH] D45173: [InstCombine] Recognize idioms for ctpop and ctlz

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 4 14:51:36 PDT 2018


efriedma added a comment.

> This isn't sustainable in the long run. Recognizing complex computations and replacing them with short equivalents (such as intrinsics that targets may provide efficient implementations of) is arguably better than only doing peephole optimizations, and yet the current model makes it really difficult to write such code.

Recognizing every pattern which is equivalent to popcount is basically impossible.  (I mean, you could theoretically integrate something like Alive into LLVM to recognize any straight-line code which is equivalent to popcount, but that's probably not practical.)  So you have to come up with some specific set of patterns to recognize, based on what the source code looks like and what transforms run before your pattern-recognition code.

As you've noted, running "instcombine" before your pattern-recognition code is going to be a constant source of trouble, because it isn't a fixed set of transforms, and it runs very early in the pass pipeline.  So either you run your pattern-recognition before instcombine, or you add some tests to the LLVM regression tests which will break if a new transform breaks your pattern-recognition, and hope for the best.  I guess it might help a bit if we came up with some restricted criteria for allowed transforms in instcombine, and put the rest into aggressive-instcombine.  But we're never going to completely freeze the optimization pipeline, so there's fundamentally some maintenance burden.


Repository:
  rL LLVM

https://reviews.llvm.org/D45173





More information about the llvm-commits mailing list