1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -mtriple=aarch64 -passes=loop-vectorize --force-vector-interleave=1 -S | FileCheck %s
4 target triple = "aarch64-unknown-linux-gnu"
6 ; The test checks that scalarized code is not generated for SVE.
7 ; It creates a scenario where the gep instruction is used outside
8 ; the loop, preventing the gep (and consequently the loop induction
9 ; update variable) from being classified as 'uniform'.
11 define void @test_no_scalarization(ptr %a, ptr noalias %b, i32 %idx, i32 %n) #0 {
12 ; CHECK-LABEL: @test_no_scalarization(
13 ; CHECK-NEXT: L.entry:
14 ; CHECK-NEXT: [[TMP0:%.*]] = add nsw i32 [[IDX:%.*]], 1
15 ; CHECK-NEXT: [[SMAX:%.*]] = call i32 @llvm.smax.i32(i32 [[N:%.*]], i32 [[TMP0]])
16 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 [[SMAX]], [[IDX]]
17 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.vscale.i32()
18 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], 2
19 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP1]], [[TMP3]]
20 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
22 ; CHECK-NEXT: [[TMP4:%.*]] = call i32 @llvm.vscale.i32()
23 ; CHECK-NEXT: [[TMP5:%.*]] = mul i32 [[TMP4]], 2
24 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[TMP1]], [[TMP5]]
25 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[TMP1]], [[N_MOD_VF]]
26 ; CHECK-NEXT: [[IND_END:%.*]] = add i32 [[IDX]], [[N_VEC]]
27 ; CHECK-NEXT: [[TMP6:%.*]] = call i32 @llvm.vscale.i32()
28 ; CHECK-NEXT: [[TMP7:%.*]] = mul i32 [[TMP6]], 2
29 ; CHECK-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <vscale x 2 x i32> poison, i32 [[IDX]], i64 0
30 ; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <vscale x 2 x i32> [[DOTSPLATINSERT]], <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer
31 ; CHECK-NEXT: [[TMP8:%.*]] = call <vscale x 2 x i32> @llvm.experimental.stepvector.nxv2i32()
32 ; CHECK-NEXT: [[TMP9:%.*]] = add <vscale x 2 x i32> [[TMP8]], zeroinitializer
33 ; CHECK-NEXT: [[TMP10:%.*]] = mul <vscale x 2 x i32> [[TMP9]], shufflevector (<vscale x 2 x i32> insertelement (<vscale x 2 x i32> poison, i32 1, i64 0), <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer)
34 ; CHECK-NEXT: [[INDUCTION:%.*]] = add <vscale x 2 x i32> [[DOTSPLAT]], [[TMP10]]
35 ; CHECK-NEXT: [[TMP11:%.*]] = call i32 @llvm.vscale.i32()
36 ; CHECK-NEXT: [[TMP12:%.*]] = mul i32 [[TMP11]], 2
37 ; CHECK-NEXT: [[TMP13:%.*]] = mul i32 1, [[TMP12]]
38 ; CHECK-NEXT: [[DOTSPLATINSERT1:%.*]] = insertelement <vscale x 2 x i32> poison, i32 [[TMP13]], i64 0
39 ; CHECK-NEXT: [[DOTSPLAT2:%.*]] = shufflevector <vscale x 2 x i32> [[DOTSPLATINSERT1]], <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer
40 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
42 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
43 ; CHECK-NEXT: [[VEC_IND:%.*]] = phi <vscale x 2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
44 ; CHECK-NEXT: [[OFFSET_IDX:%.*]] = add i32 [[IDX]], [[INDEX]]
45 ; CHECK-NEXT: [[TMP14:%.*]] = add i32 [[OFFSET_IDX]], 0
46 ; CHECK-NEXT: [[TMP15:%.*]] = getelementptr i64, ptr [[A:%.*]], <vscale x 2 x i32> [[VEC_IND]]
47 ; CHECK-NEXT: [[TMP16:%.*]] = extractelement <vscale x 2 x ptr> [[TMP15]], i32 0
48 ; CHECK-NEXT: [[TMP17:%.*]] = getelementptr double, ptr [[TMP16]], i32 0
49 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x double>, ptr [[TMP17]], align 8
50 ; CHECK-NEXT: [[TMP18:%.*]] = getelementptr i64, ptr [[B:%.*]], i32 [[TMP14]]
51 ; CHECK-NEXT: [[TMP19:%.*]] = getelementptr double, ptr [[TMP18]], i32 0
52 ; CHECK-NEXT: store <vscale x 2 x double> [[WIDE_LOAD]], ptr [[TMP19]], align 8
53 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], [[TMP7]]
54 ; CHECK-NEXT: [[VEC_IND_NEXT]] = add <vscale x 2 x i32> [[VEC_IND]], [[DOTSPLAT2]]
55 ; CHECK-NEXT: [[TMP20:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
56 ; CHECK-NEXT: br i1 [[TMP20]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
57 ; CHECK: middle.block:
58 ; CHECK-NEXT: [[TMP21:%.*]] = call i32 @llvm.vscale.i32()
59 ; CHECK-NEXT: [[TMP22:%.*]] = mul i32 [[TMP21]], 2
60 ; CHECK-NEXT: [[TMP23:%.*]] = sub i32 [[TMP22]], 1
61 ; CHECK-NEXT: [[TMP24:%.*]] = extractelement <vscale x 2 x ptr> [[TMP15]], i32 [[TMP23]]
62 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[TMP1]], [[N_VEC]]
63 ; CHECK-NEXT: br i1 [[CMP_N]], label [[L_EXIT:%.*]], label [[SCALAR_PH]]
65 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[IDX]], [[L_ENTRY:%.*]] ]
66 ; CHECK-NEXT: br label [[L_LOOPBODY:%.*]]
68 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i32 [ [[INDVAR_NEXT:%.*]], [[L_LOOPBODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
69 ; CHECK-NEXT: [[INDVAR_NEXT]] = add nsw i32 [[INDVAR]], 1
70 ; CHECK-NEXT: [[TMP25:%.*]] = getelementptr i64, ptr [[A]], i32 [[INDVAR]]
71 ; CHECK-NEXT: [[TMP26:%.*]] = load double, ptr [[TMP25]], align 8
72 ; CHECK-NEXT: [[GEP_B:%.*]] = getelementptr i64, ptr [[B]], i32 [[INDVAR]]
73 ; CHECK-NEXT: store double [[TMP26]], ptr [[GEP_B]], align 8
74 ; CHECK-NEXT: [[TMP27:%.*]] = icmp slt i32 [[INDVAR_NEXT]], [[N]]
75 ; CHECK-NEXT: br i1 [[TMP27]], label [[L_LOOPBODY]], label [[L_EXIT]], !llvm.loop [[LOOP3:![0-9]+]]
77 ; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi ptr [ [[TMP25]], [[L_LOOPBODY]] ], [ [[TMP24]], [[MIDDLE_BLOCK]] ]
78 ; CHECK-NEXT: store i64 1, ptr [[DOTLCSSA]], align 8
79 ; CHECK-NEXT: ret void
84 L.LoopBody: ; preds = %L.LoopBody, %L.entry
85 %indvar = phi i32 [ %indvar.next, %L.LoopBody ], [ %idx, %L.entry ]
86 %indvar.next = add nsw i32 %indvar, 1
87 %0 = getelementptr i64, ptr %a, i32 %indvar
88 %1 = load double, ptr %0, align 8
89 %gep.b = getelementptr i64, ptr %b, i32 %indvar
90 store double %1, ptr %gep.b
91 %2 = icmp slt i32 %indvar.next, %n
92 br i1 %2, label %L.LoopBody, label %L.exit
94 L.exit: ; preds = %L.LoopBody
95 store i64 1, ptr %0, align 8
99 attributes #0 = { nofree norecurse noreturn nosync nounwind "target-features"="+sve" }