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
6 ; Test case from PR41294.
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.
11 ; CM: LV: Scalar loop costs: 7.
12 ; CM: LV: Found an estimated cost of 5 for VF 2 For instruction: %a = extractvalue { i64, i64 } %sv, 0
13 ; CM-NEXT: LV: Found an estimated cost of 5 for VF 2 For instruction: %b = extractvalue { i64, i64 } %sv, 1
15 ; Check that the extractvalue operands are actually free in vector code.
17 ; FORCED-LABEL: vector.body: ; preds = %vector.body, %vector.ph
18 ; FORCED-NEXT: %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
19 ; FORCED-NEXT: %broadcast.splatinsert = insertelement <2 x i32> undef, i32 %index, i32 0
20 ; FORCED-NEXT: %broadcast.splat = shufflevector <2 x i32> %broadcast.splatinsert, <2 x i32> undef, <2 x i32> zeroinitializer
21 ; FORCED-NEXT: %induction = add <2 x i32> %broadcast.splat, <i32 0, i32 1>
22 ; FORCED-NEXT: %0 = add i32 %index, 0
23 ; FORCED-NEXT: %1 = extractvalue { i64, i64 } %sv, 0
24 ; FORCED-NEXT: %2 = extractvalue { i64, i64 } %sv, 0
25 ; FORCED-NEXT: %3 = insertelement <2 x i64> undef, i64 %1, i32 0
26 ; FORCED-NEXT: %4 = insertelement <2 x i64> %3, i64 %2, i32 1
27 ; FORCED-NEXT: %5 = extractvalue { i64, i64 } %sv, 1
28 ; FORCED-NEXT: %6 = extractvalue { i64, i64 } %sv, 1
29 ; FORCED-NEXT: %7 = insertelement <2 x i64> undef, i64 %5, i32 0
30 ; FORCED-NEXT: %8 = insertelement <2 x i64> %7, i64 %6, i32 1
31 ; FORCED-NEXT: %9 = getelementptr i64, i64* %dst, i32 %0
32 ; FORCED-NEXT: %10 = add <2 x i64> %4, %8
33 ; FORCED-NEXT: %11 = getelementptr i64, i64* %9, i32 0
34 ; FORCED-NEXT: %12 = bitcast i64* %11 to <2 x i64>*
35 ; FORCED-NEXT: store <2 x i64> %10, <2 x i64>* %12, align 4
36 ; FORCED-NEXT: %index.next = add i32 %index, 2
37 ; FORCED-NEXT: %13 = icmp eq i32 %index.next, 0
38 ; FORCED-NEXT: br i1 %13, label %middle.block, label %vector.body, !llvm.loop !0
40 define void @test1(i64* %dst, {i64, i64} %sv) {
45 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.body ]
46 %a = extractvalue { i64, i64 } %sv, 0
47 %b = extractvalue { i64, i64 } %sv, 1
48 %addr = getelementptr i64, i64* %dst, i32 %iv
50 store i64 %add, i64* %addr
51 %iv.next = add nsw i32 %iv, 1
52 %cond = icmp ne i32 %iv.next, 0
53 br i1 %cond, label %loop.body, label %exit
60 ; Similar to the test case above, but checks getVectorCallCost as well.
61 declare float @pow(float, float) readnone nounwind
63 ; CM: LV: Scalar loop costs: 16.
64 ; CM: LV: Found an estimated cost of 5 for VF 2 For instruction: %a = extractvalue { float, float } %sv, 0
65 ; CM-NEXT: LV: Found an estimated cost of 5 for VF 2 For instruction: %b = extractvalue { float, float } %sv, 1
67 ; FORCED-LABEL: define void @test_getVectorCallCost
69 ; FORCED-LABEL: vector.body: ; preds = %vector.body, %vector.ph
70 ; FORCED-NEXT: %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
71 ; FORCED-NEXT: %broadcast.splatinsert = insertelement <2 x i32> undef, i32 %index, i32 0
72 ; FORCED-NEXT: %broadcast.splat = shufflevector <2 x i32> %broadcast.splatinsert, <2 x i32> undef, <2 x i32> zeroinitializer
73 ; FORCED-NEXT: %induction = add <2 x i32> %broadcast.splat, <i32 0, i32 1>
74 ; FORCED-NEXT: %0 = add i32 %index, 0
75 ; FORCED-NEXT: %1 = extractvalue { float, float } %sv, 0
76 ; FORCED-NEXT: %2 = extractvalue { float, float } %sv, 0
77 ; FORCED-NEXT: %3 = insertelement <2 x float> undef, float %1, i32 0
78 ; FORCED-NEXT: %4 = insertelement <2 x float> %3, float %2, i32 1
79 ; FORCED-NEXT: %5 = extractvalue { float, float } %sv, 1
80 ; FORCED-NEXT: %6 = extractvalue { float, float } %sv, 1
81 ; FORCED-NEXT: %7 = insertelement <2 x float> undef, float %5, i32 0
82 ; FORCED-NEXT: %8 = insertelement <2 x float> %7, float %6, i32 1
83 ; FORCED-NEXT: %9 = getelementptr float, float* %dst, i32 %0
84 ; FORCED-NEXT: %10 = call <2 x float> @llvm.pow.v2f32(<2 x float> %4, <2 x float> %8)
85 ; FORCED-NEXT: %11 = getelementptr float, float* %9, i32 0
86 ; FORCED-NEXT: %12 = bitcast float* %11 to <2 x float>*
87 ; FORCED-NEXT: store <2 x float> %10, <2 x float>* %12, align 4
88 ; FORCED-NEXT: %index.next = add i32 %index, 2
89 ; FORCED-NEXT: %13 = icmp eq i32 %index.next, 0
90 ; FORCED-NEXT: br i1 %13, label %middle.block, label %vector.body, !llvm.loop !4
92 define void @test_getVectorCallCost(float* %dst, {float, float} %sv) {
97 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.body ]
98 %a = extractvalue { float, float } %sv, 0
99 %b = extractvalue { float, float } %sv, 1
100 %addr = getelementptr float, float* %dst, i32 %iv
101 %p = call float @pow(float %a, float %b)
102 store float %p, float* %addr
103 %iv.next = add nsw i32 %iv, 1
104 %cond = icmp ne i32 %iv.next, 0
105 br i1 %cond, label %loop.body, label %exit