[llvm] [SLP][NFC]Fix non-determinism in pointers comparison, NFC (PR #210216)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 16 17:51:51 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Alexey Bataev (alexey-bataev)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/210216.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+13-8)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/210216
More information about the llvm-commits
mailing list