1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt -p loop-vectorize -force-vector-width=4 -S %s | FileCheck %s
4 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128-Fn32"
5 target triple = "arm64-apple-macosx14.0.0"
7 ; Test for https://github.com/llvm/llvm-project/issues/109510.
8 define i32 @test_invariant_replicate_region(i32 %x, i1 %c) {
9 ; CHECK-LABEL: define i32 @test_invariant_replicate_region(
10 ; CHECK-SAME: i32 [[X:%.*]], i1 [[C:%.*]]) {
11 ; CHECK-NEXT: [[ENTRY:.*]]:
12 ; CHECK-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
13 ; CHECK: [[VECTOR_PH]]:
14 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i1> poison, i1 [[C]], i64 0
15 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i1> [[BROADCAST_SPLATINSERT]], <4 x i1> poison, <4 x i32> zeroinitializer
16 ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
17 ; CHECK: [[VECTOR_BODY]]:
18 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[PRED_UREM_CONTINUE6:.*]] ]
19 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <4 x i1> [[BROADCAST_SPLAT]], i32 0
20 ; CHECK-NEXT: br i1 [[TMP0]], label %[[PRED_UREM_IF:.*]], label %[[PRED_UREM_CONTINUE:.*]]
21 ; CHECK: [[PRED_UREM_IF]]:
22 ; CHECK-NEXT: [[TMP1:%.*]] = urem i32 10, [[X]]
23 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x i32> poison, i32 [[TMP1]], i32 0
24 ; CHECK-NEXT: br label %[[PRED_UREM_CONTINUE]]
25 ; CHECK: [[PRED_UREM_CONTINUE]]:
26 ; CHECK-NEXT: [[TMP3:%.*]] = phi <4 x i32> [ poison, %[[VECTOR_BODY]] ], [ [[TMP2]], %[[PRED_UREM_IF]] ]
27 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x i1> [[BROADCAST_SPLAT]], i32 1
28 ; CHECK-NEXT: br i1 [[TMP4]], label %[[PRED_UREM_IF1:.*]], label %[[PRED_UREM_CONTINUE2:.*]]
29 ; CHECK: [[PRED_UREM_IF1]]:
30 ; CHECK-NEXT: [[TMP5:%.*]] = urem i32 10, [[X]]
31 ; CHECK-NEXT: [[TMP6:%.*]] = insertelement <4 x i32> [[TMP3]], i32 [[TMP5]], i32 1
32 ; CHECK-NEXT: br label %[[PRED_UREM_CONTINUE2]]
33 ; CHECK: [[PRED_UREM_CONTINUE2]]:
34 ; CHECK-NEXT: [[TMP7:%.*]] = phi <4 x i32> [ [[TMP3]], %[[PRED_UREM_CONTINUE]] ], [ [[TMP6]], %[[PRED_UREM_IF1]] ]
35 ; CHECK-NEXT: [[TMP8:%.*]] = extractelement <4 x i1> [[BROADCAST_SPLAT]], i32 2
36 ; CHECK-NEXT: br i1 [[TMP8]], label %[[PRED_UREM_IF3:.*]], label %[[PRED_UREM_CONTINUE4:.*]]
37 ; CHECK: [[PRED_UREM_IF3]]:
38 ; CHECK-NEXT: [[TMP9:%.*]] = urem i32 10, [[X]]
39 ; CHECK-NEXT: [[TMP10:%.*]] = insertelement <4 x i32> [[TMP7]], i32 [[TMP9]], i32 2
40 ; CHECK-NEXT: br label %[[PRED_UREM_CONTINUE4]]
41 ; CHECK: [[PRED_UREM_CONTINUE4]]:
42 ; CHECK-NEXT: [[TMP11:%.*]] = phi <4 x i32> [ [[TMP7]], %[[PRED_UREM_CONTINUE2]] ], [ [[TMP10]], %[[PRED_UREM_IF3]] ]
43 ; CHECK-NEXT: [[TMP12:%.*]] = extractelement <4 x i1> [[BROADCAST_SPLAT]], i32 3
44 ; CHECK-NEXT: br i1 [[TMP12]], label %[[PRED_UREM_IF5:.*]], label %[[PRED_UREM_CONTINUE6]]
45 ; CHECK: [[PRED_UREM_IF5]]:
46 ; CHECK-NEXT: [[TMP13:%.*]] = urem i32 10, [[X]]
47 ; CHECK-NEXT: [[TMP14:%.*]] = insertelement <4 x i32> [[TMP11]], i32 [[TMP13]], i32 3
48 ; CHECK-NEXT: br label %[[PRED_UREM_CONTINUE6]]
49 ; CHECK: [[PRED_UREM_CONTINUE6]]:
50 ; CHECK-NEXT: [[TMP15:%.*]] = phi <4 x i32> [ [[TMP11]], %[[PRED_UREM_CONTINUE4]] ], [ [[TMP14]], %[[PRED_UREM_IF5]] ]
51 ; CHECK-NEXT: [[PREDPHI:%.*]] = select <4 x i1> [[BROADCAST_SPLAT]], <4 x i32> [[TMP15]], <4 x i32> zeroinitializer
52 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
53 ; CHECK-NEXT: [[TMP16:%.*]] = icmp eq i32 [[INDEX_NEXT]], 100
54 ; CHECK-NEXT: br i1 [[TMP16]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
55 ; CHECK: [[MIDDLE_BLOCK]]:
56 ; CHECK-NEXT: [[TMP17:%.*]] = extractelement <4 x i32> [[PREDPHI]], i32 3
57 ; CHECK-NEXT: br i1 true, label %[[EXIT:.*]], label %[[SCALAR_PH]]
58 ; CHECK: [[SCALAR_PH]]:
59 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ 100, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
60 ; CHECK-NEXT: br label %[[LOOP_HEADER:.*]]
61 ; CHECK: [[LOOP_HEADER]]:
62 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP_LATCH:.*]] ]
63 ; CHECK-NEXT: br i1 [[C]], label %[[THEN:.*]], label %[[LOOP_LATCH]]
65 ; CHECK-NEXT: [[REM_1:%.*]] = urem i32 10, [[X]]
66 ; CHECK-NEXT: br label %[[LOOP_LATCH]]
67 ; CHECK: [[LOOP_LATCH]]:
68 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ 0, %[[LOOP_HEADER]] ], [ [[REM_1]], %[[THEN]] ]
69 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
70 ; CHECK-NEXT: [[EC:%.*]] = icmp eq i32 [[IV]], 99
71 ; CHECK-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP_HEADER]], !llvm.loop [[LOOP3:![0-9]+]]
73 ; CHECK-NEXT: [[RES_LCSSA:%.*]] = phi i32 [ [[RES]], %[[LOOP_LATCH]] ], [ [[TMP17]], %[[MIDDLE_BLOCK]] ]
74 ; CHECK-NEXT: ret i32 [[RES_LCSSA]]
80 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
81 br i1 %c, label %then, label %loop.latch
84 %rem.1 = urem i32 10, %x
88 %res = phi i32 [ 0, %loop.header ], [ %rem.1, %then ]
89 %iv.next = add i32 %iv, 1
90 %ec = icmp eq i32 %iv, 99
91 br i1 %ec, label %exit, label %loop.header
97 ; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]]}
98 ; CHECK: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
99 ; CHECK: [[META2]] = !{!"llvm.loop.unroll.runtime.disable"}
100 ; CHECK: [[LOOP3]] = distinct !{[[LOOP3]], [[META2]], [[META1]]}