[PATCH] D60413: [AggressiveInstCombine] SExt -> ZExt when no sign bits is used with multiple uses

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 7 08:56:30 PDT 2020


nikic added a comment.

In D60413#2135831 <https://reviews.llvm.org/D60413#2135831>, @lebedev.ri wrote:

> Why doesn't `InstCombiner::SimplifyDemandedUseBits()` handle this?
>  I would have expected this <https://github.com/llvm/llvm-project/blob/874fcd4e8ffc42717a41e57ddcedb4ab63e63854/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L426-L430> to already deal with it.


`SimplifyDemandedUseBits()` can only handle single-use cases, because demanded bits are only computed for a specific use. There is `SimplifyMultipleUseDemandedBits()`, but it can only simplify a specific use-site, not replace a whole instruction.

This patch has the right general idea, in that `DemandedBits` is the analysis that can determine this for the multi-use case. However, I'm not very comfortable with performing a full demanded bits calculation (on the whole function) in AggressiveInstCombine, just for this purpose. I think it would be better to repurpose BDCE (which already computes DemandedBits) to be a bit more general and also perform some demanded-bits based folds there, rather than only DCE. (This is similar to how SCCP has recently started replacing sext with zext if possible, even though that is not the primary purpose of that pass.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60413/new/

https://reviews.llvm.org/D60413





More information about the llvm-commits mailing list