Skip to content

Commit

Permalink
[RISCV] Add cost tests for more interleave factors. NFC
Browse files Browse the repository at this point in the history
This shows how we're not properly scaling the cost with the number of
factors, i.e. a factor 8 interleave costs the same as a factor 2
interleave at VF=2.
  • Loading branch information
lukel97 committed Oct 8, 2024
1 parent 327124e commit 366e469
Showing 1 changed file with 237 additions and 0 deletions.
237 changes: 237 additions & 0 deletions llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,240 @@ for.body:
for.end:
ret void
}

%i8.4 = type {i8, i8, i8, i8}
define void @i8_factor_4(ptr %data, i64 %n) {
entry:
br label %for.body
; CHECK-LABEL: Checking a loop in 'i8_factor_4'
; CHECK: Cost of 2 for VF 2: INTERLEAVE-GROUP with factor 4 at %l0, ir<%p0>
; CHECK: Cost of 2 for VF 2: INTERLEAVE-GROUP with factor 4 at <badref>, ir<%p0>
; CHECK: Cost of 2 for VF 4: INTERLEAVE-GROUP with factor 4 at %l0, ir<%p0>
; CHECK: Cost of 2 for VF 4: INTERLEAVE-GROUP with factor 4 at <badref>, ir<%p0>
; CHECK: Cost of 3 for VF 8: INTERLEAVE-GROUP with factor 4 at %l0, ir<%p0>
; CHECK: Cost of 3 for VF 8: INTERLEAVE-GROUP with factor 4 at <badref>, ir<%p0>
; CHECK: Cost of 5 for VF 16: INTERLEAVE-GROUP with factor 4 at %l0, ir<%p0>
; CHECK: Cost of 5 for VF 16: INTERLEAVE-GROUP with factor 4 at <badref>, ir<%p0>
; CHECK: Cost of 9 for VF 32: INTERLEAVE-GROUP with factor 4 at %l0, ir<%p0>
; CHECK: Cost of 9 for VF 32: INTERLEAVE-GROUP with factor 4 at <badref>, ir<%p0>
for.body:
%i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]
%p0 = getelementptr inbounds %i8.4, ptr %data, i64 %i, i32 0
%p1 = getelementptr inbounds %i8.4, ptr %data, i64 %i, i32 1
%p2 = getelementptr inbounds %i8.4, ptr %data, i64 %i, i32 2
%p3 = getelementptr inbounds %i8.4, ptr %data, i64 %i, i32 3
%l0 = load i8, ptr %p0, align 1
%l1 = load i8, ptr %p1, align 1
%l2 = load i8, ptr %p2, align 1
%l3 = load i8, ptr %p3, align 1
%a0 = add i8 %l0, 1
%a1 = add i8 %l1, 2
%a2 = add i8 %l2, 3
%a3 = add i8 %l3, 4
store i8 %a0, ptr %p0, align 1
store i8 %a1, ptr %p1, align 1
store i8 %a2, ptr %p2, align 1
store i8 %a3, ptr %p3, align 1
%i.next = add nuw nsw i64 %i, 1
%cond = icmp slt i64 %i.next, %n
br i1 %cond, label %for.body, label %for.end

for.end:
ret void
}

%i8.5 = type {i8, i8, i8, i8, i8}
define void @i8_factor_5(ptr %data, i64 %n) {
entry:
br label %for.body
; CHECK-LABEL: Checking a loop in 'i8_factor_5'
; CHECK: Cost of 2 for VF 2: INTERLEAVE-GROUP with factor 5 at %l0, ir<%p0>
; CHECK: Cost of 2 for VF 2: INTERLEAVE-GROUP with factor 5 at <badref>, ir<%p0>
; CHECK: Cost of 3 for VF 4: INTERLEAVE-GROUP with factor 5 at %l0, ir<%p0>
; CHECK: Cost of 3 for VF 4: INTERLEAVE-GROUP with factor 5 at <badref>, ir<%p0>
; CHECK: Cost of 5 for VF 8: INTERLEAVE-GROUP with factor 5 at %l0, ir<%p0>
; CHECK: Cost of 5 for VF 8: INTERLEAVE-GROUP with factor 5 at <badref>, ir<%p0>
; CHECK: Cost of 9 for VF 16: INTERLEAVE-GROUP with factor 5 at %l0, ir<%p0>
; CHECK: Cost of 9 for VF 16: INTERLEAVE-GROUP with factor 5 at <badref>, ir<%p0>
for.body:
%i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]
%p0 = getelementptr inbounds %i8.5, ptr %data, i64 %i, i32 0
%p1 = getelementptr inbounds %i8.5, ptr %data, i64 %i, i32 1
%p2 = getelementptr inbounds %i8.5, ptr %data, i64 %i, i32 2
%p3 = getelementptr inbounds %i8.5, ptr %data, i64 %i, i32 3
%p4 = getelementptr inbounds %i8.5, ptr %data, i64 %i, i32 4
%l0 = load i8, ptr %p0, align 1
%l1 = load i8, ptr %p1, align 1
%l2 = load i8, ptr %p2, align 1
%l3 = load i8, ptr %p3, align 1
%l4 = load i8, ptr %p4, align 1
%a0 = add i8 %l0, 1
%a1 = add i8 %l1, 2
%a2 = add i8 %l2, 3
%a3 = add i8 %l3, 4
%a4 = add i8 %l4, 5
store i8 %a0, ptr %p0, align 1
store i8 %a1, ptr %p1, align 1
store i8 %a2, ptr %p2, align 1
store i8 %a3, ptr %p3, align 1
store i8 %a4, ptr %p4, align 1
%i.next = add nuw nsw i64 %i, 1
%cond = icmp slt i64 %i.next, %n
br i1 %cond, label %for.body, label %for.end

for.end:
ret void
}

%i8.6 = type {i8, i8, i8, i8, i8, i8}
define void @i8_factor_6(ptr %data, i64 %n) {
entry:
br label %for.body
; CHECK-LABEL: Checking a loop in 'i8_factor_6'
; CHECK: Cost of 2 for VF 2: INTERLEAVE-GROUP with factor 6 at %l0, ir<%p0>
; CHECK: Cost of 2 for VF 2: INTERLEAVE-GROUP with factor 6 at <badref>, ir<%p0>
; CHECK: Cost of 3 for VF 4: INTERLEAVE-GROUP with factor 6 at %l0, ir<%p0>
; CHECK: Cost of 3 for VF 4: INTERLEAVE-GROUP with factor 6 at <badref>, ir<%p0>
; CHECK: Cost of 5 for VF 8: INTERLEAVE-GROUP with factor 6 at %l0, ir<%p0>
; CHECK: Cost of 5 for VF 8: INTERLEAVE-GROUP with factor 6 at <badref>, ir<%p0>
; CHECK: Cost of 9 for VF 16: INTERLEAVE-GROUP with factor 6 at %l0, ir<%p0>
; CHECK: Cost of 9 for VF 16: INTERLEAVE-GROUP with factor 6 at <badref>, ir<%p0>
for.body:
%i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]
%p0 = getelementptr inbounds %i8.6, ptr %data, i64 %i, i32 0
%p1 = getelementptr inbounds %i8.6, ptr %data, i64 %i, i32 1
%p2 = getelementptr inbounds %i8.6, ptr %data, i64 %i, i32 2
%p3 = getelementptr inbounds %i8.6, ptr %data, i64 %i, i32 3
%p4 = getelementptr inbounds %i8.6, ptr %data, i64 %i, i32 4
%p5 = getelementptr inbounds %i8.6, ptr %data, i64 %i, i32 5
%l0 = load i8, ptr %p0, align 1
%l1 = load i8, ptr %p1, align 1
%l2 = load i8, ptr %p2, align 1
%l3 = load i8, ptr %p3, align 1
%l4 = load i8, ptr %p4, align 1
%l5 = load i8, ptr %p5, align 1
%a0 = add i8 %l0, 1
%a1 = add i8 %l1, 2
%a2 = add i8 %l2, 3
%a3 = add i8 %l3, 4
%a4 = add i8 %l4, 5
%a5 = add i8 %l5, 6
store i8 %a0, ptr %p0, align 1
store i8 %a1, ptr %p1, align 1
store i8 %a2, ptr %p2, align 1
store i8 %a3, ptr %p3, align 1
store i8 %a4, ptr %p4, align 1
store i8 %a5, ptr %p5, align 1
%i.next = add nuw nsw i64 %i, 1
%cond = icmp slt i64 %i.next, %n
br i1 %cond, label %for.body, label %for.end

for.end:
ret void
}

%i8.7 = type {i8, i8, i8, i8, i8, i8, i8}
define void @i8_factor_7(ptr %data, i64 %n) {
entry:
br label %for.body
; CHECK-LABEL: Checking a loop in 'i8_factor_7'
; CHECK: Cost of 2 for VF 2: INTERLEAVE-GROUP with factor 7 at %l0, ir<%p0>
; CHECK: Cost of 2 for VF 2: INTERLEAVE-GROUP with factor 7 at <badref>, ir<%p0>
; CHECK: Cost of 3 for VF 4: INTERLEAVE-GROUP with factor 7 at %l0, ir<%p0>
; CHECK: Cost of 3 for VF 4: INTERLEAVE-GROUP with factor 7 at <badref>, ir<%p0>
; CHECK: Cost of 5 for VF 8: INTERLEAVE-GROUP with factor 7 at %l0, ir<%p0>
; CHECK: Cost of 5 for VF 8: INTERLEAVE-GROUP with factor 7 at <badref>, ir<%p0>
; CHECK: Cost of 9 for VF 16: INTERLEAVE-GROUP with factor 7 at %l0, ir<%p0>
; CHECK: Cost of 9 for VF 16: INTERLEAVE-GROUP with factor 7 at <badref>, ir<%p0>
for.body:
%i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]
%p0 = getelementptr inbounds %i8.7, ptr %data, i64 %i, i32 0
%p1 = getelementptr inbounds %i8.7, ptr %data, i64 %i, i32 1
%p2 = getelementptr inbounds %i8.7, ptr %data, i64 %i, i32 2
%p3 = getelementptr inbounds %i8.7, ptr %data, i64 %i, i32 3
%p4 = getelementptr inbounds %i8.7, ptr %data, i64 %i, i32 4
%p5 = getelementptr inbounds %i8.7, ptr %data, i64 %i, i32 5
%p6 = getelementptr inbounds %i8.7, ptr %data, i64 %i, i32 6
%l0 = load i8, ptr %p0, align 1
%l1 = load i8, ptr %p1, align 1
%l2 = load i8, ptr %p2, align 1
%l3 = load i8, ptr %p3, align 1
%l4 = load i8, ptr %p4, align 1
%l5 = load i8, ptr %p5, align 1
%l6 = load i8, ptr %p6, align 1
%a0 = add i8 %l0, 1
%a1 = add i8 %l1, 2
%a2 = add i8 %l2, 3
%a3 = add i8 %l3, 4
%a4 = add i8 %l4, 5
%a5 = add i8 %l5, 6
%a6 = add i8 %l6, 7
store i8 %a0, ptr %p0, align 1
store i8 %a1, ptr %p1, align 1
store i8 %a2, ptr %p2, align 1
store i8 %a3, ptr %p3, align 1
store i8 %a4, ptr %p4, align 1
store i8 %a5, ptr %p5, align 1
store i8 %a6, ptr %p6, align 1
%i.next = add nuw nsw i64 %i, 1
%cond = icmp slt i64 %i.next, %n
br i1 %cond, label %for.body, label %for.end

for.end:
ret void
}

%i8.8 = type {i8, i8, i8, i8, i8, i8, i8, i8}
define void @i8_factor_8(ptr %data, i64 %n) {
entry:
br label %for.body
; CHECK-LABEL: Checking a loop in 'i8_factor_8'
; CHECK: Cost of 2 for VF 2: INTERLEAVE-GROUP with factor 8 at %l0, ir<%p0>
; CHECK: Cost of 2 for VF 2: INTERLEAVE-GROUP with factor 8 at <badref>, ir<%p0>
; CHECK: Cost of 3 for VF 4: INTERLEAVE-GROUP with factor 8 at %l0, ir<%p0>
; CHECK: Cost of 3 for VF 4: INTERLEAVE-GROUP with factor 8 at <badref>, ir<%p0>
; CHECK: Cost of 5 for VF 8: INTERLEAVE-GROUP with factor 8 at %l0, ir<%p0>
; CHECK: Cost of 5 for VF 8: INTERLEAVE-GROUP with factor 8 at <badref>, ir<%p0>
; CHECK: Cost of 9 for VF 16: INTERLEAVE-GROUP with factor 8 at %l0, ir<%p0>
; CHECK: Cost of 9 for VF 16: INTERLEAVE-GROUP with factor 8 at <badref>, ir<%p0>
for.body:
%i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]
%p0 = getelementptr inbounds %i8.8, ptr %data, i64 %i, i32 0
%p1 = getelementptr inbounds %i8.8, ptr %data, i64 %i, i32 1
%p2 = getelementptr inbounds %i8.8, ptr %data, i64 %i, i32 2
%p3 = getelementptr inbounds %i8.8, ptr %data, i64 %i, i32 3
%p4 = getelementptr inbounds %i8.8, ptr %data, i64 %i, i32 4
%p5 = getelementptr inbounds %i8.8, ptr %data, i64 %i, i32 5
%p6 = getelementptr inbounds %i8.8, ptr %data, i64 %i, i32 6
%p7 = getelementptr inbounds %i8.8, ptr %data, i64 %i, i32 7
%l0 = load i8, ptr %p0, align 1
%l1 = load i8, ptr %p1, align 1
%l2 = load i8, ptr %p2, align 1
%l3 = load i8, ptr %p3, align 1
%l4 = load i8, ptr %p4, align 1
%l5 = load i8, ptr %p5, align 1
%l6 = load i8, ptr %p6, align 1
%l7 = load i8, ptr %p7, align 1
%a0 = add i8 %l0, 1
%a1 = add i8 %l1, 2
%a2 = add i8 %l2, 3
%a3 = add i8 %l3, 4
%a4 = add i8 %l4, 5
%a5 = add i8 %l5, 6
%a6 = add i8 %l6, 7
%a7 = add i8 %l7, 8
store i8 %a0, ptr %p0, align 1
store i8 %a1, ptr %p1, align 1
store i8 %a2, ptr %p2, align 1
store i8 %a3, ptr %p3, align 1
store i8 %a4, ptr %p4, align 1
store i8 %a5, ptr %p5, align 1
store i8 %a6, ptr %p6, align 1
store i8 %a7, ptr %p7, align 1
%i.next = add nuw nsw i64 %i, 1
%cond = icmp slt i64 %i.next, %n
br i1 %cond, label %for.body, label %for.end

for.end:
ret void
}

0 comments on commit 366e469

Please sign in to comment.