[llvm] [InstCombine] Fold X * (2^N + 1) >> N -> X + X >> N, or directly to X if X >> N is 0 (PR #90295)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 20:00:18 PDT 2024


================
@@ -1479,6 +1479,30 @@ static Value *simplifyLShrInst(Value *Op0, Value *Op1, bool IsExact,
   if (Q.IIQ.UseInstrInfo && match(Op0, m_NUWShl(m_Value(X), m_Specific(Op1))))
     return X;
 
+  // Look for a "splat" mul pattern - it replicates bits across each half
+  // of a value, so a right shift is just a mask of the low bits:
+  // lshr i[2N] (mul nuw X, (2^N)+1), N --> and iN X, (2^N)-1
----------------
topperc wrote:

This code doesn't create an `and`

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


More information about the llvm-commits mailing list