[all-commits] [llvm/llvm-project] 0d429d: [LICM] Preserve nsw when reassociating integer add...

Andrey Grabezhnoy via All-commits all-commits at lists.llvm.org
Mon Sep 28 07:33:34 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0d429d44791ec27e40f08b3e9d51b743ee7fd870
      https://github.com/llvm/llvm-project/commit/0d429d44791ec27e40f08b3e9d51b743ee7fd870
  Author: Andrey Grabezhnoy <andrey.grabezhnoy at intel.com>
  Date:   2026-09-28 (Mon, 28 Sep 2026)

  Changed paths:
    M llvm/lib/Transforms/Scalar/LICM.cpp
    M llvm/test/Transforms/LICM/hoist-binop.ll

  Log Message:
  -----------
  [LICM] Preserve nsw when reassociating integer adds (#221210)

When LICM reassociates (LV + C1) + C2 into LV + (C1 + C2), it currently
drops nsw unless both original additions also have nuw.

After applying the usual OverflowTracking flags, set nsw directly on
both generated additions when both original additions have nsw and value
tracking proves that C1 + C2 cannot overflow in signed arithmetic. This
enables hoistAdd() later in the same LICM run.

Tests cover constant operands, scalar and vector operands proven safe
through known bits, operands constrained by dominating assumptions, and
the case where only the outer addition has nsw.

[Alive2 proof](https://alive2.llvm.org/ce/z/DC2dWY) of the
reassociation. The llvm.assume models the separately established fact
that C1 + C2 cannot overflow in signed arithmetic. The public example
uses i8 to finish quickly; the same proof also succeeds locally with
i32.

Fixes #220897



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