[llvm] 9f839a4 - [SLP][NFC]Fix non-determinism in pointers comparison, NFC
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 16 17:52:33 PDT 2026
Author: Alexey Bataev
Date: 2026-07-16T20:52:29-04:00
New Revision: 9f839a4396916283cc28e45d18d7f4742ad5094a
URL: https://github.com/llvm/llvm-project/commit/9f839a4396916283cc28e45d18d7f4742ad5094a
DIFF: https://github.com/llvm/llvm-project/commit/9f839a4396916283cc28e45d18d7f4742ad5094a.diff
LOG: [SLP][NFC]Fix non-determinism in pointers comparison, NFC
Reviewers:
Pull Request: https://github.com/llvm/llvm-project/pull/210216
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
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