Skip to content

Commit 2047ab0

Browse files
authored
[VPlan] Add a test for testing unused interleave recipes (#75026)
- Precommit of tests from #71360. - Replace `undef` pointer operands and add stores to avoid the loads being optmized away.
1 parent 342384c commit 2047ab0

File tree

3 files changed

+90
-38
lines changed

3 files changed

+90
-38
lines changed

llvm/test/CodeGen/ARM/loopvectorize_pr33804.ll

+22-19
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ target triple = "armv7-unknown-linux-gnueabihf"
1515
; CHECK-LABEL: @cvCalcEMD2
1616
; CHECK: vector.body
1717
; CHECK: store <{{[0-9]+}} x ptr>
18-
define void @cvCalcEMD2() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
18+
define void @cvCalcEMD2(ptr %dst) {
1919
entry:
2020
br label %for.body14.i.i
2121

2222
for.body14.i.i: ; preds = %for.body14.i.i, %entry
2323
%i.1424.i.i = phi i32 [ %inc21.i.i, %for.body14.i.i ], [ 0, %entry ]
24-
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D, ptr undef, i32 %i.1424.i.i
24+
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D, ptr %dst, i32 %i.1424.i.i
2525
store float 0xC415AF1D80000000, ptr %arrayidx15.i.i1427, align 4
26-
%next19.i.i = getelementptr inbounds %struct.CvNode1D, ptr undef, i32 %i.1424.i.i, i32 1
27-
store ptr undef, ptr %next19.i.i, align 4
26+
%next19.i.i = getelementptr inbounds %struct.CvNode1D, ptr %dst, i32 %i.1424.i.i, i32 1
27+
store ptr %dst, ptr %next19.i.i, align 4
2828
%inc21.i.i = add nuw nsw i32 %i.1424.i.i, 1
2929
%exitcond438.i.i = icmp eq i32 %inc21.i.i, 0
3030
br i1 %exitcond438.i.i, label %for.end22.i.i, label %for.body14.i.i
@@ -40,15 +40,15 @@ for.end22.i.i: ; preds = %for.body14.i.i
4040
; CHECK-LABEL: @cvCalcEMD2_2
4141
; CHECK: vector.body
4242
; CHECK: store <{{[0-9]+}} x float>
43-
define void @cvCalcEMD2_2() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
43+
define void @cvCalcEMD2_2(ptr %dst) {
4444
entry:
4545
br label %for.body14.i.i
4646

4747
for.body14.i.i: ; preds = %for.body14.i.i, %entry
4848
%i.1424.i.i = phi i32 [ %inc21.i.i, %for.body14.i.i ], [ 0, %entry ]
49-
%next19.i.i = getelementptr inbounds %struct.CvNode1D2, ptr undef, i32 %i.1424.i.i, i32 0
50-
store ptr undef, ptr %next19.i.i, align 4
51-
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D2, ptr undef, i32 %i.1424.i.i
49+
%next19.i.i = getelementptr inbounds %struct.CvNode1D2, ptr %dst, i32 %i.1424.i.i, i32 0
50+
store ptr %dst, ptr %next19.i.i, align 4
51+
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D2, ptr %dst, i32 %i.1424.i.i
5252
%val.i.i = getelementptr inbounds %struct.CvNode1D2, ptr %arrayidx15.i.i1427, i32 0, i32 1
5353
store float 0xC415AF1D80000000, ptr %val.i.i, align 4
5454
%inc21.i.i = add nuw nsw i32 %i.1424.i.i, 1
@@ -64,16 +64,20 @@ for.end22.i.i: ; preds = %for.body14.i.i
6464
; CHECK-LABEL: @cvCalcEMD3
6565
; CHECK: vector.body
6666
; CHECK: inttoptr <{{[0-9]+}} x i32>
67-
define void @cvCalcEMD3() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
67+
define void @cvCalcEMD3(ptr %src, ptr %dst) {
6868
entry:
6969
br label %for.body14.i.i
7070

7171
for.body14.i.i: ; preds = %for.body14.i.i, %entry
7272
%i.1424.i.i = phi i32 [ %inc21.i.i, %for.body14.i.i ], [ 0, %entry ]
73-
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D, ptr undef, i32 %i.1424.i.i
73+
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D, ptr %src, i32 %i.1424.i.i
7474
%loadf = load float, ptr %arrayidx15.i.i1427, align 4
75-
%next19.i.i = getelementptr inbounds %struct.CvNode1D, ptr undef, i32 %i.1424.i.i, i32 1
75+
%next19.i.i = getelementptr inbounds %struct.CvNode1D, ptr %src, i32 %i.1424.i.i, i32 1
7676
%loadp = load ptr, ptr %next19.i.i, align 4
77+
%dst.ptr = getelementptr inbounds %struct.CvNode1D, ptr %dst, i32 %i.1424.i.i
78+
%dst.ptr.1 = getelementptr inbounds %struct.CvNode1D, ptr %dst, i32 %i.1424.i.i, i32 1
79+
store float %loadf, ptr %dst.ptr, align 4
80+
store ptr %loadp, ptr %dst.ptr.1, align 4
7781
%inc21.i.i = add nuw nsw i32 %i.1424.i.i, 1
7882
%exitcond438.i.i = icmp eq i32 %inc21.i.i, 0
7983
br i1 %exitcond438.i.i, label %for.end22.i.i, label %for.body14.i.i
@@ -87,26 +91,25 @@ for.end22.i.i: ; preds = %for.body14.i.i
8791
; CHECK-LABEL: @cvCalcEMD3_2
8892
; CHECK: vector.body
8993
; CHECK: ptrtoint <{{[0-9]+}} x ptr>
90-
define void @cvCalcEMD3_2() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
94+
define void @cvCalcEMD3_2(ptr %src, ptr %dst) {
9195
entry:
9296
br label %for.body14.i.i
9397

9498
for.body14.i.i: ; preds = %for.body14.i.i, %entry
9599
%i.1424.i.i = phi i32 [ %inc21.i.i, %for.body14.i.i ], [ 0, %entry ]
96-
%next19.i.i = getelementptr inbounds %struct.CvNode1D2, ptr undef, i32 %i.1424.i.i, i32 0
100+
%next19.i.i = getelementptr inbounds %struct.CvNode1D2, ptr %src, i32 %i.1424.i.i, i32 0
97101
%loadp = load ptr, ptr %next19.i.i, align 4
98-
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D2, ptr undef, i32 %i.1424.i.i
102+
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D2, ptr %src, i32 %i.1424.i.i
99103
%val.i.i = getelementptr inbounds %struct.CvNode1D2, ptr %arrayidx15.i.i1427, i32 0, i32 1
100104
%loadf = load float, ptr %val.i.i, align 4
105+
%dst.ptr = getelementptr inbounds %struct.CvNode1D, ptr %dst, i32 %i.1424.i.i
106+
%dst.ptr.1 = getelementptr inbounds %struct.CvNode1D, ptr %dst, i32 %i.1424.i.i, i32 1
107+
store float %loadf, ptr %dst.ptr, align 4
108+
store ptr %loadp, ptr %dst.ptr.1, align 4
101109
%inc21.i.i = add nuw nsw i32 %i.1424.i.i, 1
102110
%exitcond438.i.i = icmp eq i32 %inc21.i.i, 0
103111
br i1 %exitcond438.i.i, label %for.end22.i.i, label %for.body14.i.i
104112

105113
for.end22.i.i: ; preds = %for.body14.i.i
106114
unreachable
107115
}
108-
109-
declare i32 @__gxx_personality_v0(...)
110-
111-
attributes #0 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+dsp,+neon,+vfp3,-thumb-mode" "unsafe-fp-math"="false" "use-soft-float"="false" }
112-

llvm/test/Transforms/LoopVectorize/AArch64/loopvectorize_pr33804_double.ll

+22-19
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ target triple = "aarch64-unknown-linux-gnu"
1515
; CHECK-LABEL: @cvCalcEMD2
1616
; CHECK: vector.body
1717
; CHECK: store <{{[0-9]+}} x ptr>
18-
define void @cvCalcEMD2() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
18+
define void @cvCalcEMD2(ptr %dst) {
1919
entry:
2020
br label %for.body14.i.i
2121

2222
for.body14.i.i: ; preds = %for.body14.i.i, %entry
2323
%i.1424.i.i = phi i32 [ %inc21.i.i, %for.body14.i.i ], [ 0, %entry ]
24-
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D, ptr undef, i32 %i.1424.i.i
24+
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D, ptr %dst, i32 %i.1424.i.i
2525
store double 0xC415AF1D80000000, ptr %arrayidx15.i.i1427, align 4
26-
%next19.i.i = getelementptr inbounds %struct.CvNode1D, ptr undef, i32 %i.1424.i.i, i32 1
27-
store ptr undef, ptr %next19.i.i, align 4
26+
%next19.i.i = getelementptr inbounds %struct.CvNode1D, ptr %dst, i32 %i.1424.i.i, i32 1
27+
store ptr %dst, ptr %next19.i.i, align 4
2828
%inc21.i.i = add nuw nsw i32 %i.1424.i.i, 1
2929
%exitcond438.i.i = icmp eq i32 %inc21.i.i, 0
3030
br i1 %exitcond438.i.i, label %for.end22.i.i, label %for.body14.i.i
@@ -40,15 +40,15 @@ for.end22.i.i: ; preds = %for.body14.i.i
4040
; CHECK-LABEL: @cvCalcEMD2_2
4141
; CHECK: vector.body
4242
; CHECK: store <{{[0-9]+}} x double>
43-
define void @cvCalcEMD2_2() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
43+
define void @cvCalcEMD2_2(ptr %dst) {
4444
entry:
4545
br label %for.body14.i.i
4646

4747
for.body14.i.i: ; preds = %for.body14.i.i, %entry
4848
%i.1424.i.i = phi i32 [ %inc21.i.i, %for.body14.i.i ], [ 0, %entry ]
49-
%next19.i.i = getelementptr inbounds %struct.CvNode1D2, ptr undef, i32 %i.1424.i.i, i32 0
50-
store ptr undef, ptr %next19.i.i, align 4
51-
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D2, ptr undef, i32 %i.1424.i.i
49+
%next19.i.i = getelementptr inbounds %struct.CvNode1D2, ptr %dst, i32 %i.1424.i.i, i32 0
50+
store ptr %dst, ptr %next19.i.i, align 4
51+
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D2, ptr %dst, i32 %i.1424.i.i
5252
%val.i.i = getelementptr inbounds %struct.CvNode1D2, ptr %arrayidx15.i.i1427, i32 0, i32 1
5353
store double 0xC415AF1D80000000, ptr %val.i.i, align 4
5454
%inc21.i.i = add nuw nsw i32 %i.1424.i.i, 1
@@ -64,16 +64,20 @@ for.end22.i.i: ; preds = %for.body14.i.i
6464
; CHECK-LABEL: @cvCalcEMD3
6565
; CHECK: vector.body
6666
; CHECK: inttoptr <{{[0-9]+}} x i64>
67-
define void @cvCalcEMD3() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
67+
define void @cvCalcEMD3(ptr %src, ptr %dst) {
6868
entry:
6969
br label %for.body14.i.i
7070

7171
for.body14.i.i: ; preds = %for.body14.i.i, %entry
7272
%i.1424.i.i = phi i32 [ %inc21.i.i, %for.body14.i.i ], [ 0, %entry ]
73-
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D, ptr undef, i32 %i.1424.i.i
73+
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D, ptr %src, i32 %i.1424.i.i
7474
%load_d = load double, ptr %arrayidx15.i.i1427, align 4
75-
%next19.i.i = getelementptr inbounds %struct.CvNode1D, ptr undef, i32 %i.1424.i.i, i32 1
75+
%next19.i.i = getelementptr inbounds %struct.CvNode1D, ptr %src, i32 %i.1424.i.i, i32 1
7676
%load_p = load ptr, ptr %next19.i.i, align 4
77+
%dst.ptr = getelementptr inbounds %struct.CvNode1D, ptr %dst, i32 %i.1424.i.i
78+
%dst.ptr.1 = getelementptr inbounds %struct.CvNode1D, ptr %dst, i32 %i.1424.i.i, i32 1
79+
store double %load_d, ptr %dst.ptr, align 4
80+
store ptr %load_p, ptr %dst.ptr.1, align 4
7781
%inc21.i.i = add nuw nsw i32 %i.1424.i.i, 1
7882
%exitcond438.i.i = icmp eq i32 %inc21.i.i, 0
7983
br i1 %exitcond438.i.i, label %for.end22.i.i, label %for.body14.i.i
@@ -87,26 +91,25 @@ for.end22.i.i: ; preds = %for.body14.i.i
8791
; CHECK-LABEL: @cvCalcEMD3_2
8892
; CHECK: vector.body
8993
; CHECK: ptrtoint <{{[0-9]+}} x ptr>
90-
define void @cvCalcEMD3_2() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
94+
define void @cvCalcEMD3_2(ptr %src, ptr %dst) {
9195
entry:
9296
br label %for.body14.i.i
9397

9498
for.body14.i.i: ; preds = %for.body14.i.i, %entry
9599
%i.1424.i.i = phi i32 [ %inc21.i.i, %for.body14.i.i ], [ 0, %entry ]
96-
%next19.i.i = getelementptr inbounds %struct.CvNode1D2, ptr undef, i32 %i.1424.i.i, i32 0
100+
%next19.i.i = getelementptr inbounds %struct.CvNode1D2, ptr %src, i32 %i.1424.i.i, i32 0
97101
%load_p = load ptr, ptr %next19.i.i, align 4
98-
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D2, ptr undef, i32 %i.1424.i.i
102+
%arrayidx15.i.i1427 = getelementptr inbounds %struct.CvNode1D2, ptr %src, i32 %i.1424.i.i
99103
%val.i.i = getelementptr inbounds %struct.CvNode1D2, ptr %arrayidx15.i.i1427, i32 0, i32 1
100104
%load_d = load double, ptr %val.i.i, align 4
105+
%dst.ptr = getelementptr inbounds %struct.CvNode1D, ptr %dst, i32 %i.1424.i.i
106+
%dst.ptr.1 = getelementptr inbounds %struct.CvNode1D, ptr %dst, i32 %i.1424.i.i, i32 1
107+
store double %load_d, ptr %dst.ptr, align 4
108+
store ptr %load_p, ptr %dst.ptr.1, align 4
101109
%inc21.i.i = add nuw nsw i32 %i.1424.i.i, 1
102110
%exitcond438.i.i = icmp eq i32 %inc21.i.i, 0
103111
br i1 %exitcond438.i.i, label %for.end22.i.i, label %for.body14.i.i
104112

105113
for.end22.i.i: ; preds = %for.body14.i.i
106114
unreachable
107115
}
108-
109-
declare i32 @__gxx_personality_v0(...)
110-
111-
attributes #0 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
112-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2+
; RUN: opt -passes=loop-vectorize -S -force-vector-width=4 -enable-interleaved-mem-accesses=true -debug-only=loop-vectorize < %s 2>&1 | FileCheck %s
3+
; REQUIRES: asserts
4+
5+
; This test checks if an unused interleave group is removed by removeDeadRecipes.
6+
7+
%struct.foo = type { ptr, ptr }
8+
9+
define void @test_unused_interleave(ptr %src, i32 %length) {
10+
; CHECK-LABEL: Checking a loop in 'test_unused_interleave'
11+
; CHECK: VPlan 'Initial VPlan for VF={4},UF>=1' {
12+
; CHECK-NEXT: Live-in vp<%0> = vector-trip-count
13+
; CHECK-NEXT: Live-in ir<%length> = original trip-count
14+
; CHECK-EMPTY:
15+
; CHECK-NEXT: vector.ph:
16+
; CHECK-NEXT: Successor(s): vector loop
17+
; CHECK-EMPTY:
18+
; CHECK-NEXT: <x1> vector loop: {
19+
; CHECK-NEXT: vector.body:
20+
; CHECK-NEXT: EMIT vp<%1> = CANONICAL-INDUCTION ir<0>, vp<%6>
21+
; CHECK-NEXT: vp<%2> = SCALAR-STEPS vp<%1>, ir<1>
22+
; CHECK-NEXT: CLONE ir<%next19.i.i> = getelementptr inbounds ir<%src>, vp<%2>, ir<0>
23+
; CHECK-NEXT: INTERLEAVE-GROUP with factor 2 at %load_p1, ir<%next19.i.i>
24+
; CHECK-NEXT: ir<%load_p1> = load from index 0
25+
; CHECK-NEXT: ir<%load_p2> = load from index 1
26+
; CHECK-NEXT: EMIT vp<%6> = VF * UF + nuw vp<%1>
27+
; CHECK-NEXT: EMIT branch-on-count vp<%6>, vp<%0>
28+
; CHECK-NEXT: No successors
29+
; CHECK-NEXT: }
30+
entry:
31+
br label %for.body
32+
33+
for.body:
34+
%iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]
35+
%next19.i.i = getelementptr inbounds %struct.foo, ptr %src, i32 %iv, i32 0
36+
%load_p1 = load ptr, ptr %next19.i.i, align 4
37+
%arrayidx15.i.i1427 = getelementptr inbounds %struct.foo, ptr %src, i32 %iv
38+
%val.i.i = getelementptr inbounds %struct.foo, ptr %arrayidx15.i.i1427, i32 0, i32 1
39+
%load_p2 = load ptr, ptr %val.i.i, align 4
40+
%iv.next = add nuw nsw i32 %iv, 1
41+
%cond = icmp eq i32 %iv.next, %length
42+
br i1 %cond, label %for.end, label %for.body
43+
44+
for.end:
45+
ret void
46+
}

0 commit comments

Comments
 (0)