[llvm] [SelectionDAG] Fix bug related to demanded bits/elts for BITCAST (PR #139085)

Björn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Wed May 14 08:04:42 PDT 2025


bjope wrote:

> We have isGuaranteedNotToBeUndefOrPoison - can that be used somehow?
> 
> `<edit>` I assume not as we're trying to not ADD poison as opposed to handle existing poison

One thing I experimented with was to make sure the SimplifyDemanded* functions avoided to make undemanded elements more poisonous. And then I would need to guard lots of things by checking isGuaranteedNotToBeUndefOrPoison. I could for example eliminate an INSERT_VECTOR_ELT if the inserted element wasn't demanded, but only if the same element was guaranteed not to be poison in the source vector. I think I got pretty far with such an approach, but unclear how many places I had missed. I must say that the recursions in SimplifyDemandedBits is a bit complicated to follow. It may recurse into both SimplifyDemandedBits, SimplifyMultipleUseDemandedBits, SimplifyMultipleUseDemandedVectorElts, SimplifyDemandedVectorElts, SimplifyDemandedBitsForTargetNode and SimplifyDemandedVectorEltsForTargetNode (and probably some more). So it is a quite big nest of code that is impacted if we want to change something like that.

https://github.com/llvm/llvm-project/pull/139085


More information about the llvm-commits mailing list