[llvm] [SLP][NFC]Fix non-determinism in pointers comparison, NFC (PR #210216)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 16 17:51:14 PDT 2026
https://github.com/alexey-bataev created https://github.com/llvm/llvm-project/pull/210216
None
>From f4c40eaf2433aab6da33a512aff8d5d5875bdb91 Mon Sep 17 00:00:00 2001
From: Alexey Bataev <a.bataev at outlook.com>
Date: Thu, 16 Jul 2026 17:51:00 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.7
---
.../Transforms/Vectorize/SLPVectorizer.cpp | 21 ++++++++++++-------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 6698395bf963b..93af803644a60 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -24660,9 +24660,10 @@ bool BoUpSLP::isCoveredByExistingVersionCheck(BasicBlock *BB,
const Value *Base2 = getUnderlyingObject(Ptr2);
if (Base1 == Base2)
return false;
- if (Base2 < Base1)
- std::swap(Base1, Base2);
- return It->second.contains({Base1, Base2});
+ // The recorded pairs keep their discovery order (see
+ // recordRuntimeAliasCheck), so accept either orientation.
+ return It->second.contains({Base1, Base2}) ||
+ It->second.contains({Base2, Base1});
}
/// Returns true if \p BB's body already contains vector instructions, e.g.
@@ -24702,16 +24703,20 @@ bool BoUpSLP::recordRuntimeAliasCheck(BasicBlock *BB, Instruction *Inst1,
// Only a single block can be versioned per attempt.
if (RTChecks.BB && RTChecks.BB != BB)
return false;
- // Normalize the pair order so duplicate checks collapse.
- if (Base2 < Base1)
- std::swap(Base1, Base2);
+ // A base-object pair is unordered: (Base1, Base2) and (Base2, Base1) are the
+ // same check. Keep it in discovery (program) order and drop the reverse as a
+ // duplicate, rather than ordering by pointer value, which would make the
+ // emitted checks depend on allocation addresses.
auto Pair = std::make_pair(Base1, Base2);
+ bool Present = RTChecks.BasePairs.contains(Pair) ||
+ RTChecks.BasePairs.contains({Base2, Base1});
// After the checks have been validated and bounded, do not introduce new
// pairs.
if (RTChecksFinalized)
- return RTChecks.BasePairs.contains(Pair);
+ return Present;
RTChecks.BB = BB;
- RTChecks.BasePairs.insert(Pair);
+ if (!Present)
+ RTChecks.BasePairs.insert(Pair);
return true;
}
More information about the llvm-commits
mailing list