[llvm] [InstCombine] Canonicalise packed-integer-selecting shifts (PR #162147)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 7 01:09:15 PDT 2025


================
@@ -800,6 +800,48 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I,
         Known.Zero.setHighBits(ShiftAmt);  // high bits known zero.
     } else {
       llvm::computeKnownBits(I, Known, Q, Depth);
+
+      // Let N = 2 * M.
+      // Given an N-bit integer representing a pack of two M-bit integers,
+      // we can select one of the packed integers by right-shifting by either
+      // zero or M (which is the most straightforward to check if M is a power
+      // of 2), and then isolating the lower M bits. In this case, we can
+      // represent the shift as a select on whether the shr amount is nonzero.
+      uint64_t ShlAmt;
+      Value *Upper, *Lower;
+      if (!match(I->getOperand(0),
+                 m_OneUse(m_DisjointOr(
----------------
dtcxzyw wrote:

```suggestion
                 m_OneUse(m_c_DisjointOr(
```
Can you please add some commuted tests?


https://github.com/llvm/llvm-project/pull/162147


More information about the llvm-commits mailing list