3 ; RUN: opt -passes=loop-vectorize -mtriple=arm64-apple-ios %s -S -debug -disable-output 2>&1 | FileCheck --check-prefix=CM %s
4 ; RUN: opt -passes=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: Found uniform instruction: %a = extractvalue { i64, i64 } %sv, 0
12 ; CM: LV: Found uniform instruction: %b = extractvalue { i64, i64 } %sv, 1
14 ; Ensure the extractvalue + add instructions are hoisted out
16 ; CM: CLONE ir<%a> = extractvalue ir<%sv>
17 ; CM: CLONE ir<%b> = extractvalue ir<%sv>
18 ; CM: WIDEN ir<%add> = add ir<%a>, ir<%b>
19 ; CM: Successor(s): vector loop
21 ; CM: LV: Scalar loop costs: 5.
23 ; Check that the extractvalue operands are actually free in vector code.
25 ; FORCED: [[E1:%.+]] = extractvalue { i64, i64 } %sv, 0
26 ; FORCED-NEXT: [[E2:%.+]] = extractvalue { i64, i64 } %sv, 1
27 ; FORCED-NEXT: %broadcast.splatinsert = insertelement <2 x i64> poison, i64 [[E1]], i64 0
28 ; FORCED-NEXT: %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
29 ; FORCED-NEXT: %broadcast.splatinsert1 = insertelement <2 x i64> poison, i64 [[E2]], i64 0
30 ; FORCED-NEXT: %broadcast.splat2 = shufflevector <2 x i64> %broadcast.splatinsert1, <2 x i64> poison, <2 x i32> zeroinitializer
31 ; FORCED-NEXT: [[ADD:%.+]] = add <2 x i64> %broadcast.splat, %broadcast.splat2
33 ; FORCED-LABEL: vector.body: ; preds = %vector.body, %vector.ph
34 ; FORCED-NEXT: %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
35 ; FORCED-NEXT: [[IV_0:%.]] = add i32 %index, 0
36 ; FORCED-NEXT: [[GEP:%.+]] = getelementptr i64, ptr %dst, i32 [[IV_0]]
37 ; FORCED-NEXT: [[GEP2:%.+]] = getelementptr i64, ptr [[GEP]], i32 0
38 ; FORCED-NEXT: store <2 x i64> [[ADD]], ptr [[GEP2]], align 4
39 ; FORCED-NEXT: %index.next = add nuw i32 %index, 2
40 ; FORCED-NEXT: [[C:%.+]] = icmp eq i32 %index.next, 1000
41 ; FORCED-NEXT: br i1 [[C]], label %middle.block, label %vector.body
43 define void @test1(ptr %dst, {i64, i64} %sv) {
48 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.body ]
49 %a = extractvalue { i64, i64 } %sv, 0
50 %b = extractvalue { i64, i64 } %sv, 1
51 %addr = getelementptr i64, ptr %dst, i32 %iv
53 store i64 %add, ptr %addr
54 %iv.next = add nsw i32 %iv, 1
55 %cond = icmp ne i32 %iv.next, 1000
56 br i1 %cond, label %loop.body, label %exit
63 ; Similar to the test case above, but checks getVectorCallCost as well.
64 declare float @powf(float, float) readnone nounwind
66 ; Ensure the extractvalue + add instructions are hoisted out
68 ; CM: CLONE ir<%a> = extractvalue ir<%sv>
69 ; CM: CLONE ir<%b> = extractvalue ir<%sv>
70 ; CM: WIDEN ir<%add> = add ir<%a>, ir<%b>
71 ; CM: Successor(s): vector loop
73 ; CM: LV: Scalar loop costs: 14.
75 ; FORCED-LABEL: define void @test_getVectorCallCost
77 ; FORCED: [[E1:%.+]] = extractvalue { float, float } %sv, 0
78 ; FORCED-NEXT: [[E2:%.+]] = extractvalue { float, float } %sv, 1
79 ; FORCED-NEXT: %broadcast.splatinsert = insertelement <2 x float> poison, float [[E1]], i64 0
80 ; FORCED-NEXT: %broadcast.splat = shufflevector <2 x float> %broadcast.splatinsert, <2 x float> poison, <2 x i32> zeroinitializer
81 ; FORCED-NEXT: %broadcast.splatinsert1 = insertelement <2 x float> poison, float [[E2]], i64 0
82 ; FORCED-NEXT: %broadcast.splat2 = shufflevector <2 x float> %broadcast.splatinsert1, <2 x float> poison, <2 x i32> zeroinitializer
84 ; FORCED-LABEL: vector.body: ; preds = %vector.body, %vector.ph
85 ; FORCED-NEXT: %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
86 ; FORCED-NEXT: [[IV0:%.+]] = add i32 %index, 0
87 ; FORCED-NEXT: [[GEP1:%.+]] = getelementptr float, ptr %dst, i32 [[IV0]]
88 ; FORCED-NEXT: [[POW:%.+]] = call <2 x float> @llvm.pow.v2f32(<2 x float> %broadcast.splat, <2 x float> %broadcast.splat2)
89 ; FORCED-NEXT: [[GEP2:%.+]] = getelementptr float, ptr [[GEP1]], i32 0
90 ; FORCED-NEXT: store <2 x float> [[POW]], ptr [[GEP2]], align 4
91 ; FORCED-NEXT: %index.next = add nuw i32 %index, 2
92 ; FORCED-NEXT: [[C:%.+]] = icmp eq i32 %index.next, 1000
93 ; FORCED-NEXT: br i1 [[C]], label %middle.block, label %vector.body
95 define void @test_getVectorCallCost(ptr %dst, {float, float} %sv) {
100 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.body ]
101 %a = extractvalue { float, float } %sv, 0
102 %b = extractvalue { float, float } %sv, 1
103 %addr = getelementptr float, ptr %dst, i32 %iv
104 %p = call float @powf(float %a, float %b)
105 store float %p, ptr %addr
106 %iv.next = add nsw i32 %iv, 1
107 %cond = icmp ne i32 %iv.next, 1000
108 br i1 %cond, label %loop.body, label %exit