[llvm] [Analysis] Optimise mul(const, (udiv %n, const)) during SCEV expansion (PR #212769)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 30 00:52:50 PDT 2026


================
@@ -599,6 +599,27 @@ Value *SCEVExpander::visitAddExpr(SCEVUseT<const SCEVAddExpr *> S) {
 Value *SCEVExpander::visitMulExpr(SCEVUseT<const SCEVMulExpr *> S) {
   Type *Ty = S->getType();
 
+  // Specializations for 2-operand cases.
+  if (S->getNumOperands() == 2) {
+    const SCEVConstant *MulC;
+    const SCEV *Val;
+    // mul(PowerOf2C, (udiv X, PowerOf2C)) == (X >> C) << C
----------------
david-arm wrote:

Oh, do you mean check for the inverse pattern `udiv(mul(PowerOf2C, X), PowerOf2C)`?

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


More information about the llvm-commits mailing list