[llvm] [LV] Create in-loop sub reductions (PR #147026)

Sam Tebbs via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 18 06:40:40 PDT 2025


================
@@ -644,14 +644,14 @@ define i32 @reduction_sub_lhs(ptr noalias nocapture %A) {
 ; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq i64 [[INDEX_NEXT]], 256
 ; CHECK-NEXT:    br i1 [[TMP2]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP26:![0-9]+]]
 ; CHECK:       middle.block:
-; CHECK-NEXT:    [[TMP3:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[TMP1]])
----------------
SamTebbs33 wrote:

I've traced how the scalar and vector loops act and they are equivalent as they are, but I think I should have removed the change I made to the comment since it doesn't create an in-loop reduction.

```
Data = [1, 2, 3, 4, 5, 6, 7, 8]
Scalar loop:
Iteration | Operation | New Phi
1         | 0 - 1     | -1
2         | -1 - 2    | -3
3         | -3 - 3    | -6
4         | -6 - 4    | -10
5         | -10 - 5   | -15
6         | -15 - 6   | -21
7         | -21 - 7   | -28
8         | -28 - 8   | -36

Vector loop:
Iteration | Operation                           | New Phi
1         | [0, 0, 0, 0] - [1, 2, 3, 4]         | [-1, -2, -3, -4]
2         | [-1, -2, -3, -4] - [-5, -6, -7, -8] | [-6, -8, -10, -12]
reduce.add([-6, -8, -10, -12]) = -36
```

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


More information about the llvm-commits mailing list