[llvm] [InstCombine] Fold ((cst << x) & 1) --> x == 0 when cst is odd (PR #79772)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 30 21:46:12 PST 2024


================
@@ -2220,10 +2220,13 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
   Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
 
   Value *X, *Y;
-  if (match(Op0, m_OneUse(m_LogicalShift(m_One(), m_Value(X)))) &&
+  const APInt *C;
+  if ((match(Op0, m_OneUse(m_LogicalShift(m_One(), m_Value(X)))) ||
+       (match(Op0, m_OneUse(m_Shl(m_APInt(C), m_Value(X)))) &&
+        C->countr_zero() == 0)) &&
----------------
dtcxzyw wrote:

```suggestion
        (*C)[0])) &&
```


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


More information about the llvm-commits mailing list