1; REQUIRES: asserts
2
3; RUN: opt -loop-vectorize -mtriple=arm64-apple-ios %s -S -debug -disable-output 2>&1 | FileCheck --check-prefix=CM %s
4; RUN: opt -loop-vectorize -force-vector-width=2 -force-vector-interleave=1 %s -S | FileCheck --check-prefix=FORCED %s
5
6; Test case from PR41294.
7
8; Check scalar cost for extractvalue. The constant and loop invariant operands are free,
9; leaving cost 3 for scalarizing the result + 2 for executing the op with VF 2.
10
11; CM: LV: Found uniform instruction:   %a = extractvalue { i64, i64 } %sv, 0
12; CM: LV: Found uniform instruction:   %b = extractvalue { i64, i64 } %sv, 1
13
14; CM: LV: Scalar loop costs: 5.
15; CM: LV: Found an estimated cost of 0 for VF 2 For instruction:   %a = extractvalue { i64, i64 } %sv, 0
16; CM-NEXT: LV: Found an estimated cost of 0 for VF 2 For instruction:   %b = extractvalue { i64, i64 } %sv, 1
17
18; Check that the extractvalue operands are actually free in vector code.
19
20; FORCED-LABEL: vector.body:                                      ; preds = %vector.body, %vector.ph
21; FORCED-NEXT:    %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
22; FORCED-NEXT:    %0 = add i32 %index, 0
23; FORCED-NEXT:    %1 = extractvalue { i64, i64 } %sv, 0
24; FORCED-NEXT:    %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %1, i32 0
25; FORCED-NEXT:    %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
26; FORCED-NEXT:    %2 = extractvalue { i64, i64 } %sv, 1
27; FORCED-NEXT:    %broadcast.splatinsert1 = insertelement <2 x i64> poison, i64 %2, i32 0
28; FORCED-NEXT:    %broadcast.splat2 = shufflevector <2 x i64> %broadcast.splatinsert1, <2 x i64> poison, <2 x i32> zeroinitializer
29; FORCED-NEXT:    %3 = getelementptr i64, i64* %dst, i32 %0
30; FORCED-NEXT:    %4 = add <2 x i64> %broadcast.splat, %broadcast.splat2
31; FORCED-NEXT:    %5 = getelementptr i64, i64* %3, i32 0
32; FORCED-NEXT:    %6 = bitcast i64* %5 to <2 x i64>*
33; FORCED-NEXT:    store <2 x i64> %4, <2 x i64>* %6, align 4
34; FORCED-NEXT:    %index.next = add nuw i32 %index, 2
35; FORCED-NEXT:    %7 = icmp eq i32 %index.next, 0
36; FORCED-NEXT:    br i1 %7, label %middle.block, label %vector.body, !llvm.loop !0
37
38define void @test1(i64* %dst, {i64, i64} %sv) {
39entry:
40  br label %loop.body
41
42loop.body:
43  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.body ]
44  %a = extractvalue { i64, i64 } %sv, 0
45  %b = extractvalue { i64, i64 } %sv, 1
46  %addr = getelementptr i64, i64* %dst, i32 %iv
47  %add = add i64 %a, %b
48  store i64 %add, i64* %addr
49  %iv.next = add nsw i32 %iv, 1
50  %cond = icmp ne i32 %iv.next, 0
51  br i1 %cond, label %loop.body, label %exit
52
53exit:
54  ret void
55}
56
57
58; Similar to the test case above, but checks getVectorCallCost as well.
59declare float @pow(float, float) readnone nounwind
60
61; CM: LV: Found uniform instruction:   %a = extractvalue { float, float } %sv, 0
62; CM: LV: Found uniform instruction:   %b = extractvalue { float, float } %sv, 1
63
64; CM: LV: Scalar loop costs: 14.
65; CM: LV: Found an estimated cost of 0 for VF 2 For instruction:   %a = extractvalue { float, float } %sv, 0
66; CM-NEXT: LV: Found an estimated cost of 0 for VF 2 For instruction:   %b = extractvalue { float, float } %sv, 1
67
68; FORCED-LABEL: define void @test_getVectorCallCost
69
70; FORCED-LABEL: vector.body:                                      ; preds = %vector.body, %vector.ph
71; FORCED-NEXT:    %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
72; FORCED-NEXT:    %0 = add i32 %index, 0
73; FORCED-NEXT:    %1 = extractvalue { float, float } %sv, 0
74; FORCED-NEXT:    %broadcast.splatinsert = insertelement <2 x float> poison, float %1, i32 0
75; FORCED-NEXT:    %broadcast.splat = shufflevector <2 x float> %broadcast.splatinsert, <2 x float> poison, <2 x i32> zeroinitializer
76; FORCED-NEXT:    %2 = extractvalue { float, float } %sv, 1
77; FORCED-NEXT:    %broadcast.splatinsert1 = insertelement <2 x float> poison, float %2, i32 0
78; FORCED-NEXT:    %broadcast.splat2 = shufflevector <2 x float> %broadcast.splatinsert1, <2 x float> poison, <2 x i32> zeroinitializer
79; FORCED-NEXT:    %3 = getelementptr float, float* %dst, i32 %0
80; FORCED-NEXT:    %4 = call <2 x float> @llvm.pow.v2f32(<2 x float> %broadcast.splat, <2 x float> %broadcast.splat2)
81; FORCED-NEXT:    %5 = getelementptr float, float* %3, i32 0
82; FORCED-NEXT:    %6 = bitcast float* %5 to <2 x float>*
83; FORCED-NEXT:    store <2 x float> %4, <2 x float>* %6, align 4
84; FORCED-NEXT:    %index.next = add nuw i32 %index, 2
85; FORCED-NEXT:    %7 = icmp eq i32 %index.next, 0
86; FORCED-NEXT:    br i1 %7, label %middle.block, label %vector.body, !llvm.loop !4
87
88define void @test_getVectorCallCost(float* %dst, {float, float} %sv) {
89entry:
90  br label %loop.body
91
92loop.body:
93  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.body ]
94  %a = extractvalue { float, float } %sv, 0
95  %b = extractvalue { float, float } %sv, 1
96  %addr = getelementptr float, float* %dst, i32 %iv
97  %p = call float @pow(float %a, float %b)
98  store float %p, float* %addr
99  %iv.next = add nsw i32 %iv, 1
100  %cond = icmp ne i32 %iv.next, 0
101  br i1 %cond, label %loop.body, label %exit
102
103exit:
104  ret void
105}
106