[llvm] [InstCombine] Generalize sext (trunc (lshr Y, C)) -> sext/trunc (ashr Y, C) to other shift amounts (PR #227320)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 7 14:51:16 PDT 2026
================
@@ -1994,11 +1995,14 @@ Instruction *InstCombinerImpl::visitSExt(SExtInst &Sext) {
// the logic shift to arithmetic shift and eliminate the cast to
// intermediate type:
// sext (trunc (lshr Y, C)) --> sext/trunc (ashr Y, C)
+ // where C <= truncatedbits && signbits(Y) + C > truncatedbits
Value *Y;
+ const APInt *C;
if (Src->hasOneUse() &&
- match(X, m_LShr(m_Value(Y),
- m_SpecificIntAllowPoison(XBitSize - SrcBitSize)))) {
- Value *Ashr = Builder.CreateAShr(Y, XBitSize - SrcBitSize);
+ match(X, m_LShr(m_Value(Y), m_APIntAllowPoison(C))) &&
+ C->ule(TruncatedBits) &&
+ ComputeNumSignBits(Y, &Sext) + C->getZExtValue() > TruncatedBits) {
----------------
lukel97 wrote:
Sorry for the delay, done in 5083979de924
https://github.com/llvm/llvm-project/pull/227320
More information about the llvm-commits
mailing list