llvm-project
d607d6f7 - [LegalizeTypes] Keep non-negative info in SUB(CTLZ) (#186338)

Commit
29 days ago
[LegalizeTypes] Keep non-negative info in SUB(CTLZ) (#186338) When legalizing CTLZ for a wider type with a SUB bit-width compensation, the result for a zero-defined case can have an extra bit that exceeds the maximum value of the original type width. Unlike CTLS, which covers all bits within its type width, CTLZ leads to producing undefined KnownBits. So, after subtraction, the KnownBits could represent a negative value, which prevents subsequent optimizations. This patch ensures that non-negative information is preserved during the SUB(CTLZ) expansion, so that KnownBits after SUB will take a stricter range within the type width, thus allowing further combine optimizations following by SUB. Particularly, this enables the DAG Combiner to remove unnecessary AND instructions for CTLZ output type conversion. Fixes #136516 --------- Co-authored-by: Simon Pilgrim <git@redking.me.uk>
Parents
Loading