[llvm] [InstCombine] Add fold combining adjacent extracted bit fields to restore optimization for separate truncations (PR #219598)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 29 04:07:42 PDT 2026
================
@@ -4319,6 +4319,29 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
return BinaryOperator::CreateAnd(Or, C01);
}
}
+
+ // (trunc (lshr X, S) & C0) | (lshr (trunc X), S & C1)
+ // --> (trunc (lshr X, S) & (C0 | C1) (and similar cases)
+ // A = trunc (lshr X, S) B = lshr (trunc X), S
+ const APInt *ShiftAmt;
+ if (match(A, m_OneUse(m_Trunc(m_LShr(m_Value(X), m_APInt(ShiftAmt))))) &&
+ match(B, m_LShr(m_Trunc(m_Specific(X)),
+ m_SpecificInt(ShiftAmt->getZExtValue())))) {
+ APInt CombinedMask = *C0 | *C1;
+ return BinaryOperator::CreateAnd(
+ A, ConstantInt::get(I.getType(), CombinedMask));
+ }
+ // A = lshr (trunc X), S
+ // B = trunc (lshr X, S)
+ const APInt *ReverseShiftAmt;
----------------
andjo403 wrote:
no need for an other APInt reuse the other one only adds extra noise
https://github.com/llvm/llvm-project/pull/219598
More information about the llvm-commits
mailing list