1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-vectorize -force-vector-width=2 -S -prefer-predicate-over-epilogue=predicate-dont-vectorize %s | FileCheck %s
5 ; Test case for PR46525. There are two candidates to pick for
6 ; `udiv i64 %y, %add` when expanding SCEV expressions. Make sure we pick %div,
7 ; which dominates the vector loop.
9 define void @test(i16 %x, i64 %y, ptr %ptr) {
12 ; CHECK-NEXT: [[CONV19:%.*]] = sext i16 [[X:%.*]] to i64
13 ; CHECK-NEXT: [[ADD:%.*]] = add i64 [[CONV19]], 492802768830814067
14 ; CHECK-NEXT: br label [[LOOP_PREHEADER:%.*]]
15 ; CHECK: loop.preheader:
16 ; CHECK-NEXT: [[DIV:%.*]] = udiv i64 [[Y:%.*]], [[ADD]]
17 ; CHECK-NEXT: [[INC:%.*]] = add i64 [[DIV]], 1
18 ; CHECK-NEXT: [[TMP0:%.*]] = add nuw nsw i64 [[DIV]], 4
19 ; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 [[TMP0]], [[INC]]
20 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
21 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
23 ; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[TMP2]], 1
24 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], 2
25 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
26 ; CHECK-NEXT: [[IND_END:%.*]] = mul i64 [[N_VEC]], [[INC]]
27 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
29 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
30 ; CHECK-NEXT: store i32 0, ptr [[PTR:%.*]], align 4
31 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
32 ; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
33 ; CHECK-NEXT: br i1 [[TMP3]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
34 ; CHECK: middle.block:
35 ; CHECK-NEXT: br i1 true, label [[LOOP_EXIT:%.*]], label [[SCALAR_PH]]
37 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_PREHEADER]] ]
38 ; CHECK-NEXT: br label [[LOOP:%.*]]
40 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
41 ; CHECK-NEXT: store i32 0, ptr [[PTR]], align 4
42 ; CHECK-NEXT: [[V2:%.*]] = trunc i64 [[IV]] to i8
43 ; CHECK-NEXT: [[V3:%.*]] = add i8 [[V2]], 1
44 ; CHECK-NEXT: [[CMP15:%.*]] = icmp slt i8 [[V3]], 5
45 ; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], [[INC]]
46 ; CHECK-NEXT: br i1 [[CMP15]], label [[LOOP]], label [[LOOP_EXIT]], !llvm.loop [[LOOP3:![0-9]+]]
48 ; CHECK-NEXT: [[DIV_1:%.*]] = udiv i64 [[Y]], [[ADD]]
49 ; CHECK-NEXT: [[V1:%.*]] = add i64 [[DIV_1]], 1
50 ; CHECK-NEXT: br label [[LOOP_2:%.*]]
52 ; CHECK-NEXT: [[IV_1:%.*]] = phi i64 [ [[IV_NEXT_1:%.*]], [[LOOP_2]] ], [ 0, [[LOOP_EXIT]] ]
53 ; CHECK-NEXT: [[IV_NEXT_1]] = add i64 [[IV_1]], [[V1]]
54 ; CHECK-NEXT: call void @use(i64 [[IV_NEXT_1]])
55 ; CHECK-NEXT: [[EC:%.*]] = icmp ult i64 [[IV_NEXT_1]], 200
56 ; CHECK-NEXT: br i1 [[EC]], label [[LOOP_2]], label [[LOOP_2_EXIT:%.*]]
58 ; CHECK-NEXT: [[C:%.*]] = call i1 @cond()
59 ; CHECK-NEXT: br i1 [[C]], label [[LOOP_PREHEADER]], label [[EXIT:%.*]]
61 ; CHECK-NEXT: ret void
64 %conv19 = sext i16 %x to i64
65 %add = add i64 %conv19, 492802768830814067
66 br label %loop.preheader
69 %div = udiv i64 %y, %add
70 %inc = add i64 %div, 1
74 %iv = phi i64 [ %iv.next, %loop ], [ 0, %loop.preheader ]
75 store i32 0, ptr %ptr, align 4
76 %v2 = trunc i64 %iv to i8
78 %cmp15 = icmp slt i8 %v3, 5
79 %iv.next = add i64 %iv, %inc
80 br i1 %cmp15, label %loop, label %loop.exit
83 %div.1 = udiv i64 %y, %add
84 %v1 = add i64 %div.1, 1
88 %iv.1 = phi i64 [ %iv.next.1, %loop.2 ], [ 0, %loop.exit ]
89 %iv.next.1 = add i64 %iv.1, %v1
90 call void @use(i64 %iv.next.1)
91 %ec = icmp ult i64 %iv.next.1, 200
92 br i1 %ec, label %loop.2, label %loop.2.exit
96 br i1 %c, label %loop.preheader, label %exit
102 declare void @use(i64)