Review Report

Agent analysis and findings from PR review
Bugs Found
1
Total Time
5m 13s
Chat Rounds
21
Total Tokens
871,876
Est. Cost
-

Test Strategies (Phase 1)

1 Non-reverse arbitrary strided-store permutation
Target
Mutate basic-strided-stores.ll constant_stride_reorder_data / constant_stride_reorder_geps store order to a non-reverse, non-self-inverse permutation such as address-order values [load0, load3, load1, load6, load2, load7, load5, load4], and FileCheck the pre-store shufflevector mask equals that address-order permutation.
Rationale
The patch changes FinalShuffle for Store+StridedVectorize to call add(V, ReorderIndices) instead of addOrdered(V, ReorderIndices). This is exactly where arbitrary non-reverse reorder masks differ from inverse-permutation semantics. An 8-lane i8 case with a self-inverse-avoiding permutation distinguishes the two masks.
Expected Issue
The generated shuffle before llvm.experimental.vp.strided.store may still use the inverse permutation or the load-side order rather than the store-address order, so memory slots receive wrong lanes (e.g. ps+6 gets load7 instead of load3).
2 Reversed-address strided store with data reorder
Target
Create/mutate a strided-store test where the store instructions appear in descending memory order (e.g. ps+14, ps+12, ..., ps+0) but the stored loaded values are permuted independently. Check whether the vectorizer emits either a negative/adjusted stride plus a compensating shuffle or preserves scalar stores.
Rationale
The fix intentionally keeps reversed strided stores as addOrdered(V,{}) before testing Store+StridedVectorize. That assumes reverse-order strided stores never require the store-specific data reorder mask, or that reversing the pointer/stride fully accounts for ReorderIndices. A reversed address order combined with non-reversed value order can violate this assumption.
Expected Issue
The special first branch for (StridedVectorize && IsReverseOrder) bypasses the store-specific handling. If a reversed strided store also has data-lane reordering, the pass may suppress a needed shuffle entirely or choose base/stride inconsistent with data order.
3 Store reorder combined with reused scalar lanes
Target
Mutate a strided-store test so multiple stores write the same scalar/load value and the tree has ReuseShuffleIndices, e.g. store [load0, load2, load2, load1, load5, load4, load7, load6] to ascending strided addresses. FileCheck that the shuffle/store value has duplicate lanes in the exact address order and no poison for live stores.
Rationale
FinalShuffle applies add(...ReorderIndices) and then finalize(E->ReuseShuffleIndices,...). The patch fixes only the initial store reorder direction. If values are duplicated or reused, ExtMask composition uses CommonMask[ExtMask[I]], and store masks may need different composition than ordinary reorders. Duplicate stored values can expose wrong lane reuse or poison lanes.
Expected Issue
The single final shuffle may compose ReuseShuffleIndices with the store ReorderIndices in the wrong direction, producing a valid-looking but semantically wrong composed mask.
4 Revectorized vector-element strided stores with reorder
Target
Extend RISCV/revec-strided-store.ll with stores of vector-typed values (e.g. load `<2 x i8>` chunks, store them to strided vector-element addresses in permuted order) and check that the shufflevector mask is replicated/expanded correctly before vp.strided.store.
Rationale
ShuffleInstructionBuilder is parameterized by ScalarTy and may cast/transform masks when ScalarTy itself is a fixed vector. The new store-specific path directly reinterprets ReorderIndices as int and passes it to add(), unlike addOrdered() and other paths that may go through scalar-to-vector mask expansion. ReVec cases with `<2 x i8>` or `<4 x i8>` scalar elements can reveal whether the mask is expanded at the correct granularity.
Expected Issue
The generated mask or vector type may be malformed or semantically off by the scalar-vector element expansion factor; stores may write subelements in the wrong order.
5 External-user induced store reorder from non-store producer
Target
Start from a test with vectorized arithmetic/load producer feeding stores; mutate so the producer has both in-tree uses and external strided store users with a nontrivial permutation. Check that the store’s vp.strided.store base is the lowest address and the input vector shuffle matches address order.
Rationale
ReorderIndices can be introduced by findExternalStoreUsersReorderIndices for store users of a producer TE, not only by the store bundle itself. The cost model treats store order as a mask, but other reordering propagation may clear/invert/compose it. A producer used by an external strided store can violate the assumption that E->ReorderIndices maps directly from vector lanes to store-address lanes at emission.
Expected Issue
The base pointer selected from E->ReorderIndices.front() and the data shuffle mask may disagree after bottom-up/top-down reordering, causing the strided store to start at a non-lowest address while the value lanes are arranged for ascending addresses.

Bugs Found (Phase 2)

BUG #1
Analysis

The previous differential test timed out executing the transformed vp.strided.store intrinsic, but static inspection of opt output proves a real semantic mismatch: original stores to offsets 14,12,10,8,6,4,2,0; optimized emits a single vp.strided.store from base %ps+8 with positive stride 2 and EVL 8, which stores to offsets 8,10,12,14,16,18,20,22. Therefore offsets 0,2,4,6 are no longer written and offsets 16..22 are newly written. This is independent of data values and is a real miscompile for the reversed-address strided store with data reorder mutation.

Original IR
@pl = global [16 x i8] c"\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F", align 1
@ps = global [32 x i8] zeroinitializer, align 1

define void @reversed_addr_data_reorder(ptr %pl, ptr %ps) {
  %l0 = getelementptr i8, ptr %pl, i64 0
  %l1 = getelementptr i8, ptr %pl, i64 1
  %l2 = getelementptr i8, ptr %pl, i64 2
  %l3 = getelementptr i8, ptr %pl, i64 3
  %l4 = getelementptr i8, ptr %pl, i64 4
  %l5 = getelementptr i8, ptr %pl, i64 5
  %l6 = getelementptr i8, ptr %pl, i64 6
  %l7 = getelementptr i8, ptr %pl, i64 7
  %v0 = load i8, ptr %l0, align 1
  %v1 = load i8, ptr %l1, align 1
  %v2 = load i8, ptr %l2, align 1
  %v3 = load i8, ptr %l3, align 1
  %v4 = load i8, ptr %l4, align 1
  %v5 = load i8, ptr %l5, align 1
  %v6 = load i8, ptr %l6, align 1
  %v7 = load i8, ptr %l7, align 1
  %s0 = getelementptr i8, ptr %ps, i64 14
  %s1 = getelementptr i8, ptr %ps, i64 12
  %s2 = getelementptr i8, ptr %ps, i64 10
  %s3 = getelementptr i8, ptr %ps, i64 8
  %s4 = getelementptr i8, ptr %ps, i64 6
  %s5 = getelementptr i8, ptr %ps, i64 4
  %s6 = getelementptr i8, ptr %ps, i64 2
  %s7 = getelementptr i8, ptr %ps, i64 0
  store i8 %v0, ptr %s0, align 1
  store i8 %v3, ptr %s1, align 1
  store i8 %v1, ptr %s2, align 1
  store i8 %v6, ptr %s3, align 1
  store i8 %v2, ptr %s4, align 1
  store i8 %v7, ptr %s5, align 1
  store i8 %v5, ptr %s6, align 1
  store i8 %v4, ptr %s7, align 1
  ret void
}

define void @main(i32 %argc, ptr %argv) {
entry:
  call void @reversed_addr_data_reorder(ptr @pl, ptr @ps)
  ret void
}
Transformed IR
; ModuleID = '/data/tmp/tmp0nsxem15/orig.ll'
source_filename = "/data/tmp/tmp0nsxem15/orig.ll"
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "riscv64"

@pl = global [16 x i8] c"\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F", align 1
@ps = global [32 x i8] zeroinitializer, align 1

define void @reversed_addr_data_reorder(ptr %pl, ptr %ps) #0 {
  %l0 = getelementptr i8, ptr %pl, i64 0
  %s3 = getelementptr i8, ptr %ps, i64 8
  %1 = load <8 x i8>, ptr %l0, align 1
  %2 = shufflevector <8 x i8> %1, <8 x i8> poison, <8 x i32> <i32 4, i32 5, i32 7, i32 2, i32 6, i32 1, i32 3, i32 0>
  call void @llvm.experimental.vp.strided.store.v8i8.p0.i64(<8 x i8> %2, ptr align 1 %s3, i64 2, <8 x i1> splat (i1 true), i32 8)
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: write)
declare void @llvm.experimental.vp.strided.store.v8i8.p0.i64(<8 x i8>, ptr captures(none), i64, <8 x i1>, i32) #1

attributes #0 = { "target-features"="+m,+v" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }

define void @main(i32 %argc, ptr %argv) {
entry:
  call void @reversed_addr_data_reorder(ptr @pl, ptr @ps)
  ret void
}
Output Log
Confirmed as bug by agent.
Original Output: {'timed_out': False, 'return_code': 0, 'stdout': '', 'stderr': '', 'executor': 'llubi'}
Transformed Output: {'timed_out': True, 'return_code': None, 'stdout': '', 'stderr': '', 'executor': 'llubi'}

Analysis & Findings

Bug Triggering Analysis:
This mutation targets the patch's explicit exception for (E->State == TreeEntry::StridedVectorize && IsReverseOrder). The scalar program stores to a descending strided address sequence: %ps+14, +12, +10, +8, +6, +4, +2, +0, while the stored values are independently permuted (v0,v3,v1,v6,v2,v7,v5,v4). Running opt with -mtriple=riscv64 -mattr=+m,+v -passes=slp-vectorizer -S -slp-enable-strided-stores transforms it to:

%s3 = getelementptr i8, ptr %ps, i64 8
%1 = load <8 x i8>, ptr %l0, align 1
%2 = shufflevector <8 x i8> %1, poison, <8 x i32> <i32 4, i32 5, i32 7, i32 2, i32 6, i32 1, i32 3, i32 0>
call void @llvm.experimental.vp.strided.store.v8i8.p0.i64(<8 x i8> %2, ptr align 1 %s3, i64 2, <8 x i1> splat (i1 true), i32 8)

By the LangRef, llvm.experimental.vp.strided.store stores lanes at base + i * stride bytes. The optimized code therefore writes offsets 8,10,12,14,16,18,20,22. The original program wrote offsets 14,12,10,8,6,4,2,0. Thus offsets 0,2,4,6 are dropped and offsets 16,18,20,22 are newly written. This is a clear memory-effect mismatch independent of lane values.

Verification Notes:
Alive2 could not complete verification for the target-specific experimental VP strided-store intrinsic. Differential execution with llubi timed out on the transformed intrinsic, but the transformed IR from trans and the intrinsic's specified address semantics are sufficient to confirm the bug. The difftest result was confirmed as a real bug based on this static semantic mismatch.

Fix Weakness Analysis:
The patch corrected non-reverse strided stores by treating store ReorderIndices as a direct shuffle mask. However, it preserves the reverse-order fast path before the store-specific branch:

if ((E->State == TreeEntry::StridedVectorize && IsReverseOrder) || ...)
  addOrdered(V, {});
else if (Store && (Vectorize || StridedVectorize))
  add(V, ReorderIndices);

This assumes reverse-order strided stores require no store-specific reorder handling and that base/stride selection elsewhere fully accounts for reversal. The test violates that assumption by combining reversed memory order with independent data reorder. The resulting base pointer is neither the low address nor a correct high-address base with negative stride; it starts at %ps+8 and uses positive stride, producing an incorrect address set. Therefore the fix leaves an edge case in the reversed strided-store path.