[all-commits] [llvm/llvm-project] 99b3c7: [Analysis] Optimise mul(const, (udiv %n, const)) d...

David Sherwood via All-commits all-commits at lists.llvm.org
Fri Jul 31 00:52:25 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 99b3c767c34a04af0a2bbb1fd41bf1b2cb62b331
      https://github.com/llvm/llvm-project/commit/99b3c767c34a04af0a2bbb1fd41bf1b2cb62b331
  Author: David Sherwood <david.sherwood at arm.com>
  Date:   2026-07-31 (Fri, 31 Jul 2026)

  Changed paths:
    M llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
    M llvm/test/CodeGen/AMDGPU/memset-param-combinations.ll
    M llvm/test/CodeGen/RISCV/branch-on-zero.ll
    M llvm/test/Transforms/IndVarSimplify/ARM/code-size.ll
    M llvm/test/Transforms/IndVarSimplify/replace-loop-exit-folds.ll
    M llvm/test/Transforms/LoopIdiom/basic.ll
    M llvm/test/Transforms/LoopStrengthReduce/AArch64/expand-ptrtoaddr-reuse-ptrtoint.ll
    M llvm/test/Transforms/LoopVectorize/AArch64/reduction-cost.ll
    M llvm/test/Transforms/LoopVectorize/interleaved-accesses-metadata.ll
    M llvm/test/Transforms/LoopVectorize/opaque-ptr.ll
    M llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp

  Log Message:
  -----------
  [Analysis] Optimise mul(const, (udiv %n, const)) during SCEV expansion (#212769)

We sometimes see SCEV expansions like this:

  %lshr = lshr i64 %n, 2
  %shl = shl i64 %lshr, 2

which originate from SCEV mul and udiv expressions:

  mul(4, udiv(%n, 4))

that both share the same multiplicand, divisor. The instcombine pass
normally canonicalises this into

  %and = and %n, -4

which is the final IR typically seen by the backend. In the case of SCEV
expansion during a pass like the loop vectoriser, instcombine does clean
this up. However, before this is cleaned up it will lead to
over-estimation of costs of SCEV checks, since the shifts are costed
separately and added up. It doesn't seem like there is an easy way to
look at the use count of a SCEV node in the SCEVExpander code. However,
I think for simple cases like this it's always beneficial to fold them
even if there are multiple uses of the SCEV udiv because we're dropping
both shifts.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list