[all-commits] [llvm/llvm-project] 7ff58e: [LoopVectorize] Fix nondeterminism in loop-vectori...

Orlando Cazalet-Hyams via All-commits all-commits at lists.llvm.org
Mon Jun 15 00:29:32 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7ff58e4747dcece251d3e5cf2e5d8de4670c5252
      https://github.com/llvm/llvm-project/commit/7ff58e4747dcece251d3e5cf2e5d8de4670c5252
  Author: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
  Date:   2026-06-15 (Mon, 15 Jun 2026)

  Changed paths:
    M llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
    A llvm/test/Transforms/LoopVectorize/X86/nondetermisitic-widening-cost.ll

  Log Message:
  -----------
  [LoopVectorize] Fix nondeterminism in loop-vectorize (#200833)

The nondeterministic iteration over `AddrDefs` (SmallPtrSet) causes
nondeterministic output for the test case in this patch (reduced from a
C codebase). One of two different outputs is generated arbitrarily,
chosen roughly equally.

Between the two different outputs sometimes the instruction
   `%3 = load i64, ptr %2, align 8`
has an associated cost of 4 and othertimes 9. The instruction is visited
twice in `setCostBasedWideningDecision` in the `AddrDefs` loop: once
directly as an element of `AddrDefs`, and the other time indirectly in
the lambda `UpdateMemOpUserCost` as a User of another `AddrDefs`
element. Each of those times `setWideningDecision` is called with a
different cost value; the final of the two calls sets the final value
(previous is overwritten). Because `AddrDefs` iteration is
nondeterministic, the order of those two calls to `setWideningDecision`
is also nondeterministic, hence we see two different costs arbitrarily
between runs.

This patch prevents the nondeterministic iteration order.

Some additional info:
We observe the issue reproducing (frequently) in llvm-22 but not
llvm-21.

With the test case in this patch we observe the nondeterminism
frequently reproduces (< 3 tries) from
1f331e453fa9c328c165c739f61e17a2815ece82 building on and targeting
x86_64 linux. Before that we haven't observed the nondeterminism (> 500
tries), but can't rule out that it may be observed with different inputs
based on the fact the SmallPtrSet has been in use since 2017. N.B.
Building on Windows bisects to a different commit.



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