[llvm] ReduxWidth check for 0 (PR #123257)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 16 15:40:56 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-vectorizers

Author: George Chaltas (gchaltas)

<details>
<summary>Changes</summary>

Added assert to check for underflow of ReduxWidth

	modified:   llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp


Source code analysis flagged   the operation (ReduxWwidth - 1) as potential underflow, since ReduxWidth is unsigned.
Realize that this should never happen if everything is working right, but added an assert to check for it just in case.

---
Full diff: https://github.com/llvm/llvm-project/pull/123257.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+1) 


``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index b0b8f8249d657b..ae08b0e5a33403 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -20080,6 +20080,7 @@ class HorizontalReduction {
         NumRegs =
             TTI.getNumberOfRegisters(TTI.getRegisterClassForType(true, Tp));
         while (NumParts > NumRegs) {
+	  assert(ReduxWidth > 0 && "ReduxWidth is unexpectedly 0.");
           ReduxWidth = bit_floor(ReduxWidth - 1);
           VectorType *Tp = getWidenedType(ScalarTy, ReduxWidth);
           NumParts = TTI.getNumberOfParts(Tp);

``````````

</details>


https://github.com/llvm/llvm-project/pull/123257


More information about the llvm-commits mailing list