If we are truncating to a narrower type, shifting left, and extending
back to the original type, we could do a left shift in the original
type followed by masking.
https://alive2.llvm.org/ce/z/etjn25
This patch fixes:
Differential D148440
[InstCombine] Fold zext(shl(trunc)) into and(shl) kazu on Apr 15 2023, 2:40 PM. Authored by
Details
If we are truncating to a narrower type, shifting left, and extending https://alive2.llvm.org/ce/z/etjn25 This patch fixes:
Diff Detail
Unit Tests Event Timeline
Comment Actions I missed the entire block of code in InstCombinerImpl::visitZExt to widen an expression tree: // Try to extend the entire expression tree to the wide destination type. unsigned BitsToClear; if (shouldChangeType(SrcTy, DestTy) && canEvaluateZExtd(Src, DestTy, BitsToClear, *this, &Zext)) { Let me see if I could modify this block code to accommodate our trunc-shl-zext sequence.
Comment Actions On X86 at least, shouldChangeType returns false on going from 16-bit integers to 32-bit integers because DataLayout::isLegalInteger always returns false. Note that LegalIntWidths is empty on X86. Widening narrow computation to well supported types like i32 or i64 seems to be a worthwhile transformation. Do we happen to know why LegalIntWidths is empty on X86? Anyone? |
Why only shl, this seems to be pretty generically true:
https://alive2.llvm.org/ce/z/kTBKC7