[llvm] [InstCombine] Added optimization for shift add (PR #163502)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 16 09:46:41 PDT 2025


================
@@ -1635,6 +1674,30 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
       return BinaryOperator::CreateLShr(NewShl, Shl1_Op1);
     }
   }
+
+  // Fold ((X << A) + C) >>u B  -->  (X << (A - B)) + (C >>u B)
+  // when the shift is exact and the add has nuw.
+  const APInt *ShAmtAPInt, *ShlAmt, *AddC;
+  if (match(Op1, m_APInt(ShAmtAPInt)) && I.isExact() &&
----------------
dtcxzyw wrote:

Do we still need this and the ashr variant? Isn't it covered by the changes in `canEvaluateShifted` and `getShiftedValue`?

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


More information about the llvm-commits mailing list