[llvm] [NFCI][msan] Refactor into 'horizontalReduce' (PR #152961)
Florian Mayer via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 11 13:46:56 PDT 2025
================
@@ -2690,6 +2690,44 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
SC.Done(&I);
}
+ // Perform a bitwise OR on the horizontal pairs (or other specified grouping)
+ // of elements. This is convenient for instrumenting horizontal add/sub.
+ Value *horizontalReduce(IntrinsicInst &I, unsigned ReductionFactor,
+ Value *VectorA, Value* VectorB) {
+ assert(isa<FixedVectorType>(VectorA->getType()));
+ unsigned TotalNumElems
+ = cast<FixedVectorType>(VectorA->getType())->getNumElements();
+
+ if (VectorB) {
+ assert(VectorA->getType() == VectorB->getType());
+ TotalNumElems = TotalNumElems * 2;
+ }
+
+ assert(TotalNumElems % ReductionFactor == 0);
+
+ Value *Or = nullptr;
+
+ IRBuilder<> IRB(&I);
+ for (unsigned i = 0; i < ReductionFactor; i++) {
+ SmallVector<int, 16> Mask;
+ for (unsigned X = 0; X < TotalNumElems; X += ReductionFactor)
----------------
fmayer wrote:
I would put an example in a comment
https://github.com/llvm/llvm-project/pull/152961
More information about the llvm-commits
mailing list