[llvm] [InstCombine] Add fold combining adjacent extracted bit fields to restore optimization for separate truncations (PR #219598)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 13 04:25:18 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_Trunc(m_LShr(m_Value(X), m_APInt(ShiftAmt)))) &&
+ match(B, m_LShr(m_Trunc(m_Specific(X)), m_SpecificInt(*ShiftAmt))) &&
+ ShiftAmt->ult(A->getType()->getScalarSizeInBits()) &&
+ !C1->intersects(APInt::getHighBitsSet(
+ A->getType()->getScalarSizeInBits(), ShiftAmt->getZExtValue()))) {
+ return BinaryOperator::CreateAnd(
+ A, ConstantInt::getIntegerValue(I.getType(), *C0 | *C1));
----------------
dtcxzyw wrote:
`ConstantInt::get` supports vector types:
https://github.com/llvm/llvm-project/blob/31a1c03fe67cccd917f11e5ab50cc425770c1400/llvm/lib/IR/Constants.cpp#L994-L1004
I replaced `ConstantInt::getIntegerValue` with `ConstantInt::get`, and it didn't break any tests.
https://github.com/llvm/llvm-project/pull/219598
More information about the llvm-commits
mailing list