1eb052f6bSPhilip Reames; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2cee313d2SEric Christopher; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=2 -S | FileCheck %s
3cee313d2SEric Christopher; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=2 -instcombine -S | FileCheck %s --check-prefix=IND
4cee313d2SEric Christopher; RUN: opt < %s -loop-vectorize -force-vector-interleave=2 -force-vector-width=2 -instcombine -S | FileCheck %s --check-prefix=UNROLL
5cee313d2SEric Christopher; RUN: opt < %s -loop-vectorize -force-vector-interleave=2 -force-vector-width=2 -S | FileCheck %s --check-prefix=UNROLL-NO-IC
6cee313d2SEric Christopher; RUN: opt < %s -loop-vectorize -force-vector-interleave=2 -force-vector-width=4 -enable-interleaved-mem-accesses -instcombine -S | FileCheck %s --check-prefix=INTERLEAVE
7cee313d2SEric Christopher
8cee313d2SEric Christophertarget datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
9cee313d2SEric Christopher
10cee313d2SEric Christopher; Make sure that we can handle multiple integer induction variables.
11cee313d2SEric Christopher;
12eb052f6bSPhilip Reamesdefine void @multi_int_induction(i32* %A, i32 %N) {
13cee313d2SEric Christopher; CHECK-LABEL: @multi_int_induction(
14eb052f6bSPhilip Reames; CHECK-NEXT:  for.body.lr.ph:
15eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
16eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
17eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
18eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], 2
19eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
20eb052f6bSPhilip Reames; CHECK:       vector.ph:
21eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 2
22eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
230c00dbb9SNikita Popov; CHECK-NEXT:    [[CAST_VTC:%.*]] = trunc i64 [[N_VEC]] to i32
240c00dbb9SNikita Popov; CHECK-NEXT:    [[IND_END:%.*]] = add i32 190, [[CAST_VTC]]
25eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
26cee313d2SEric Christopher; CHECK:       vector.body:
27eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
28eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 190, i32 191>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
29eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = add i64 [[INDEX]], 0
30eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP3]]
31cee313d2SEric Christopher; CHECK-NEXT:    [[TMP5:%.*]] = getelementptr inbounds i32, i32* [[TMP4]], i32 0
32cee313d2SEric Christopher; CHECK-NEXT:    [[TMP6:%.*]] = bitcast i32* [[TMP5]] to <2 x i32>*
33eb052f6bSPhilip Reames; CHECK-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP6]], align 4
34eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
35eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
36eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
37eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP7]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
38eb052f6bSPhilip Reames; CHECK:       middle.block:
39eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
40eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
41eb052f6bSPhilip Reames; CHECK:       scalar.ph:
42eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_LR_PH:%.*]] ]
43eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 190, [[FOR_BODY_LR_PH]] ]
44eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
45eb052f6bSPhilip Reames; CHECK:       for.body:
46eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
47eb052f6bSPhilip Reames; CHECK-NEXT:    [[COUNT_09:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
48eb052f6bSPhilip Reames; CHECK-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[INDVARS_IV]]
49eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[COUNT_09]], i32* [[ARRAYIDX2]], align 4
50eb052f6bSPhilip Reames; CHECK-NEXT:    [[INC]] = add nsw i32 [[COUNT_09]], 1
51eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1
52eb052f6bSPhilip Reames; CHECK-NEXT:    [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
53eb052f6bSPhilip Reames; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp ne i32 [[LFTR_WIDEIV]], [[N]]
54eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP2:![0-9]+]]
55eb052f6bSPhilip Reames; CHECK:       for.end:
56eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
57eb052f6bSPhilip Reames;
58eb052f6bSPhilip Reames; IND-LABEL: @multi_int_induction(
59eb052f6bSPhilip Reames; IND-NEXT:  for.body.lr.ph:
60eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
61eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
62eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
63eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp eq i32 [[TMP0]], 0
64eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
65eb052f6bSPhilip Reames; IND:       vector.ph:
66eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i64 [[TMP2]], 8589934590
670c00dbb9SNikita Popov; IND-NEXT:    [[CAST_VTC:%.*]] = trunc i64 [[N_VEC]] to i32
680c00dbb9SNikita Popov; IND-NEXT:    [[IND_END:%.*]] = add i32 [[CAST_VTC]], 190
69eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
70eb052f6bSPhilip Reames; IND:       vector.body:
71eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
72eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 190, i32 191>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
73eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[INDEX]]
74eb052f6bSPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = bitcast i32* [[TMP3]] to <2 x i32>*
75eb052f6bSPhilip Reames; IND-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP4]], align 4
76eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
77eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
78eb052f6bSPhilip Reames; IND-NEXT:    [[TMP5:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
79eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
80eb052f6bSPhilip Reames; IND:       middle.block:
81eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
82eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
83eb052f6bSPhilip Reames; IND:       scalar.ph:
84eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_LR_PH:%.*]] ]
85eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 190, [[FOR_BODY_LR_PH]] ]
86eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
87eb052f6bSPhilip Reames; IND:       for.body:
88eb052f6bSPhilip Reames; IND-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
89eb052f6bSPhilip Reames; IND-NEXT:    [[COUNT_09:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
90eb052f6bSPhilip Reames; IND-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[INDVARS_IV]]
91eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[COUNT_09]], i32* [[ARRAYIDX2]], align 4
92eb052f6bSPhilip Reames; IND-NEXT:    [[INC]] = add nsw i32 [[COUNT_09]], 1
93eb052f6bSPhilip Reames; IND-NEXT:    [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1
94eb052f6bSPhilip Reames; IND-NEXT:    [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
95eb052f6bSPhilip Reames; IND-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i32 [[LFTR_WIDEIV]], [[N]]
96eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP2:![0-9]+]]
97eb052f6bSPhilip Reames; IND:       for.end:
98eb052f6bSPhilip Reames; IND-NEXT:    ret void
99eb052f6bSPhilip Reames;
100eb052f6bSPhilip Reames; UNROLL-LABEL: @multi_int_induction(
101eb052f6bSPhilip Reames; UNROLL-NEXT:  for.body.lr.ph:
102eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
103eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
104eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
105eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 3
106eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
107eb052f6bSPhilip Reames; UNROLL:       vector.ph:
108eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i64 [[TMP2]], 8589934588
1090c00dbb9SNikita Popov; UNROLL-NEXT:    [[CAST_VTC:%.*]] = trunc i64 [[N_VEC]] to i32
1100c00dbb9SNikita Popov; UNROLL-NEXT:    [[IND_END:%.*]] = add i32 [[CAST_VTC]], 190
111eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
112eb052f6bSPhilip Reames; UNROLL:       vector.body:
113eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
114eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 190, i32 191>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
115eb052f6bSPhilip Reames; UNROLL-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
116eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[INDEX]]
117eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = bitcast i32* [[TMP3]] to <2 x i32>*
118eb052f6bSPhilip Reames; UNROLL-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP4]], align 4
119eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = getelementptr inbounds i32, i32* [[TMP3]], i64 2
120eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP6:%.*]] = bitcast i32* [[TMP5]] to <2 x i32>*
121eb052f6bSPhilip Reames; UNROLL-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP6]], align 4
122eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
123eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 4, i32 4>
124eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
125eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP7]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
126eb052f6bSPhilip Reames; UNROLL:       middle.block:
127eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
128eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
129eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
130eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_LR_PH:%.*]] ]
131eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 190, [[FOR_BODY_LR_PH]] ]
132eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
133eb052f6bSPhilip Reames; UNROLL:       for.body:
134eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
135eb052f6bSPhilip Reames; UNROLL-NEXT:    [[COUNT_09:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
136eb052f6bSPhilip Reames; UNROLL-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[INDVARS_IV]]
137eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[COUNT_09]], i32* [[ARRAYIDX2]], align 4
138eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INC]] = add nsw i32 [[COUNT_09]], 1
139eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1
140eb052f6bSPhilip Reames; UNROLL-NEXT:    [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
141eb052f6bSPhilip Reames; UNROLL-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i32 [[LFTR_WIDEIV]], [[N]]
142eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP2:![0-9]+]]
143eb052f6bSPhilip Reames; UNROLL:       for.end:
144eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
145eb052f6bSPhilip Reames;
146eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @multi_int_induction(
147eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  for.body.lr.ph:
148eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
149eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
150eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
151eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], 4
152eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
153eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
154eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 4
155eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
1560c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[CAST_VTC:%.*]] = trunc i64 [[N_VEC]] to i32
1570c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[IND_END:%.*]] = add i32 190, [[CAST_VTC]]
158eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
159eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
160eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
161eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 190, i32 191>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
162b3e8ace1SFlorian Hahn; UNROLL-NO-IC-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
163eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = add i64 [[INDEX]], 0
164eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = add i64 [[INDEX]], 2
165eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP3]]
166eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP4]]
167eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i32, i32* [[TMP5]], i32 0
168eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = bitcast i32* [[TMP7]] to <2 x i32>*
169eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP8]], align 4
170eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = getelementptr inbounds i32, i32* [[TMP5]], i32 2
171eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = bitcast i32* [[TMP9]] to <2 x i32>*
172eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP10]], align 4
173eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
174eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[STEP_ADD]], <i32 2, i32 2>
175eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
176eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP11]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
177eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
178eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
179eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
180eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
181eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_LR_PH:%.*]] ]
182eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 190, [[FOR_BODY_LR_PH]] ]
183eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
184eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
185eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
186eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[COUNT_09:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
187eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[INDVARS_IV]]
188eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[COUNT_09]], i32* [[ARRAYIDX2]], align 4
189eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INC]] = add nsw i32 [[COUNT_09]], 1
190eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1
191eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
192eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[EXITCOND:%.*]] = icmp ne i32 [[LFTR_WIDEIV]], [[N]]
193eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP2:![0-9]+]]
194eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.end:
195eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
196eb052f6bSPhilip Reames;
197eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @multi_int_induction(
198eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  for.body.lr.ph:
199eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
200eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
201eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
202eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 7
203eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
204eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
205eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i64 [[TMP2]], 8589934584
2060c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[CAST_VTC:%.*]] = trunc i64 [[N_VEC]] to i32
2070c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[IND_END:%.*]] = add i32 [[CAST_VTC]], 190
208eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
209eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
210eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
211eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 190, i32 191, i32 192, i32 193>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
212eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[STEP_ADD:%.*]] = add <4 x i32> [[VEC_IND]], <i32 4, i32 4, i32 4, i32 4>
213eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[INDEX]]
214eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = bitcast i32* [[TMP3]] to <4 x i32>*
215eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store <4 x i32> [[VEC_IND]], <4 x i32>* [[TMP4]], align 4
216eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = getelementptr inbounds i32, i32* [[TMP3]], i64 4
217eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = bitcast i32* [[TMP5]] to <4 x i32>*
218eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store <4 x i32> [[STEP_ADD]], <4 x i32>* [[TMP6]], align 4
219eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
220eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_IND_NEXT]] = add <4 x i32> [[VEC_IND]], <i32 8, i32 8, i32 8, i32 8>
221eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
222eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP7]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
223eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
224eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
225eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
226eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
227eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_LR_PH:%.*]] ]
228eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 190, [[FOR_BODY_LR_PH]] ]
229eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
230eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
231eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
232eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[COUNT_09:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
233eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[INDVARS_IV]]
234eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[COUNT_09]], i32* [[ARRAYIDX2]], align 4
235eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INC]] = add nsw i32 [[COUNT_09]], 1
236eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1
237eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
238eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i32 [[LFTR_WIDEIV]], [[N]]
239eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP2:![0-9]+]]
240eb052f6bSPhilip Reames; INTERLEAVE:       for.end:
241eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
242eb052f6bSPhilip Reames;
243cee313d2SEric Christopherfor.body.lr.ph:
244cee313d2SEric Christopher  br label %for.body
245cee313d2SEric Christopher
246cee313d2SEric Christopherfor.body:
247cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]
248cee313d2SEric Christopher  %count.09 = phi i32 [ 190, %for.body.lr.ph ], [ %inc, %for.body ]
249cee313d2SEric Christopher  %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
250cee313d2SEric Christopher  store i32 %count.09, i32* %arrayidx2, align 4
251cee313d2SEric Christopher  %inc = add nsw i32 %count.09, 1
252cee313d2SEric Christopher  %indvars.iv.next = add i64 %indvars.iv, 1
253cee313d2SEric Christopher  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
254cee313d2SEric Christopher  %exitcond = icmp ne i32 %lftr.wideiv, %N
255cee313d2SEric Christopher  br i1 %exitcond, label %for.body, label %for.end
256cee313d2SEric Christopher
257cee313d2SEric Christopherfor.end:
258cee313d2SEric Christopher  ret void
259cee313d2SEric Christopher}
260cee313d2SEric Christopher
261cee313d2SEric Christopher; Make sure we remove unneeded vectorization of induction variables.
262cee313d2SEric Christopher; In order for instcombine to cleanup the vectorized induction variables that we
263cee313d2SEric Christopher; create in the loop vectorizer we need to perform some form of redundancy
264cee313d2SEric Christopher; elimination to get rid of multiple uses.
265cee313d2SEric Christopher
266cee313d2SEric Christopher
267cee313d2SEric Christopher;   Vectorized induction variable.
268cee313d2SEric Christopher
269cee313d2SEric Christopherdefine void @scalar_use(float* %a, float %b, i64 %offset, i64 %offset2, i64 %n) {
270eb052f6bSPhilip Reames; CHECK-LABEL: @scalar_use(
271eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
272eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N:%.*]], 2
273eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
274eb052f6bSPhilip Reames; CHECK:       vector.memcheck:
275eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr float, float* [[A:%.*]], i64 [[OFFSET:%.*]]
276eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP1:%.*]] = bitcast float* [[SCEVGEP]] to i8*
277eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i64 [[N]], [[OFFSET]]
278eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP2:%.*]] = getelementptr float, float* [[A]], i64 [[TMP0]]
279eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP23:%.*]] = bitcast float* [[SCEVGEP2]] to i8*
280eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP4:%.*]] = getelementptr float, float* [[A]], i64 [[OFFSET2:%.*]]
281eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP45:%.*]] = bitcast float* [[SCEVGEP4]] to i8*
282eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[N]], [[OFFSET2]]
283eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP6:%.*]] = getelementptr float, float* [[A]], i64 [[TMP1]]
284eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP67:%.*]] = bitcast float* [[SCEVGEP6]] to i8*
285eb052f6bSPhilip Reames; CHECK-NEXT:    [[BOUND0:%.*]] = icmp ult i8* [[SCEVGEP1]], [[SCEVGEP67]]
286eb052f6bSPhilip Reames; CHECK-NEXT:    [[BOUND1:%.*]] = icmp ult i8* [[SCEVGEP45]], [[SCEVGEP23]]
287eb052f6bSPhilip Reames; CHECK-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
288eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
289eb052f6bSPhilip Reames; CHECK:       vector.ph:
290eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[N]], 2
291eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[N]], [[N_MOD_VF]]
292eb052f6bSPhilip Reames; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x float> poison, float [[B:%.*]], i32 0
293eb052f6bSPhilip Reames; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x float> [[BROADCAST_SPLATINSERT]], <2 x float> poison, <2 x i32> zeroinitializer
294eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
295eb052f6bSPhilip Reames; CHECK:       vector.body:
296eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
297eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = add i64 [[INDEX]], 0
298eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = add i64 [[TMP2]], [[OFFSET]]
299eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP3]]
300eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP5:%.*]] = getelementptr inbounds float, float* [[TMP4]], i32 0
301eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP6:%.*]] = bitcast float* [[TMP5]] to <2 x float>*
302eb052f6bSPhilip Reames; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x float>, <2 x float>* [[TMP6]], align 4, !alias.scope !4, !noalias !7
303eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP7:%.*]] = add i64 [[TMP2]], [[OFFSET2]]
304eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP7]]
305eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP9:%.*]] = getelementptr inbounds float, float* [[TMP8]], i32 0
306eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP10:%.*]] = bitcast float* [[TMP9]] to <2 x float>*
307eb052f6bSPhilip Reames; CHECK-NEXT:    [[WIDE_LOAD8:%.*]] = load <2 x float>, <2 x float>* [[TMP10]], align 4, !alias.scope !7
308eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP11:%.*]] = fmul fast <2 x float> [[BROADCAST_SPLAT]], [[WIDE_LOAD8]]
309eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP12:%.*]] = fadd fast <2 x float> [[WIDE_LOAD]], [[TMP11]]
310eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP13:%.*]] = bitcast float* [[TMP5]] to <2 x float>*
311eb052f6bSPhilip Reames; CHECK-NEXT:    store <2 x float> [[TMP12]], <2 x float>* [[TMP13]], align 4, !alias.scope !4, !noalias !7
312eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
313eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP14:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
314eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP14]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
315eb052f6bSPhilip Reames; CHECK:       middle.block:
316eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]]
317eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
318eb052f6bSPhilip Reames; CHECK:       scalar.ph:
319eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
320eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
321eb052f6bSPhilip Reames; CHECK:       for.body:
322eb052f6bSPhilip Reames; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
323eb052f6bSPhilip Reames; CHECK-NEXT:    [[IND_SUM:%.*]] = add i64 [[IV]], [[OFFSET]]
324eb052f6bSPhilip Reames; CHECK-NEXT:    [[ARR_IDX:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[IND_SUM]]
325eb052f6bSPhilip Reames; CHECK-NEXT:    [[L1:%.*]] = load float, float* [[ARR_IDX]], align 4
326eb052f6bSPhilip Reames; CHECK-NEXT:    [[IND_SUM2:%.*]] = add i64 [[IV]], [[OFFSET2]]
327eb052f6bSPhilip Reames; CHECK-NEXT:    [[ARR_IDX2:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[IND_SUM2]]
328eb052f6bSPhilip Reames; CHECK-NEXT:    [[L2:%.*]] = load float, float* [[ARR_IDX2]], align 4
329eb052f6bSPhilip Reames; CHECK-NEXT:    [[M:%.*]] = fmul fast float [[B]], [[L2]]
330eb052f6bSPhilip Reames; CHECK-NEXT:    [[AD:%.*]] = fadd fast float [[L1]], [[M]]
331eb052f6bSPhilip Reames; CHECK-NEXT:    store float [[AD]], float* [[ARR_IDX]], align 4
332eb052f6bSPhilip Reames; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
333eb052f6bSPhilip Reames; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
334eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]
335eb052f6bSPhilip Reames; CHECK:       loopexit:
336eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
337eb052f6bSPhilip Reames;
338eb052f6bSPhilip Reames; IND-LABEL: @scalar_use(
339eb052f6bSPhilip Reames; IND-NEXT:  entry:
340eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N:%.*]], 2
341eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
342eb052f6bSPhilip Reames; IND:       vector.memcheck:
343eb052f6bSPhilip Reames; IND-NEXT:    [[SCEVGEP:%.*]] = getelementptr float, float* [[A:%.*]], i64 [[OFFSET:%.*]]
344eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = add i64 [[N]], [[OFFSET]]
345eb052f6bSPhilip Reames; IND-NEXT:    [[SCEVGEP2:%.*]] = getelementptr float, float* [[A]], i64 [[TMP0]]
346eb052f6bSPhilip Reames; IND-NEXT:    [[SCEVGEP4:%.*]] = getelementptr float, float* [[A]], i64 [[OFFSET2:%.*]]
347eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = add i64 [[N]], [[OFFSET2]]
348eb052f6bSPhilip Reames; IND-NEXT:    [[SCEVGEP6:%.*]] = getelementptr float, float* [[A]], i64 [[TMP1]]
349eb052f6bSPhilip Reames; IND-NEXT:    [[BOUND0:%.*]] = icmp ult float* [[SCEVGEP]], [[SCEVGEP6]]
350eb052f6bSPhilip Reames; IND-NEXT:    [[BOUND1:%.*]] = icmp ult float* [[SCEVGEP4]], [[SCEVGEP2]]
351eb052f6bSPhilip Reames; IND-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
352eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
353eb052f6bSPhilip Reames; IND:       vector.ph:
354eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i64 [[N]], -2
355e6ad9ef4SPhilip Reames; IND-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x float> poison, float [[B:%.*]], i64 0
356eb052f6bSPhilip Reames; IND-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x float> [[BROADCAST_SPLATINSERT]], <2 x float> poison, <2 x i32> zeroinitializer
357eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
358eb052f6bSPhilip Reames; IND:       vector.body:
359eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
360eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = add i64 [[INDEX]], [[OFFSET]]
361eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP2]]
362eb052f6bSPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = bitcast float* [[TMP3]] to <2 x float>*
363eb052f6bSPhilip Reames; IND-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x float>, <2 x float>* [[TMP4]], align 4, !alias.scope !4, !noalias !7
364eb052f6bSPhilip Reames; IND-NEXT:    [[TMP5:%.*]] = add i64 [[INDEX]], [[OFFSET2]]
365eb052f6bSPhilip Reames; IND-NEXT:    [[TMP6:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP5]]
366eb052f6bSPhilip Reames; IND-NEXT:    [[TMP7:%.*]] = bitcast float* [[TMP6]] to <2 x float>*
367eb052f6bSPhilip Reames; IND-NEXT:    [[WIDE_LOAD8:%.*]] = load <2 x float>, <2 x float>* [[TMP7]], align 4, !alias.scope !7
368eb052f6bSPhilip Reames; IND-NEXT:    [[TMP8:%.*]] = fmul fast <2 x float> [[BROADCAST_SPLAT]], [[WIDE_LOAD8]]
369eb052f6bSPhilip Reames; IND-NEXT:    [[TMP9:%.*]] = fadd fast <2 x float> [[WIDE_LOAD]], [[TMP8]]
370eb052f6bSPhilip Reames; IND-NEXT:    [[TMP10:%.*]] = bitcast float* [[TMP3]] to <2 x float>*
371eb052f6bSPhilip Reames; IND-NEXT:    store <2 x float> [[TMP9]], <2 x float>* [[TMP10]], align 4, !alias.scope !4, !noalias !7
372eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
373eb052f6bSPhilip Reames; IND-NEXT:    [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
374eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP11]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
375eb052f6bSPhilip Reames; IND:       middle.block:
376eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[N]]
377eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
378eb052f6bSPhilip Reames; IND:       scalar.ph:
379eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
380eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
381eb052f6bSPhilip Reames; IND:       for.body:
382eb052f6bSPhilip Reames; IND-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
383eb052f6bSPhilip Reames; IND-NEXT:    [[IND_SUM:%.*]] = add i64 [[IV]], [[OFFSET]]
384eb052f6bSPhilip Reames; IND-NEXT:    [[ARR_IDX:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[IND_SUM]]
385eb052f6bSPhilip Reames; IND-NEXT:    [[L1:%.*]] = load float, float* [[ARR_IDX]], align 4
386eb052f6bSPhilip Reames; IND-NEXT:    [[IND_SUM2:%.*]] = add i64 [[IV]], [[OFFSET2]]
387eb052f6bSPhilip Reames; IND-NEXT:    [[ARR_IDX2:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[IND_SUM2]]
388eb052f6bSPhilip Reames; IND-NEXT:    [[L2:%.*]] = load float, float* [[ARR_IDX2]], align 4
389eb052f6bSPhilip Reames; IND-NEXT:    [[M:%.*]] = fmul fast float [[L2]], [[B]]
390eb052f6bSPhilip Reames; IND-NEXT:    [[AD:%.*]] = fadd fast float [[L1]], [[M]]
391eb052f6bSPhilip Reames; IND-NEXT:    store float [[AD]], float* [[ARR_IDX]], align 4
392eb052f6bSPhilip Reames; IND-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
393eb052f6bSPhilip Reames; IND-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
394eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]
395eb052f6bSPhilip Reames; IND:       loopexit:
396eb052f6bSPhilip Reames; IND-NEXT:    ret void
397eb052f6bSPhilip Reames;
398eb052f6bSPhilip Reames; UNROLL-LABEL: @scalar_use(
399eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
400eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N:%.*]], 4
401eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
402eb052f6bSPhilip Reames; UNROLL:       vector.memcheck:
403eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SCEVGEP:%.*]] = getelementptr float, float* [[A:%.*]], i64 [[OFFSET:%.*]]
404eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = add i64 [[N]], [[OFFSET]]
405eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SCEVGEP2:%.*]] = getelementptr float, float* [[A]], i64 [[TMP0]]
406eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SCEVGEP4:%.*]] = getelementptr float, float* [[A]], i64 [[OFFSET2:%.*]]
407eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = add i64 [[N]], [[OFFSET2]]
408eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SCEVGEP6:%.*]] = getelementptr float, float* [[A]], i64 [[TMP1]]
409eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BOUND0:%.*]] = icmp ult float* [[SCEVGEP]], [[SCEVGEP6]]
410eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BOUND1:%.*]] = icmp ult float* [[SCEVGEP4]], [[SCEVGEP2]]
411eb052f6bSPhilip Reames; UNROLL-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
412eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
413eb052f6bSPhilip Reames; UNROLL:       vector.ph:
414eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i64 [[N]], -4
415e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x float> poison, float [[B:%.*]], i64 0
416eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x float> [[BROADCAST_SPLATINSERT]], <2 x float> poison, <2 x i32> zeroinitializer
417e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLATINSERT11:%.*]] = insertelement <2 x float> poison, float [[B]], i64 0
418eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLAT12:%.*]] = shufflevector <2 x float> [[BROADCAST_SPLATINSERT11]], <2 x float> poison, <2 x i32> zeroinitializer
419eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
420eb052f6bSPhilip Reames; UNROLL:       vector.body:
421eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
422eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = add i64 [[INDEX]], [[OFFSET]]
423eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP2]]
424eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = bitcast float* [[TMP3]] to <2 x float>*
425eb052f6bSPhilip Reames; UNROLL-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x float>, <2 x float>* [[TMP4]], align 4, !alias.scope !4, !noalias !7
426eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = getelementptr inbounds float, float* [[TMP3]], i64 2
427eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP6:%.*]] = bitcast float* [[TMP5]] to <2 x float>*
428eb052f6bSPhilip Reames; UNROLL-NEXT:    [[WIDE_LOAD8:%.*]] = load <2 x float>, <2 x float>* [[TMP6]], align 4, !alias.scope !4, !noalias !7
429eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP7:%.*]] = add i64 [[INDEX]], [[OFFSET2]]
430eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP8:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP7]]
431eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP9:%.*]] = bitcast float* [[TMP8]] to <2 x float>*
432eb052f6bSPhilip Reames; UNROLL-NEXT:    [[WIDE_LOAD9:%.*]] = load <2 x float>, <2 x float>* [[TMP9]], align 4, !alias.scope !7
433eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP10:%.*]] = getelementptr inbounds float, float* [[TMP8]], i64 2
434eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP11:%.*]] = bitcast float* [[TMP10]] to <2 x float>*
435eb052f6bSPhilip Reames; UNROLL-NEXT:    [[WIDE_LOAD10:%.*]] = load <2 x float>, <2 x float>* [[TMP11]], align 4, !alias.scope !7
436eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP12:%.*]] = fmul fast <2 x float> [[BROADCAST_SPLAT]], [[WIDE_LOAD9]]
437eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP13:%.*]] = fmul fast <2 x float> [[BROADCAST_SPLAT12]], [[WIDE_LOAD10]]
438eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP14:%.*]] = fadd fast <2 x float> [[WIDE_LOAD]], [[TMP12]]
439eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP15:%.*]] = fadd fast <2 x float> [[WIDE_LOAD8]], [[TMP13]]
440eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP16:%.*]] = bitcast float* [[TMP3]] to <2 x float>*
441eb052f6bSPhilip Reames; UNROLL-NEXT:    store <2 x float> [[TMP14]], <2 x float>* [[TMP16]], align 4, !alias.scope !4, !noalias !7
442eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP17:%.*]] = bitcast float* [[TMP5]] to <2 x float>*
443eb052f6bSPhilip Reames; UNROLL-NEXT:    store <2 x float> [[TMP15]], <2 x float>* [[TMP17]], align 4, !alias.scope !4, !noalias !7
444eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
445eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP18:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
446eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP18]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
447eb052f6bSPhilip Reames; UNROLL:       middle.block:
448eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[N]]
449eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
450eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
451eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
452eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
453eb052f6bSPhilip Reames; UNROLL:       for.body:
454eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
455eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IND_SUM:%.*]] = add i64 [[IV]], [[OFFSET]]
456eb052f6bSPhilip Reames; UNROLL-NEXT:    [[ARR_IDX:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[IND_SUM]]
457eb052f6bSPhilip Reames; UNROLL-NEXT:    [[L1:%.*]] = load float, float* [[ARR_IDX]], align 4
458eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IND_SUM2:%.*]] = add i64 [[IV]], [[OFFSET2]]
459eb052f6bSPhilip Reames; UNROLL-NEXT:    [[ARR_IDX2:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[IND_SUM2]]
460eb052f6bSPhilip Reames; UNROLL-NEXT:    [[L2:%.*]] = load float, float* [[ARR_IDX2]], align 4
461eb052f6bSPhilip Reames; UNROLL-NEXT:    [[M:%.*]] = fmul fast float [[L2]], [[B]]
462eb052f6bSPhilip Reames; UNROLL-NEXT:    [[AD:%.*]] = fadd fast float [[L1]], [[M]]
463eb052f6bSPhilip Reames; UNROLL-NEXT:    store float [[AD]], float* [[ARR_IDX]], align 4
464eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
465eb052f6bSPhilip Reames; UNROLL-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
466eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]
467eb052f6bSPhilip Reames; UNROLL:       loopexit:
468eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
469eb052f6bSPhilip Reames;
470eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @scalar_use(
471eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
472eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N:%.*]], 4
473eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
474eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.memcheck:
475eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP:%.*]] = getelementptr float, float* [[A:%.*]], i64 [[OFFSET:%.*]]
476eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP1:%.*]] = bitcast float* [[SCEVGEP]] to i8*
477eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i64 [[N]], [[OFFSET]]
478eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP2:%.*]] = getelementptr float, float* [[A]], i64 [[TMP0]]
479eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP23:%.*]] = bitcast float* [[SCEVGEP2]] to i8*
480eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP4:%.*]] = getelementptr float, float* [[A]], i64 [[OFFSET2:%.*]]
481eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP45:%.*]] = bitcast float* [[SCEVGEP4]] to i8*
482eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = add i64 [[N]], [[OFFSET2]]
483eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP6:%.*]] = getelementptr float, float* [[A]], i64 [[TMP1]]
484eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP67:%.*]] = bitcast float* [[SCEVGEP6]] to i8*
485eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BOUND0:%.*]] = icmp ult i8* [[SCEVGEP1]], [[SCEVGEP67]]
486eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BOUND1:%.*]] = icmp ult i8* [[SCEVGEP45]], [[SCEVGEP23]]
487eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
488eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
489eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
490eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[N]], 4
491eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i64 [[N]], [[N_MOD_VF]]
492eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x float> poison, float [[B:%.*]], i32 0
493eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x float> [[BROADCAST_SPLATINSERT]], <2 x float> poison, <2 x i32> zeroinitializer
494eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLATINSERT11:%.*]] = insertelement <2 x float> poison, float [[B]], i32 0
495eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLAT12:%.*]] = shufflevector <2 x float> [[BROADCAST_SPLATINSERT11]], <2 x float> poison, <2 x i32> zeroinitializer
496eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
497eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
498eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
499eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = add i64 [[INDEX]], 0
500eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = add i64 [[INDEX]], 2
501eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = add i64 [[TMP2]], [[OFFSET]]
502eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = add i64 [[TMP3]], [[OFFSET]]
503eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP4]]
504eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP5]]
505eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = getelementptr inbounds float, float* [[TMP6]], i32 0
506eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = bitcast float* [[TMP8]] to <2 x float>*
507eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x float>, <2 x float>* [[TMP9]], align 4, !alias.scope !4, !noalias !7
508eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = getelementptr inbounds float, float* [[TMP6]], i32 2
509eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = bitcast float* [[TMP10]] to <2 x float>*
510eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[WIDE_LOAD8:%.*]] = load <2 x float>, <2 x float>* [[TMP11]], align 4, !alias.scope !4, !noalias !7
511eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = add i64 [[TMP2]], [[OFFSET2]]
512eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = add i64 [[TMP3]], [[OFFSET2]]
513eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP12]]
514eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP13]]
515eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP16:%.*]] = getelementptr inbounds float, float* [[TMP14]], i32 0
516eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP17:%.*]] = bitcast float* [[TMP16]] to <2 x float>*
517eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[WIDE_LOAD9:%.*]] = load <2 x float>, <2 x float>* [[TMP17]], align 4, !alias.scope !7
518eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP18:%.*]] = getelementptr inbounds float, float* [[TMP14]], i32 2
519eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP19:%.*]] = bitcast float* [[TMP18]] to <2 x float>*
520eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[WIDE_LOAD10:%.*]] = load <2 x float>, <2 x float>* [[TMP19]], align 4, !alias.scope !7
521eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP20:%.*]] = fmul fast <2 x float> [[BROADCAST_SPLAT]], [[WIDE_LOAD9]]
522eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP21:%.*]] = fmul fast <2 x float> [[BROADCAST_SPLAT12]], [[WIDE_LOAD10]]
523eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP22:%.*]] = fadd fast <2 x float> [[WIDE_LOAD]], [[TMP20]]
524eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP23:%.*]] = fadd fast <2 x float> [[WIDE_LOAD8]], [[TMP21]]
525eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP24:%.*]] = bitcast float* [[TMP8]] to <2 x float>*
526eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store <2 x float> [[TMP22]], <2 x float>* [[TMP24]], align 4, !alias.scope !4, !noalias !7
527eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP25:%.*]] = bitcast float* [[TMP10]] to <2 x float>*
528eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store <2 x float> [[TMP23]], <2 x float>* [[TMP25]], align 4, !alias.scope !4, !noalias !7
529eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
530eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP26:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
531eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP26]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
532eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
533eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]]
534eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
535eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
536eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
537eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
538eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
539eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
540eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IND_SUM:%.*]] = add i64 [[IV]], [[OFFSET]]
541eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[ARR_IDX:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[IND_SUM]]
542eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[L1:%.*]] = load float, float* [[ARR_IDX]], align 4
543eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IND_SUM2:%.*]] = add i64 [[IV]], [[OFFSET2]]
544eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[ARR_IDX2:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[IND_SUM2]]
545eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[L2:%.*]] = load float, float* [[ARR_IDX2]], align 4
546eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[M:%.*]] = fmul fast float [[B]], [[L2]]
547eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[AD:%.*]] = fadd fast float [[L1]], [[M]]
548eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store float [[AD]], float* [[ARR_IDX]], align 4
549eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
550eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
551eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]
552eb052f6bSPhilip Reames; UNROLL-NO-IC:       loopexit:
553eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
554eb052f6bSPhilip Reames;
555eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @scalar_use(
556eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
557eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N:%.*]], 8
558eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
559eb052f6bSPhilip Reames; INTERLEAVE:       vector.memcheck:
560eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SCEVGEP:%.*]] = getelementptr float, float* [[A:%.*]], i64 [[OFFSET:%.*]]
561eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = add i64 [[N]], [[OFFSET]]
562eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SCEVGEP2:%.*]] = getelementptr float, float* [[A]], i64 [[TMP0]]
563eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SCEVGEP4:%.*]] = getelementptr float, float* [[A]], i64 [[OFFSET2:%.*]]
564eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = add i64 [[N]], [[OFFSET2]]
565eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SCEVGEP6:%.*]] = getelementptr float, float* [[A]], i64 [[TMP1]]
566eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BOUND0:%.*]] = icmp ult float* [[SCEVGEP]], [[SCEVGEP6]]
567eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BOUND1:%.*]] = icmp ult float* [[SCEVGEP4]], [[SCEVGEP2]]
568eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
569eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
570eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
571eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i64 [[N]], -8
572e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x float> poison, float [[B:%.*]], i64 0
573eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x float> [[BROADCAST_SPLATINSERT]], <4 x float> poison, <4 x i32> zeroinitializer
574e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLATINSERT11:%.*]] = insertelement <4 x float> poison, float [[B]], i64 0
575eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLAT12:%.*]] = shufflevector <4 x float> [[BROADCAST_SPLATINSERT11]], <4 x float> poison, <4 x i32> zeroinitializer
576eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
577eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
578eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
579eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = add i64 [[INDEX]], [[OFFSET]]
580eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP2]]
581eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = bitcast float* [[TMP3]] to <4 x float>*
582eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x float>, <4 x float>* [[TMP4]], align 4, !alias.scope !4, !noalias !7
583eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = getelementptr inbounds float, float* [[TMP3]], i64 4
584eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = bitcast float* [[TMP5]] to <4 x float>*
585eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_LOAD8:%.*]] = load <4 x float>, <4 x float>* [[TMP6]], align 4, !alias.scope !4, !noalias !7
586eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP7:%.*]] = add i64 [[INDEX]], [[OFFSET2]]
587eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP8:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP7]]
588eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP9:%.*]] = bitcast float* [[TMP8]] to <4 x float>*
589eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_LOAD9:%.*]] = load <4 x float>, <4 x float>* [[TMP9]], align 4, !alias.scope !7
590eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP10:%.*]] = getelementptr inbounds float, float* [[TMP8]], i64 4
591eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP11:%.*]] = bitcast float* [[TMP10]] to <4 x float>*
592eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_LOAD10:%.*]] = load <4 x float>, <4 x float>* [[TMP11]], align 4, !alias.scope !7
593eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP12:%.*]] = fmul fast <4 x float> [[BROADCAST_SPLAT]], [[WIDE_LOAD9]]
594eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP13:%.*]] = fmul fast <4 x float> [[BROADCAST_SPLAT12]], [[WIDE_LOAD10]]
595eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP14:%.*]] = fadd fast <4 x float> [[WIDE_LOAD]], [[TMP12]]
596eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP15:%.*]] = fadd fast <4 x float> [[WIDE_LOAD8]], [[TMP13]]
597eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP16:%.*]] = bitcast float* [[TMP3]] to <4 x float>*
598eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store <4 x float> [[TMP14]], <4 x float>* [[TMP16]], align 4, !alias.scope !4, !noalias !7
599eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP17:%.*]] = bitcast float* [[TMP5]] to <4 x float>*
600eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store <4 x float> [[TMP15]], <4 x float>* [[TMP17]], align 4, !alias.scope !4, !noalias !7
601eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
602eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP18:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
603eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP18]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
604eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
605eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[N]]
606eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
607eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
608eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
609eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
610eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
611eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
612eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IND_SUM:%.*]] = add i64 [[IV]], [[OFFSET]]
613eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[ARR_IDX:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[IND_SUM]]
614eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[L1:%.*]] = load float, float* [[ARR_IDX]], align 4
615eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IND_SUM2:%.*]] = add i64 [[IV]], [[OFFSET2]]
616eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[ARR_IDX2:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[IND_SUM2]]
617eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[L2:%.*]] = load float, float* [[ARR_IDX2]], align 4
618eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[M:%.*]] = fmul fast float [[L2]], [[B]]
619eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[AD:%.*]] = fadd fast float [[L1]], [[M]]
620eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store float [[AD]], float* [[ARR_IDX]], align 4
621eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
622eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
623eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]
624eb052f6bSPhilip Reames; INTERLEAVE:       loopexit:
625eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
626eb052f6bSPhilip Reames;
627cee313d2SEric Christopherentry:
628cee313d2SEric Christopher  br label %for.body
629cee313d2SEric Christopher
630cee313d2SEric Christopherfor.body:
631cee313d2SEric Christopher  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
632cee313d2SEric Christopher  %ind.sum = add i64 %iv, %offset
633cee313d2SEric Christopher  %arr.idx = getelementptr inbounds float, float* %a, i64 %ind.sum
634cee313d2SEric Christopher  %l1 = load float, float* %arr.idx, align 4
635cee313d2SEric Christopher  %ind.sum2 = add i64 %iv, %offset2
636cee313d2SEric Christopher  %arr.idx2 = getelementptr inbounds float, float* %a, i64 %ind.sum2
637cee313d2SEric Christopher  %l2 = load float, float* %arr.idx2, align 4
638cee313d2SEric Christopher  %m = fmul fast float %b, %l2
639cee313d2SEric Christopher  %ad = fadd fast float %l1, %m
640cee313d2SEric Christopher  store float %ad, float* %arr.idx, align 4
641cee313d2SEric Christopher  %iv.next = add nuw nsw i64 %iv, 1
642cee313d2SEric Christopher  %exitcond = icmp eq i64 %iv.next, %n
643cee313d2SEric Christopher  br i1 %exitcond, label %loopexit, label %for.body
644cee313d2SEric Christopher
645cee313d2SEric Christopherloopexit:
646cee313d2SEric Christopher  ret void
647cee313d2SEric Christopher}
648cee313d2SEric Christopher
649cee313d2SEric Christopher; Make sure we don't create a vector induction phi node that is unused.
650cee313d2SEric Christopher; Scalarize the step vectors instead.
651cee313d2SEric Christopher;
652cee313d2SEric Christopher; for (int i = 0; i < n; ++i)
653cee313d2SEric Christopher;   sum += a[i];
654cee313d2SEric Christopher;
655bbfaf0b1SPhilip Reames;
656bbfaf0b1SPhilip Reames;
657bbfaf0b1SPhilip Reames;
658bbba8676SPhilip Reames
659bbba8676SPhilip Reamesdefine i64 @scalarize_induction_variable_01(i64 *%a, i64 %n) {
660eb052f6bSPhilip Reames; CHECK-LABEL: @scalarize_induction_variable_01(
661eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
662eb052f6bSPhilip Reames; CHECK-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
663eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 2
664eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
665eb052f6bSPhilip Reames; CHECK:       vector.ph:
666eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[SMAX]], 2
667eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[SMAX]], [[N_MOD_VF]]
668eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
669eb052f6bSPhilip Reames; CHECK:       vector.body:
670eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
671eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP4:%.*]], [[VECTOR_BODY]] ]
672eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
673eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i64, i64* [[A:%.*]], i64 [[TMP0]]
674eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, i64* [[TMP1]], i32 0
675eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i64* [[TMP2]] to <2 x i64>*
676eb052f6bSPhilip Reames; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x i64>, <2 x i64>* [[TMP3]], align 8
677eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4]] = add <2 x i64> [[WIDE_LOAD]], [[VEC_PHI]]
678eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
679eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
680eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]
681eb052f6bSPhilip Reames; CHECK:       middle.block:
682eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP6:%.*]] = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> [[TMP4]])
683eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
684eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
685eb052f6bSPhilip Reames; CHECK:       scalar.ph:
686eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
687eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[TMP6]], [[MIDDLE_BLOCK]] ]
688eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
689eb052f6bSPhilip Reames; CHECK:       for.body:
690eb052f6bSPhilip Reames; CHECK-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
691eb052f6bSPhilip Reames; CHECK-NEXT:    [[SUM:%.*]] = phi i64 [ [[TMP9:%.*]], [[FOR_BODY]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
692eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i64, i64* [[A]], i64 [[I]]
693eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP8:%.*]] = load i64, i64* [[TMP7]], align 8
694eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP9]] = add i64 [[TMP8]], [[SUM]]
695eb052f6bSPhilip Reames; CHECK-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
696eb052f6bSPhilip Reames; CHECK-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
697eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP12:![0-9]+]]
698eb052f6bSPhilip Reames; CHECK:       for.end:
699eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP10:%.*]] = phi i64 [ [[TMP9]], [[FOR_BODY]] ], [ [[TMP6]], [[MIDDLE_BLOCK]] ]
700eb052f6bSPhilip Reames; CHECK-NEXT:    ret i64 [[TMP10]]
701eb052f6bSPhilip Reames;
702eb052f6bSPhilip Reames; IND-LABEL: @scalarize_induction_variable_01(
703eb052f6bSPhilip Reames; IND-NEXT:  entry:
704eb052f6bSPhilip Reames; IND-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
705eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 2
706eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
707eb052f6bSPhilip Reames; IND:       vector.ph:
708eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i64 [[SMAX]], 9223372036854775806
709eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
710eb052f6bSPhilip Reames; IND:       vector.body:
711eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
712eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP2:%.*]], [[VECTOR_BODY]] ]
713eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = getelementptr inbounds i64, i64* [[A:%.*]], i64 [[INDEX]]
714eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = bitcast i64* [[TMP0]] to <2 x i64>*
715eb052f6bSPhilip Reames; IND-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x i64>, <2 x i64>* [[TMP1]], align 8
716eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2]] = add <2 x i64> [[WIDE_LOAD]], [[VEC_PHI]]
717eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
718eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
719eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP3]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]
720eb052f6bSPhilip Reames; IND:       middle.block:
721eb052f6bSPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> [[TMP2]])
722eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
723eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
724eb052f6bSPhilip Reames; IND:       scalar.ph:
725eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
726eb052f6bSPhilip Reames; IND-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i64 [ [[TMP4]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
727eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
728eb052f6bSPhilip Reames; IND:       for.body:
729eb052f6bSPhilip Reames; IND-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
730eb052f6bSPhilip Reames; IND-NEXT:    [[SUM:%.*]] = phi i64 [ [[TMP7:%.*]], [[FOR_BODY]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
731eb052f6bSPhilip Reames; IND-NEXT:    [[TMP5:%.*]] = getelementptr inbounds i64, i64* [[A]], i64 [[I]]
732eb052f6bSPhilip Reames; IND-NEXT:    [[TMP6:%.*]] = load i64, i64* [[TMP5]], align 8
733eb052f6bSPhilip Reames; IND-NEXT:    [[TMP7]] = add i64 [[TMP6]], [[SUM]]
734eb052f6bSPhilip Reames; IND-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
735eb052f6bSPhilip Reames; IND-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
736eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP12:![0-9]+]]
737eb052f6bSPhilip Reames; IND:       for.end:
738eb052f6bSPhilip Reames; IND-NEXT:    [[TMP8:%.*]] = phi i64 [ [[TMP7]], [[FOR_BODY]] ], [ [[TMP4]], [[MIDDLE_BLOCK]] ]
739eb052f6bSPhilip Reames; IND-NEXT:    ret i64 [[TMP8]]
740eb052f6bSPhilip Reames;
741eb052f6bSPhilip Reames; UNROLL-LABEL: @scalarize_induction_variable_01(
742eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
743eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
744eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 4
745eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
746eb052f6bSPhilip Reames; UNROLL:       vector.ph:
747eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i64 [[SMAX]], 9223372036854775804
748eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
749eb052f6bSPhilip Reames; UNROLL:       vector.body:
750eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
751eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP4:%.*]], [[VECTOR_BODY]] ]
752eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_PHI1:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP5:%.*]], [[VECTOR_BODY]] ]
753eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = getelementptr inbounds i64, i64* [[A:%.*]], i64 [[INDEX]]
754eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = bitcast i64* [[TMP0]] to <2 x i64>*
755eb052f6bSPhilip Reames; UNROLL-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x i64>, <2 x i64>* [[TMP1]], align 8
756eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, i64* [[TMP0]], i64 2
757eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = bitcast i64* [[TMP2]] to <2 x i64>*
758eb052f6bSPhilip Reames; UNROLL-NEXT:    [[WIDE_LOAD2:%.*]] = load <2 x i64>, <2 x i64>* [[TMP3]], align 8
759eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4]] = add <2 x i64> [[WIDE_LOAD]], [[VEC_PHI]]
760eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5]] = add <2 x i64> [[WIDE_LOAD2]], [[VEC_PHI1]]
761eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
762eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
763eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]
764eb052f6bSPhilip Reames; UNROLL:       middle.block:
765eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BIN_RDX:%.*]] = add <2 x i64> [[TMP5]], [[TMP4]]
766eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP7:%.*]] = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> [[BIN_RDX]])
767eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
768eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
769eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
770eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
771eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i64 [ [[TMP7]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
772eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
773eb052f6bSPhilip Reames; UNROLL:       for.body:
774eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
775eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SUM:%.*]] = phi i64 [ [[TMP10:%.*]], [[FOR_BODY]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
776eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i64, i64* [[A]], i64 [[I]]
777eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP9:%.*]] = load i64, i64* [[TMP8]], align 8
778eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP10]] = add i64 [[TMP9]], [[SUM]]
779eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
780eb052f6bSPhilip Reames; UNROLL-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
781eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP12:![0-9]+]]
782eb052f6bSPhilip Reames; UNROLL:       for.end:
783eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP11:%.*]] = phi i64 [ [[TMP10]], [[FOR_BODY]] ], [ [[TMP7]], [[MIDDLE_BLOCK]] ]
784eb052f6bSPhilip Reames; UNROLL-NEXT:    ret i64 [[TMP11]]
785eb052f6bSPhilip Reames;
786eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @scalarize_induction_variable_01(
787eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
788eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
789eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 4
790eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
791eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
792eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[SMAX]], 4
793eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i64 [[SMAX]], [[N_MOD_VF]]
794eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
795eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
796eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
797eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP8:%.*]], [[VECTOR_BODY]] ]
798eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_PHI1:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP9:%.*]], [[VECTOR_BODY]] ]
799eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
800eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = add i64 [[INDEX]], 2
801eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, i64* [[A:%.*]], i64 [[TMP0]]
802eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i64, i64* [[A]], i64 [[TMP1]]
803eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i64, i64* [[TMP2]], i32 0
804eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = bitcast i64* [[TMP4]] to <2 x i64>*
805eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x i64>, <2 x i64>* [[TMP5]], align 8
806eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = getelementptr inbounds i64, i64* [[TMP2]], i32 2
807eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = bitcast i64* [[TMP6]] to <2 x i64>*
808eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[WIDE_LOAD2:%.*]] = load <2 x i64>, <2 x i64>* [[TMP7]], align 8
809eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP8]] = add <2 x i64> [[WIDE_LOAD]], [[VEC_PHI]]
810eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP9]] = add <2 x i64> [[WIDE_LOAD2]], [[VEC_PHI1]]
811eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
812eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
813eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]
814eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
815eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BIN_RDX:%.*]] = add <2 x i64> [[TMP9]], [[TMP8]]
816eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> [[BIN_RDX]])
817eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
818eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
819eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
820eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
821eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[TMP11]], [[MIDDLE_BLOCK]] ]
822eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
823eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
824eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
825eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SUM:%.*]] = phi i64 [ [[TMP14:%.*]], [[FOR_BODY]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
826eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = getelementptr inbounds i64, i64* [[A]], i64 [[I]]
827eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = load i64, i64* [[TMP12]], align 8
828eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP14]] = add i64 [[TMP13]], [[SUM]]
829eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
830eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
831eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP12:![0-9]+]]
832eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.end:
833eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = phi i64 [ [[TMP14]], [[FOR_BODY]] ], [ [[TMP11]], [[MIDDLE_BLOCK]] ]
834eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret i64 [[TMP15]]
835eb052f6bSPhilip Reames;
836eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @scalarize_induction_variable_01(
837eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
838eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
839eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 8
840eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
841eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
842eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i64 [[SMAX]], 9223372036854775800
843eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
844eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
845eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
846eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_PHI:%.*]] = phi <4 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP4:%.*]], [[VECTOR_BODY]] ]
847eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_PHI1:%.*]] = phi <4 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP5:%.*]], [[VECTOR_BODY]] ]
848eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = getelementptr inbounds i64, i64* [[A:%.*]], i64 [[INDEX]]
849eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = bitcast i64* [[TMP0]] to <4 x i64>*
850eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x i64>, <4 x i64>* [[TMP1]], align 8
851eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, i64* [[TMP0]], i64 4
852eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = bitcast i64* [[TMP2]] to <4 x i64>*
853eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_LOAD2:%.*]] = load <4 x i64>, <4 x i64>* [[TMP3]], align 8
854eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4]] = add <4 x i64> [[WIDE_LOAD]], [[VEC_PHI]]
855eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5]] = add <4 x i64> [[WIDE_LOAD2]], [[VEC_PHI1]]
856eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
857eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
858eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]
859eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
860eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BIN_RDX:%.*]] = add <4 x i64> [[TMP5]], [[TMP4]]
861eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP7:%.*]] = call i64 @llvm.vector.reduce.add.v4i64(<4 x i64> [[BIN_RDX]])
862eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
863eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
864eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
865eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
866eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i64 [ [[TMP7]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
867eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
868eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
869eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
870eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SUM:%.*]] = phi i64 [ [[TMP10:%.*]], [[FOR_BODY]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
871eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i64, i64* [[A]], i64 [[I]]
872eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP9:%.*]] = load i64, i64* [[TMP8]], align 8
873eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP10]] = add i64 [[TMP9]], [[SUM]]
874eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
875eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
876eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP12:![0-9]+]]
877eb052f6bSPhilip Reames; INTERLEAVE:       for.end:
878eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP11:%.*]] = phi i64 [ [[TMP10]], [[FOR_BODY]] ], [ [[TMP7]], [[MIDDLE_BLOCK]] ]
879eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret i64 [[TMP11]]
880eb052f6bSPhilip Reames;
881cee313d2SEric Christopherentry:
882cee313d2SEric Christopher  br label %for.body
883cee313d2SEric Christopher
884cee313d2SEric Christopherfor.body:
885cee313d2SEric Christopher  %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
886cee313d2SEric Christopher  %sum = phi i64 [ %2, %for.body ], [ 0, %entry ]
887cee313d2SEric Christopher  %0 = getelementptr inbounds i64, i64* %a, i64 %i
888cee313d2SEric Christopher  %1 = load i64, i64* %0, align 8
889cee313d2SEric Christopher  %2 = add i64 %1, %sum
890cee313d2SEric Christopher  %i.next = add nuw nsw i64 %i, 1
891cee313d2SEric Christopher  %cond = icmp slt i64 %i.next, %n
892cee313d2SEric Christopher  br i1 %cond, label %for.body, label %for.end
893cee313d2SEric Christopher
894cee313d2SEric Christopherfor.end:
895cee313d2SEric Christopher  %3  = phi i64 [ %2, %for.body ]
896cee313d2SEric Christopher  ret i64 %3
897cee313d2SEric Christopher}
898cee313d2SEric Christopher
899cee313d2SEric Christopher; Make sure we scalarize the step vectors used for the pointer arithmetic. We
900cee313d2SEric Christopher; can't easily simplify vectorized step vectors.
901cee313d2SEric Christopher;
902cee313d2SEric Christopher; float s = 0;
903cee313d2SEric Christopher; for (int i ; 0; i < n; i += 8)
904cee313d2SEric Christopher;   s += (a[i] + b[i] + 1.0f);
905cee313d2SEric Christopher;
906bbfaf0b1SPhilip Reames;
907bbfaf0b1SPhilip Reames;
908bbfaf0b1SPhilip Reames;
909bbba8676SPhilip Reames
910bbba8676SPhilip Reamesdefine float @scalarize_induction_variable_02(float* %a, float* %b, i64 %n) {
911eb052f6bSPhilip Reames; CHECK-LABEL: @scalarize_induction_variable_02(
912eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
913eb052f6bSPhilip Reames; CHECK-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 8)
914eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add nsw i64 [[SMAX]], -1
915eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = lshr i64 [[TMP0]], 3
916eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
917eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], 2
918eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
919eb052f6bSPhilip Reames; CHECK:       vector.ph:
920eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 2
921eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
922eb052f6bSPhilip Reames; CHECK-NEXT:    [[IND_END:%.*]] = mul i64 [[N_VEC]], 8
923eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
924eb052f6bSPhilip Reames; CHECK:       vector.body:
925eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
926eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <2 x float> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP19:%.*]], [[VECTOR_BODY]] ]
927eb052f6bSPhilip Reames; CHECK-NEXT:    [[OFFSET_IDX:%.*]] = mul i64 [[INDEX]], 8
928eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = add i64 [[OFFSET_IDX]], 0
929eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = add i64 [[OFFSET_IDX]], 8
930eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP5:%.*]] = getelementptr inbounds float, float* [[A:%.*]], i64 [[TMP3]]
931eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP6:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP4]]
932eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP7:%.*]] = load float, float* [[TMP5]], align 4
933eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP8:%.*]] = load float, float* [[TMP6]], align 4
934eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP9:%.*]] = insertelement <2 x float> poison, float [[TMP7]], i32 0
935eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP10:%.*]] = insertelement <2 x float> [[TMP9]], float [[TMP8]], i32 1
936eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP11:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 [[TMP3]]
937eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP12:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[TMP4]]
938eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP13:%.*]] = load float, float* [[TMP11]], align 4
939eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP14:%.*]] = load float, float* [[TMP12]], align 4
940eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP15:%.*]] = insertelement <2 x float> poison, float [[TMP13]], i32 0
941eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP16:%.*]] = insertelement <2 x float> [[TMP15]], float [[TMP14]], i32 1
942eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP17:%.*]] = fadd fast <2 x float> [[VEC_PHI]], <float 1.000000e+00, float 1.000000e+00>
943eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP18:%.*]] = fadd fast <2 x float> [[TMP17]], [[TMP10]]
944eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP19]] = fadd fast <2 x float> [[TMP18]], [[TMP16]]
945eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
946eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP20:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
947eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP20]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
948eb052f6bSPhilip Reames; CHECK:       middle.block:
949eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP21:%.*]] = call fast float @llvm.vector.reduce.fadd.v2f32(float -0.000000e+00, <2 x float> [[TMP19]])
950eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
951eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
952eb052f6bSPhilip Reames; CHECK:       scalar.ph:
953eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
954eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_MERGE_RDX:%.*]] = phi float [ 0.000000e+00, [[ENTRY]] ], [ [[TMP21]], [[MIDDLE_BLOCK]] ]
955eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
956eb052f6bSPhilip Reames; CHECK:       for.body:
957eb052f6bSPhilip Reames; CHECK-NEXT:    [[I:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[FOR_BODY]] ]
958eb052f6bSPhilip Reames; CHECK-NEXT:    [[S:%.*]] = phi float [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[TMP28:%.*]], [[FOR_BODY]] ]
959eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP22:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[I]]
960eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP23:%.*]] = load float, float* [[TMP22]], align 4
961eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP24:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[I]]
962eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP25:%.*]] = load float, float* [[TMP24]], align 4
963eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP26:%.*]] = fadd fast float [[S]], 1.000000e+00
964eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP27:%.*]] = fadd fast float [[TMP26]], [[TMP23]]
965eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP28]] = fadd fast float [[TMP27]], [[TMP25]]
966eb052f6bSPhilip Reames; CHECK-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 8
967eb052f6bSPhilip Reames; CHECK-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
968eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP14:![0-9]+]]
969eb052f6bSPhilip Reames; CHECK:       for.end:
970eb052f6bSPhilip Reames; CHECK-NEXT:    [[S_LCSSA:%.*]] = phi float [ [[TMP28]], [[FOR_BODY]] ], [ [[TMP21]], [[MIDDLE_BLOCK]] ]
971eb052f6bSPhilip Reames; CHECK-NEXT:    ret float [[S_LCSSA]]
972eb052f6bSPhilip Reames;
973eb052f6bSPhilip Reames; IND-LABEL: @scalarize_induction_variable_02(
974eb052f6bSPhilip Reames; IND-NEXT:  entry:
975eb052f6bSPhilip Reames; IND-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 8)
976eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = add nsw i64 [[SMAX]], -1
977eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = lshr i64 [[TMP0]], 3
978eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
979eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP0]], 8
980eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
981eb052f6bSPhilip Reames; IND:       vector.ph:
982eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i64 [[TMP2]], 4611686018427387902
983eb052f6bSPhilip Reames; IND-NEXT:    [[IND_END:%.*]] = shl i64 [[N_VEC]], 3
984eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
985eb052f6bSPhilip Reames; IND:       vector.body:
986eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
987eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_PHI:%.*]] = phi <2 x float> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP18:%.*]], [[VECTOR_BODY]] ]
988eb052f6bSPhilip Reames; IND-NEXT:    [[OFFSET_IDX:%.*]] = shl i64 [[INDEX]], 3
989eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = or i64 [[OFFSET_IDX]], 8
990eb052f6bSPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = getelementptr inbounds float, float* [[A:%.*]], i64 [[OFFSET_IDX]]
991eb052f6bSPhilip Reames; IND-NEXT:    [[TMP5:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP3]]
992eb052f6bSPhilip Reames; IND-NEXT:    [[TMP6:%.*]] = load float, float* [[TMP4]], align 4
993eb052f6bSPhilip Reames; IND-NEXT:    [[TMP7:%.*]] = load float, float* [[TMP5]], align 4
994e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP8:%.*]] = insertelement <2 x float> poison, float [[TMP6]], i64 0
995e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP9:%.*]] = insertelement <2 x float> [[TMP8]], float [[TMP7]], i64 1
996eb052f6bSPhilip Reames; IND-NEXT:    [[TMP10:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 [[OFFSET_IDX]]
997eb052f6bSPhilip Reames; IND-NEXT:    [[TMP11:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[TMP3]]
998eb052f6bSPhilip Reames; IND-NEXT:    [[TMP12:%.*]] = load float, float* [[TMP10]], align 4
999eb052f6bSPhilip Reames; IND-NEXT:    [[TMP13:%.*]] = load float, float* [[TMP11]], align 4
1000e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP14:%.*]] = insertelement <2 x float> poison, float [[TMP12]], i64 0
1001e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP15:%.*]] = insertelement <2 x float> [[TMP14]], float [[TMP13]], i64 1
1002eb052f6bSPhilip Reames; IND-NEXT:    [[TMP16:%.*]] = fadd fast <2 x float> [[VEC_PHI]], <float 1.000000e+00, float 1.000000e+00>
1003eb052f6bSPhilip Reames; IND-NEXT:    [[TMP17:%.*]] = fadd fast <2 x float> [[TMP16]], [[TMP9]]
1004eb052f6bSPhilip Reames; IND-NEXT:    [[TMP18]] = fadd fast <2 x float> [[TMP17]], [[TMP15]]
1005eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
1006eb052f6bSPhilip Reames; IND-NEXT:    [[TMP19:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1007eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP19]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
1008eb052f6bSPhilip Reames; IND:       middle.block:
1009eb052f6bSPhilip Reames; IND-NEXT:    [[TMP20:%.*]] = call fast float @llvm.vector.reduce.fadd.v2f32(float -0.000000e+00, <2 x float> [[TMP18]])
1010eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
1011eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
1012eb052f6bSPhilip Reames; IND:       scalar.ph:
1013eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
1014eb052f6bSPhilip Reames; IND-NEXT:    [[BC_MERGE_RDX:%.*]] = phi float [ [[TMP20]], [[MIDDLE_BLOCK]] ], [ 0.000000e+00, [[ENTRY]] ]
1015eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
1016eb052f6bSPhilip Reames; IND:       for.body:
1017eb052f6bSPhilip Reames; IND-NEXT:    [[I:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[FOR_BODY]] ]
1018eb052f6bSPhilip Reames; IND-NEXT:    [[S:%.*]] = phi float [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[TMP27:%.*]], [[FOR_BODY]] ]
1019eb052f6bSPhilip Reames; IND-NEXT:    [[TMP21:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[I]]
1020eb052f6bSPhilip Reames; IND-NEXT:    [[TMP22:%.*]] = load float, float* [[TMP21]], align 4
1021eb052f6bSPhilip Reames; IND-NEXT:    [[TMP23:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[I]]
1022eb052f6bSPhilip Reames; IND-NEXT:    [[TMP24:%.*]] = load float, float* [[TMP23]], align 4
1023eb052f6bSPhilip Reames; IND-NEXT:    [[TMP25:%.*]] = fadd fast float [[S]], 1.000000e+00
1024eb052f6bSPhilip Reames; IND-NEXT:    [[TMP26:%.*]] = fadd fast float [[TMP25]], [[TMP22]]
1025eb052f6bSPhilip Reames; IND-NEXT:    [[TMP27]] = fadd fast float [[TMP26]], [[TMP24]]
1026eb052f6bSPhilip Reames; IND-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 8
1027eb052f6bSPhilip Reames; IND-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
1028eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP14:![0-9]+]]
1029eb052f6bSPhilip Reames; IND:       for.end:
1030eb052f6bSPhilip Reames; IND-NEXT:    [[S_LCSSA:%.*]] = phi float [ [[TMP27]], [[FOR_BODY]] ], [ [[TMP20]], [[MIDDLE_BLOCK]] ]
1031eb052f6bSPhilip Reames; IND-NEXT:    ret float [[S_LCSSA]]
1032eb052f6bSPhilip Reames;
1033eb052f6bSPhilip Reames; UNROLL-LABEL: @scalarize_induction_variable_02(
1034eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
1035eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 8)
1036eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = add nsw i64 [[SMAX]], -1
1037eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = lshr i64 [[TMP0]], 3
1038eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
1039eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP0]], 24
1040eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1041eb052f6bSPhilip Reames; UNROLL:       vector.ph:
1042eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i64 [[TMP2]], 4611686018427387900
1043eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IND_END:%.*]] = shl i64 [[N_VEC]], 3
1044eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
1045eb052f6bSPhilip Reames; UNROLL:       vector.body:
1046eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1047eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_PHI:%.*]] = phi <2 x float> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP34:%.*]], [[VECTOR_BODY]] ]
1048eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_PHI1:%.*]] = phi <2 x float> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP35:%.*]], [[VECTOR_BODY]] ]
1049eb052f6bSPhilip Reames; UNROLL-NEXT:    [[OFFSET_IDX:%.*]] = shl i64 [[INDEX]], 3
1050eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = or i64 [[OFFSET_IDX]], 8
1051eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = or i64 [[OFFSET_IDX]], 16
1052eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = or i64 [[OFFSET_IDX]], 24
1053eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP6:%.*]] = getelementptr inbounds float, float* [[A:%.*]], i64 [[OFFSET_IDX]]
1054eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP7:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP3]]
1055eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP8:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP4]]
1056eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP9:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP5]]
1057eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP10:%.*]] = load float, float* [[TMP6]], align 4
1058eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP11:%.*]] = load float, float* [[TMP7]], align 4
1059e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP12:%.*]] = insertelement <2 x float> poison, float [[TMP10]], i64 0
1060e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP13:%.*]] = insertelement <2 x float> [[TMP12]], float [[TMP11]], i64 1
1061eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP14:%.*]] = load float, float* [[TMP8]], align 4
1062eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP15:%.*]] = load float, float* [[TMP9]], align 4
1063e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP16:%.*]] = insertelement <2 x float> poison, float [[TMP14]], i64 0
1064e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP17:%.*]] = insertelement <2 x float> [[TMP16]], float [[TMP15]], i64 1
1065eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP18:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 [[OFFSET_IDX]]
1066eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP19:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[TMP3]]
1067eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP20:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[TMP4]]
1068eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP21:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[TMP5]]
1069eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP22:%.*]] = load float, float* [[TMP18]], align 4
1070eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP23:%.*]] = load float, float* [[TMP19]], align 4
1071e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP24:%.*]] = insertelement <2 x float> poison, float [[TMP22]], i64 0
1072e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP25:%.*]] = insertelement <2 x float> [[TMP24]], float [[TMP23]], i64 1
1073eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP26:%.*]] = load float, float* [[TMP20]], align 4
1074eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP27:%.*]] = load float, float* [[TMP21]], align 4
1075e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP28:%.*]] = insertelement <2 x float> poison, float [[TMP26]], i64 0
1076e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP29:%.*]] = insertelement <2 x float> [[TMP28]], float [[TMP27]], i64 1
1077eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP30:%.*]] = fadd fast <2 x float> [[VEC_PHI]], <float 1.000000e+00, float 1.000000e+00>
1078eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP31:%.*]] = fadd fast <2 x float> [[VEC_PHI1]], <float 1.000000e+00, float 1.000000e+00>
1079eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP32:%.*]] = fadd fast <2 x float> [[TMP30]], [[TMP13]]
1080eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP33:%.*]] = fadd fast <2 x float> [[TMP31]], [[TMP17]]
1081eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP34]] = fadd fast <2 x float> [[TMP32]], [[TMP25]]
1082eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP35]] = fadd fast <2 x float> [[TMP33]], [[TMP29]]
1083eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
1084eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP36:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1085eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP36]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
1086eb052f6bSPhilip Reames; UNROLL:       middle.block:
1087eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BIN_RDX:%.*]] = fadd fast <2 x float> [[TMP35]], [[TMP34]]
1088eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP37:%.*]] = call fast float @llvm.vector.reduce.fadd.v2f32(float -0.000000e+00, <2 x float> [[BIN_RDX]])
1089eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
1090eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
1091eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
1092eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
1093eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_MERGE_RDX:%.*]] = phi float [ [[TMP37]], [[MIDDLE_BLOCK]] ], [ 0.000000e+00, [[ENTRY]] ]
1094eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
1095eb052f6bSPhilip Reames; UNROLL:       for.body:
1096eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[FOR_BODY]] ]
1097eb052f6bSPhilip Reames; UNROLL-NEXT:    [[S:%.*]] = phi float [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[TMP44:%.*]], [[FOR_BODY]] ]
1098eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP38:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[I]]
1099eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP39:%.*]] = load float, float* [[TMP38]], align 4
1100eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP40:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[I]]
1101eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP41:%.*]] = load float, float* [[TMP40]], align 4
1102eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP42:%.*]] = fadd fast float [[S]], 1.000000e+00
1103eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP43:%.*]] = fadd fast float [[TMP42]], [[TMP39]]
1104eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP44]] = fadd fast float [[TMP43]], [[TMP41]]
1105eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 8
1106eb052f6bSPhilip Reames; UNROLL-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
1107eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP14:![0-9]+]]
1108eb052f6bSPhilip Reames; UNROLL:       for.end:
1109eb052f6bSPhilip Reames; UNROLL-NEXT:    [[S_LCSSA:%.*]] = phi float [ [[TMP44]], [[FOR_BODY]] ], [ [[TMP37]], [[MIDDLE_BLOCK]] ]
1110eb052f6bSPhilip Reames; UNROLL-NEXT:    ret float [[S_LCSSA]]
1111eb052f6bSPhilip Reames;
1112eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @scalarize_induction_variable_02(
1113eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
1114eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 8)
1115eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add nsw i64 [[SMAX]], -1
1116eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = lshr i64 [[TMP0]], 3
1117eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
1118eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], 4
1119eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1120eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
1121eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 4
1122eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
1123eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IND_END:%.*]] = mul i64 [[N_VEC]], 8
1124eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
1125eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
1126eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1127eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_PHI:%.*]] = phi <2 x float> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP35:%.*]], [[VECTOR_BODY]] ]
1128eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_PHI1:%.*]] = phi <2 x float> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP36:%.*]], [[VECTOR_BODY]] ]
1129eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[OFFSET_IDX:%.*]] = mul i64 [[INDEX]], 8
1130eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = add i64 [[OFFSET_IDX]], 0
1131eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = add i64 [[OFFSET_IDX]], 8
1132eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = add i64 [[OFFSET_IDX]], 16
1133eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = add i64 [[OFFSET_IDX]], 24
1134eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = getelementptr inbounds float, float* [[A:%.*]], i64 [[TMP3]]
1135eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP4]]
1136eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP5]]
1137eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP6]]
1138eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = load float, float* [[TMP7]], align 4
1139eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = load float, float* [[TMP8]], align 4
1140eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = insertelement <2 x float> poison, float [[TMP11]], i32 0
1141eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = insertelement <2 x float> [[TMP13]], float [[TMP12]], i32 1
1142eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = load float, float* [[TMP9]], align 4
1143eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP16:%.*]] = load float, float* [[TMP10]], align 4
1144eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP17:%.*]] = insertelement <2 x float> poison, float [[TMP15]], i32 0
1145eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP18:%.*]] = insertelement <2 x float> [[TMP17]], float [[TMP16]], i32 1
1146eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP19:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 [[TMP3]]
1147eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP20:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[TMP4]]
1148eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP21:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[TMP5]]
1149eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP22:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[TMP6]]
1150eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP23:%.*]] = load float, float* [[TMP19]], align 4
1151eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP24:%.*]] = load float, float* [[TMP20]], align 4
1152eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP25:%.*]] = insertelement <2 x float> poison, float [[TMP23]], i32 0
1153eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP26:%.*]] = insertelement <2 x float> [[TMP25]], float [[TMP24]], i32 1
1154eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP27:%.*]] = load float, float* [[TMP21]], align 4
1155eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP28:%.*]] = load float, float* [[TMP22]], align 4
1156eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP29:%.*]] = insertelement <2 x float> poison, float [[TMP27]], i32 0
1157eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP30:%.*]] = insertelement <2 x float> [[TMP29]], float [[TMP28]], i32 1
1158eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP31:%.*]] = fadd fast <2 x float> [[VEC_PHI]], <float 1.000000e+00, float 1.000000e+00>
1159eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP32:%.*]] = fadd fast <2 x float> [[VEC_PHI1]], <float 1.000000e+00, float 1.000000e+00>
1160eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP33:%.*]] = fadd fast <2 x float> [[TMP31]], [[TMP14]]
1161eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP34:%.*]] = fadd fast <2 x float> [[TMP32]], [[TMP18]]
1162eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP35]] = fadd fast <2 x float> [[TMP33]], [[TMP26]]
1163eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP36]] = fadd fast <2 x float> [[TMP34]], [[TMP30]]
1164eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
1165eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP37:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1166eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP37]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
1167eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
1168eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BIN_RDX:%.*]] = fadd fast <2 x float> [[TMP36]], [[TMP35]]
1169eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP38:%.*]] = call fast float @llvm.vector.reduce.fadd.v2f32(float -0.000000e+00, <2 x float> [[BIN_RDX]])
1170eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
1171eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
1172eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
1173eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
1174eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_MERGE_RDX:%.*]] = phi float [ 0.000000e+00, [[ENTRY]] ], [ [[TMP38]], [[MIDDLE_BLOCK]] ]
1175eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
1176eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
1177eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[FOR_BODY]] ]
1178eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[S:%.*]] = phi float [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[TMP45:%.*]], [[FOR_BODY]] ]
1179eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP39:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[I]]
1180eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP40:%.*]] = load float, float* [[TMP39]], align 4
1181eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP41:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[I]]
1182eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP42:%.*]] = load float, float* [[TMP41]], align 4
1183eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP43:%.*]] = fadd fast float [[S]], 1.000000e+00
1184eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP44:%.*]] = fadd fast float [[TMP43]], [[TMP40]]
1185eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP45]] = fadd fast float [[TMP44]], [[TMP42]]
1186eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 8
1187eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
1188eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP14:![0-9]+]]
1189eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.end:
1190eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[S_LCSSA:%.*]] = phi float [ [[TMP45]], [[FOR_BODY]] ], [ [[TMP38]], [[MIDDLE_BLOCK]] ]
1191eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret float [[S_LCSSA]]
1192eb052f6bSPhilip Reames;
1193eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @scalarize_induction_variable_02(
1194eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
1195eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 8)
1196eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = add nsw i64 [[SMAX]], -1
1197eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP0]], 64
1198eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1199eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
12000af3e6a2SAndrew Wei; INTERLEAVE-NEXT:    [[TMP1:%.*]] = lshr i64 [[TMP0]], 3
12010af3e6a2SAndrew Wei; INTERLEAVE-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
1202eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_MOD_VF:%.*]] = and i64 [[TMP2]], 7
1203eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
1204eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = select i1 [[TMP3]], i64 8, i64 [[N_MOD_VF]]
1205eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = sub nsw i64 [[TMP2]], [[TMP4]]
1206eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IND_END:%.*]] = shl i64 [[N_VEC]], 3
1207eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
1208eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
1209eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1210eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_PHI:%.*]] = phi <4 x float> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP18:%.*]], [[VECTOR_BODY]] ]
1211eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_PHI1:%.*]] = phi <4 x float> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP19:%.*]], [[VECTOR_BODY]] ]
1212eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[OFFSET_IDX:%.*]] = shl i64 [[INDEX]], 3
1213eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = or i64 [[OFFSET_IDX]], 32
1214eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = getelementptr inbounds float, float* [[A:%.*]], i64 [[OFFSET_IDX]]
1215eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP7:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[TMP5]]
1216eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP8:%.*]] = bitcast float* [[TMP6]] to <32 x float>*
1217eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP9:%.*]] = bitcast float* [[TMP7]] to <32 x float>*
1218eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_VEC:%.*]] = load <32 x float>, <32 x float>* [[TMP8]], align 4
1219eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_VEC2:%.*]] = load <32 x float>, <32 x float>* [[TMP9]], align 4
1220eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[STRIDED_VEC:%.*]] = shufflevector <32 x float> [[WIDE_VEC]], <32 x float> poison, <4 x i32> <i32 0, i32 8, i32 16, i32 24>
1221eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[STRIDED_VEC3:%.*]] = shufflevector <32 x float> [[WIDE_VEC2]], <32 x float> poison, <4 x i32> <i32 0, i32 8, i32 16, i32 24>
1222eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP10:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 [[OFFSET_IDX]]
1223eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP11:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[TMP5]]
1224eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP12:%.*]] = bitcast float* [[TMP10]] to <32 x float>*
1225eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP13:%.*]] = bitcast float* [[TMP11]] to <32 x float>*
1226eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_VEC4:%.*]] = load <32 x float>, <32 x float>* [[TMP12]], align 4
1227eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_VEC5:%.*]] = load <32 x float>, <32 x float>* [[TMP13]], align 4
1228eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[STRIDED_VEC6:%.*]] = shufflevector <32 x float> [[WIDE_VEC4]], <32 x float> poison, <4 x i32> <i32 0, i32 8, i32 16, i32 24>
1229eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[STRIDED_VEC7:%.*]] = shufflevector <32 x float> [[WIDE_VEC5]], <32 x float> poison, <4 x i32> <i32 0, i32 8, i32 16, i32 24>
1230eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP14:%.*]] = fadd fast <4 x float> [[VEC_PHI]], <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>
1231eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP15:%.*]] = fadd fast <4 x float> [[VEC_PHI1]], <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>
1232eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP16:%.*]] = fadd fast <4 x float> [[TMP14]], [[STRIDED_VEC]]
1233eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP17:%.*]] = fadd fast <4 x float> [[TMP15]], [[STRIDED_VEC3]]
1234eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP18]] = fadd fast <4 x float> [[TMP16]], [[STRIDED_VEC6]]
1235eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP19]] = fadd fast <4 x float> [[TMP17]], [[STRIDED_VEC7]]
1236eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
1237eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP20:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1238eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP20]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
1239eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
1240eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BIN_RDX:%.*]] = fadd fast <4 x float> [[TMP19]], [[TMP18]]
1241eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP21:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float -0.000000e+00, <4 x float> [[BIN_RDX]])
1242eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[SCALAR_PH]]
1243eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
1244eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
1245eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_MERGE_RDX:%.*]] = phi float [ [[TMP21]], [[MIDDLE_BLOCK]] ], [ 0.000000e+00, [[ENTRY]] ]
1246eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
1247eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
1248eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[FOR_BODY]] ]
1249eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[S:%.*]] = phi float [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[TMP28:%.*]], [[FOR_BODY]] ]
1250eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP22:%.*]] = getelementptr inbounds float, float* [[A]], i64 [[I]]
1251eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP23:%.*]] = load float, float* [[TMP22]], align 4
1252eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP24:%.*]] = getelementptr inbounds float, float* [[B]], i64 [[I]]
1253eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP25:%.*]] = load float, float* [[TMP24]], align 4
1254eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP26:%.*]] = fadd fast float [[S]], 1.000000e+00
1255eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP27:%.*]] = fadd fast float [[TMP26]], [[TMP23]]
1256eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP28]] = fadd fast float [[TMP27]], [[TMP25]]
1257eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 8
1258eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
1259eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END:%.*]], !llvm.loop [[LOOP14:![0-9]+]]
1260eb052f6bSPhilip Reames; INTERLEAVE:       for.end:
1261eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret float [[TMP28]]
1262eb052f6bSPhilip Reames;
1263cee313d2SEric Christopherentry:
1264cee313d2SEric Christopher  br label %for.body
1265cee313d2SEric Christopher
1266cee313d2SEric Christopherfor.body:
1267cee313d2SEric Christopher  %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]
1268cee313d2SEric Christopher  %s = phi float [ 0.0, %entry ], [ %6, %for.body ]
1269cee313d2SEric Christopher  %0 = getelementptr inbounds float, float* %a, i64 %i
1270cee313d2SEric Christopher  %1 = load float, float* %0, align 4
1271cee313d2SEric Christopher  %2 = getelementptr inbounds float, float* %b, i64 %i
1272cee313d2SEric Christopher  %3 = load float, float* %2, align 4
1273cee313d2SEric Christopher  %4 = fadd fast float %s, 1.0
1274cee313d2SEric Christopher  %5 = fadd fast float %4, %1
1275cee313d2SEric Christopher  %6 = fadd fast float %5, %3
1276cee313d2SEric Christopher  %i.next = add nuw nsw i64 %i, 8
1277cee313d2SEric Christopher  %cond = icmp slt i64 %i.next, %n
1278cee313d2SEric Christopher  br i1 %cond, label %for.body, label %for.end
1279cee313d2SEric Christopher
1280cee313d2SEric Christopherfor.end:
1281cee313d2SEric Christopher  %s.lcssa = phi float [ %6, %for.body ]
1282cee313d2SEric Christopher  ret float %s.lcssa
1283cee313d2SEric Christopher}
1284cee313d2SEric Christopher
1285cee313d2SEric Christopher; Make sure we scalarize the step vectors used for the pointer arithmetic. We
1286cee313d2SEric Christopher; can't easily simplify vectorized step vectors. (Interleaved accesses.)
1287cee313d2SEric Christopher;
1288cee313d2SEric Christopher; for (int i = 0; i < n; ++i)
1289cee313d2SEric Christopher;   a[i].f ^= y;
1290cee313d2SEric Christopher;
1291cee313d2SEric Christopher
1292cee313d2SEric Christopher%pair.i32 = type { i32, i32 }
1293cee313d2SEric Christopherdefine void @scalarize_induction_variable_03(%pair.i32 *%p, i32 %y, i64 %n) {
1294eb052f6bSPhilip Reames; CHECK-LABEL: @scalarize_induction_variable_03(
1295eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
1296eb052f6bSPhilip Reames; CHECK-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
1297eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 2
1298eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1299eb052f6bSPhilip Reames; CHECK:       vector.ph:
1300eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[SMAX]], 2
1301eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[SMAX]], [[N_MOD_VF]]
1302eb052f6bSPhilip Reames; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[Y:%.*]], i32 0
1303eb052f6bSPhilip Reames; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
1304eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
1305eb052f6bSPhilip Reames; CHECK:       vector.body:
1306eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1307eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
1308eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[INDEX]], 1
1309eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds [[PAIR_I32:%.*]], %pair.i32* [[P:%.*]], i64 [[TMP0]], i32 1
1310eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP1]], i32 1
1311eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = load i32, i32* [[TMP2]], align 8
1312eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP5:%.*]] = load i32, i32* [[TMP3]], align 8
1313eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP6:%.*]] = insertelement <2 x i32> poison, i32 [[TMP4]], i32 0
1314eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP7:%.*]] = insertelement <2 x i32> [[TMP6]], i32 [[TMP5]], i32 1
1315eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP8:%.*]] = xor <2 x i32> [[TMP7]], [[BROADCAST_SPLAT]]
1316eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP9:%.*]] = extractelement <2 x i32> [[TMP8]], i32 0
1317eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[TMP9]], i32* [[TMP2]], align 8
1318eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP10:%.*]] = extractelement <2 x i32> [[TMP8]], i32 1
1319eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[TMP10]], i32* [[TMP3]], align 8
1320eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
1321eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1322eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP11]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP15:![0-9]+]]
1323eb052f6bSPhilip Reames; CHECK:       middle.block:
1324eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
1325eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
1326eb052f6bSPhilip Reames; CHECK:       scalar.ph:
1327eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
1328eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
1329eb052f6bSPhilip Reames; CHECK:       for.body:
1330eb052f6bSPhilip Reames; CHECK-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
1331eb052f6bSPhilip Reames; CHECK-NEXT:    [[F:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[I]], i32 1
1332eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP12:%.*]] = load i32, i32* [[F]], align 8
1333eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP13:%.*]] = xor i32 [[TMP12]], [[Y]]
1334eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[TMP13]], i32* [[F]], align 8
1335eb052f6bSPhilip Reames; CHECK-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
1336eb052f6bSPhilip Reames; CHECK-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
1337eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP16:![0-9]+]]
1338eb052f6bSPhilip Reames; CHECK:       for.end:
1339eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
1340eb052f6bSPhilip Reames;
1341eb052f6bSPhilip Reames; IND-LABEL: @scalarize_induction_variable_03(
1342eb052f6bSPhilip Reames; IND-NEXT:  entry:
1343eb052f6bSPhilip Reames; IND-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
1344eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 2
1345eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1346eb052f6bSPhilip Reames; IND:       vector.ph:
1347eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i64 [[SMAX]], 9223372036854775806
1348e6ad9ef4SPhilip Reames; IND-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[Y:%.*]], i64 0
1349eb052f6bSPhilip Reames; IND-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
1350eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
1351eb052f6bSPhilip Reames; IND:       vector.body:
1352eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1353eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = or i64 [[INDEX]], 1
1354eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = getelementptr inbounds [[PAIR_I32:%.*]], %pair.i32* [[P:%.*]], i64 [[INDEX]], i32 1
1355eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP0]], i32 1
1356eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = load i32, i32* [[TMP1]], align 8
1357eb052f6bSPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = load i32, i32* [[TMP2]], align 8
1358e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP5:%.*]] = insertelement <2 x i32> poison, i32 [[TMP3]], i64 0
1359e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP6:%.*]] = insertelement <2 x i32> [[TMP5]], i32 [[TMP4]], i64 1
1360eb052f6bSPhilip Reames; IND-NEXT:    [[TMP7:%.*]] = xor <2 x i32> [[TMP6]], [[BROADCAST_SPLAT]]
1361e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP8:%.*]] = extractelement <2 x i32> [[TMP7]], i64 0
1362eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[TMP8]], i32* [[TMP1]], align 8
1363e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP9:%.*]] = extractelement <2 x i32> [[TMP7]], i64 1
1364eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[TMP9]], i32* [[TMP2]], align 8
1365eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
1366eb052f6bSPhilip Reames; IND-NEXT:    [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1367eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP15:![0-9]+]]
1368eb052f6bSPhilip Reames; IND:       middle.block:
1369eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
1370eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
1371eb052f6bSPhilip Reames; IND:       scalar.ph:
1372eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
1373eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
1374eb052f6bSPhilip Reames; IND:       for.body:
1375eb052f6bSPhilip Reames; IND-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
1376eb052f6bSPhilip Reames; IND-NEXT:    [[F:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[I]], i32 1
1377eb052f6bSPhilip Reames; IND-NEXT:    [[TMP11:%.*]] = load i32, i32* [[F]], align 8
1378eb052f6bSPhilip Reames; IND-NEXT:    [[TMP12:%.*]] = xor i32 [[TMP11]], [[Y]]
1379eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[TMP12]], i32* [[F]], align 8
1380eb052f6bSPhilip Reames; IND-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
1381eb052f6bSPhilip Reames; IND-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
1382eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP16:![0-9]+]]
1383eb052f6bSPhilip Reames; IND:       for.end:
1384eb052f6bSPhilip Reames; IND-NEXT:    ret void
1385eb052f6bSPhilip Reames;
1386eb052f6bSPhilip Reames; UNROLL-LABEL: @scalarize_induction_variable_03(
1387eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
1388eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
1389eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 4
1390eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1391eb052f6bSPhilip Reames; UNROLL:       vector.ph:
1392eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i64 [[SMAX]], 9223372036854775804
1393e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[Y:%.*]], i64 0
1394eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
1395e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <2 x i32> poison, i32 [[Y]], i64 0
1396eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLAT2:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT1]], <2 x i32> poison, <2 x i32> zeroinitializer
1397eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
1398eb052f6bSPhilip Reames; UNROLL:       vector.body:
1399eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1400eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = or i64 [[INDEX]], 1
1401eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = or i64 [[INDEX]], 2
1402eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = or i64 [[INDEX]], 3
1403eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = getelementptr inbounds [[PAIR_I32:%.*]], %pair.i32* [[P:%.*]], i64 [[INDEX]], i32 1
1404eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP0]], i32 1
1405eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP1]], i32 1
1406eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP6:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP2]], i32 1
1407eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP7:%.*]] = load i32, i32* [[TMP3]], align 8
1408eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP8:%.*]] = load i32, i32* [[TMP4]], align 8
1409e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP9:%.*]] = insertelement <2 x i32> poison, i32 [[TMP7]], i64 0
1410e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP10:%.*]] = insertelement <2 x i32> [[TMP9]], i32 [[TMP8]], i64 1
1411eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP11:%.*]] = load i32, i32* [[TMP5]], align 8
1412eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP12:%.*]] = load i32, i32* [[TMP6]], align 8
1413e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP13:%.*]] = insertelement <2 x i32> poison, i32 [[TMP11]], i64 0
1414e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP14:%.*]] = insertelement <2 x i32> [[TMP13]], i32 [[TMP12]], i64 1
1415eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP15:%.*]] = xor <2 x i32> [[TMP10]], [[BROADCAST_SPLAT]]
1416eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP16:%.*]] = xor <2 x i32> [[TMP14]], [[BROADCAST_SPLAT2]]
1417e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP17:%.*]] = extractelement <2 x i32> [[TMP15]], i64 0
1418eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[TMP17]], i32* [[TMP3]], align 8
1419e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP18:%.*]] = extractelement <2 x i32> [[TMP15]], i64 1
1420eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[TMP18]], i32* [[TMP4]], align 8
1421e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP19:%.*]] = extractelement <2 x i32> [[TMP16]], i64 0
1422eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[TMP19]], i32* [[TMP5]], align 8
1423e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP20:%.*]] = extractelement <2 x i32> [[TMP16]], i64 1
1424eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[TMP20]], i32* [[TMP6]], align 8
1425eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
1426eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP21:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1427eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP21]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP15:![0-9]+]]
1428eb052f6bSPhilip Reames; UNROLL:       middle.block:
1429eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
1430eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
1431eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
1432eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
1433eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
1434eb052f6bSPhilip Reames; UNROLL:       for.body:
1435eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
1436eb052f6bSPhilip Reames; UNROLL-NEXT:    [[F:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[I]], i32 1
1437eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP22:%.*]] = load i32, i32* [[F]], align 8
1438eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP23:%.*]] = xor i32 [[TMP22]], [[Y]]
1439eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[TMP23]], i32* [[F]], align 8
1440eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
1441eb052f6bSPhilip Reames; UNROLL-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
1442eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP16:![0-9]+]]
1443eb052f6bSPhilip Reames; UNROLL:       for.end:
1444eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
1445eb052f6bSPhilip Reames;
1446eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @scalarize_induction_variable_03(
1447eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
1448eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
1449eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 4
1450eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1451eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
1452eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[SMAX]], 4
1453eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i64 [[SMAX]], [[N_MOD_VF]]
1454eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[Y:%.*]], i32 0
1455eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
1456eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <2 x i32> poison, i32 [[Y]], i32 0
1457eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLAT2:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT1]], <2 x i32> poison, <2 x i32> zeroinitializer
1458eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
1459eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
1460eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1461eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
1462eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = add i64 [[INDEX]], 1
1463eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = add i64 [[INDEX]], 2
1464eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = add i64 [[INDEX]], 3
1465eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = getelementptr inbounds [[PAIR_I32:%.*]], %pair.i32* [[P:%.*]], i64 [[TMP0]], i32 1
1466eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP1]], i32 1
1467eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP2]], i32 1
1468eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP3]], i32 1
1469eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = load i32, i32* [[TMP4]], align 8
1470eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = load i32, i32* [[TMP5]], align 8
1471eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = insertelement <2 x i32> poison, i32 [[TMP8]], i32 0
1472eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = insertelement <2 x i32> [[TMP10]], i32 [[TMP9]], i32 1
1473eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = load i32, i32* [[TMP6]], align 8
1474eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = load i32, i32* [[TMP7]], align 8
1475eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = insertelement <2 x i32> poison, i32 [[TMP12]], i32 0
1476eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = insertelement <2 x i32> [[TMP14]], i32 [[TMP13]], i32 1
1477eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP16:%.*]] = xor <2 x i32> [[TMP11]], [[BROADCAST_SPLAT]]
1478eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP17:%.*]] = xor <2 x i32> [[TMP15]], [[BROADCAST_SPLAT2]]
1479eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP18:%.*]] = extractelement <2 x i32> [[TMP16]], i32 0
1480eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[TMP18]], i32* [[TMP4]], align 8
1481eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP19:%.*]] = extractelement <2 x i32> [[TMP16]], i32 1
1482eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[TMP19]], i32* [[TMP5]], align 8
1483eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP20:%.*]] = extractelement <2 x i32> [[TMP17]], i32 0
1484eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[TMP20]], i32* [[TMP6]], align 8
1485eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP21:%.*]] = extractelement <2 x i32> [[TMP17]], i32 1
1486eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[TMP21]], i32* [[TMP7]], align 8
1487eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
1488eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP22:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1489eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP22]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP15:![0-9]+]]
1490eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
1491eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
1492eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
1493eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
1494eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
1495eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
1496eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
1497eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
1498eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[F:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[I]], i32 1
1499eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP23:%.*]] = load i32, i32* [[F]], align 8
1500eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP24:%.*]] = xor i32 [[TMP23]], [[Y]]
1501eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[TMP24]], i32* [[F]], align 8
1502eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
1503eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
1504eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP16:![0-9]+]]
1505eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.end:
1506eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
1507eb052f6bSPhilip Reames;
1508eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @scalarize_induction_variable_03(
1509eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
1510eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
1511eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 9
1512eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1513eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
1514eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_MOD_VF:%.*]] = and i64 [[SMAX]], 7
1515eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
1516eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = select i1 [[TMP0]], i64 8, i64 [[N_MOD_VF]]
1517eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = sub nsw i64 [[SMAX]], [[TMP1]]
1518e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[Y:%.*]], i64 0
1519eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
1520e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLATINSERT3:%.*]] = insertelement <4 x i32> poison, i32 [[Y]], i64 0
1521eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLAT4:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT3]], <4 x i32> poison, <4 x i32> zeroinitializer
1522eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
1523eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
1524eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1525eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = or i64 [[INDEX]], 1
1526eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = or i64 [[INDEX]], 2
1527eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = or i64 [[INDEX]], 3
1528eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = or i64 [[INDEX]], 4
1529eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = or i64 [[INDEX]], 5
1530eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP7:%.*]] = or i64 [[INDEX]], 6
1531eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP8:%.*]] = or i64 [[INDEX]], 7
1532eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP9:%.*]] = getelementptr inbounds [[PAIR_I32:%.*]], %pair.i32* [[P:%.*]], i64 [[INDEX]], i32 1
1533eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP10:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP2]], i32 1
1534eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP11:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP3]], i32 1
1535eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP12:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP4]], i32 1
1536eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP13:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP5]], i32 1
1537eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP14:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP6]], i32 1
1538eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP15:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP7]], i32 1
1539eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP16:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP8]], i32 1
1540eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP17:%.*]] = bitcast i32* [[TMP9]] to <8 x i32>*
1541eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP18:%.*]] = bitcast i32* [[TMP13]] to <8 x i32>*
1542eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_VEC:%.*]] = load <8 x i32>, <8 x i32>* [[TMP17]], align 8
1543eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_VEC1:%.*]] = load <8 x i32>, <8 x i32>* [[TMP18]], align 8
1544eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[STRIDED_VEC:%.*]] = shufflevector <8 x i32> [[WIDE_VEC]], <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
1545eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[STRIDED_VEC2:%.*]] = shufflevector <8 x i32> [[WIDE_VEC1]], <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
1546eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP19:%.*]] = xor <4 x i32> [[STRIDED_VEC]], [[BROADCAST_SPLAT]]
1547eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP20:%.*]] = xor <4 x i32> [[STRIDED_VEC2]], [[BROADCAST_SPLAT4]]
1548e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP21:%.*]] = extractelement <4 x i32> [[TMP19]], i64 0
1549eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP21]], i32* [[TMP9]], align 8
1550e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP22:%.*]] = extractelement <4 x i32> [[TMP19]], i64 1
1551eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP22]], i32* [[TMP10]], align 8
1552e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP23:%.*]] = extractelement <4 x i32> [[TMP19]], i64 2
1553eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP23]], i32* [[TMP11]], align 8
1554e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP24:%.*]] = extractelement <4 x i32> [[TMP19]], i64 3
1555eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP24]], i32* [[TMP12]], align 8
1556e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP25:%.*]] = extractelement <4 x i32> [[TMP20]], i64 0
1557eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP25]], i32* [[TMP13]], align 8
1558e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP26:%.*]] = extractelement <4 x i32> [[TMP20]], i64 1
1559eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP26]], i32* [[TMP14]], align 8
1560e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP27:%.*]] = extractelement <4 x i32> [[TMP20]], i64 2
1561eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP27]], i32* [[TMP15]], align 8
1562e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP28:%.*]] = extractelement <4 x i32> [[TMP20]], i64 3
1563eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP28]], i32* [[TMP16]], align 8
1564eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
1565eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP29:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1566eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP29]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP15:![0-9]+]]
1567eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
1568eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[SCALAR_PH]]
1569eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
1570eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
1571eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
1572eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
1573eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
1574eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[F:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[I]], i32 1
1575eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP30:%.*]] = load i32, i32* [[F]], align 8
1576eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP31:%.*]] = xor i32 [[TMP30]], [[Y]]
1577eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP31]], i32* [[F]], align 8
1578eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
1579eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
1580eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END:%.*]], !llvm.loop [[LOOP16:![0-9]+]]
1581eb052f6bSPhilip Reames; INTERLEAVE:       for.end:
1582eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
1583eb052f6bSPhilip Reames;
1584cee313d2SEric Christopherentry:
1585cee313d2SEric Christopher  br label %for.body
1586cee313d2SEric Christopher
1587cee313d2SEric Christopherfor.body:
1588cee313d2SEric Christopher  %i  = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
1589cee313d2SEric Christopher  %f = getelementptr inbounds %pair.i32, %pair.i32* %p, i64 %i, i32 1
1590cee313d2SEric Christopher  %0 = load i32, i32* %f, align 8
1591cee313d2SEric Christopher  %1 = xor i32 %0, %y
1592cee313d2SEric Christopher  store i32 %1, i32* %f, align 8
1593cee313d2SEric Christopher  %i.next = add nuw nsw i64 %i, 1
1594cee313d2SEric Christopher  %cond = icmp slt i64 %i.next, %n
1595cee313d2SEric Christopher  br i1 %cond, label %for.body, label %for.end
1596cee313d2SEric Christopher
1597cee313d2SEric Christopherfor.end:
1598cee313d2SEric Christopher  ret void
1599cee313d2SEric Christopher}
1600cee313d2SEric Christopher
1601cee313d2SEric Christopher; Make sure we scalarize the step vectors used for the pointer arithmetic. We
1602cee313d2SEric Christopher; can't easily simplify vectorized step vectors. (Interleaved accesses.)
1603cee313d2SEric Christopher;
1604cee313d2SEric Christopher; for (int i = 0; i < n; ++i)
1605cee313d2SEric Christopher;   p[i].f = a[i * 4]
1606cee313d2SEric Christopher;
1607cee313d2SEric Christopher
1608cee313d2SEric Christopherdefine void @scalarize_induction_variable_04(i32* %a, %pair.i32* %p, i32 %n) {
1609eb052f6bSPhilip Reames; CHECK-LABEL: @scalarize_induction_variable_04(
1610eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
1611eb052f6bSPhilip Reames; CHECK-NEXT:    [[A4:%.*]] = bitcast i32* [[A:%.*]] to i8*
1612eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
1613eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
1614eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
1615eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], 2
1616eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
1617eb052f6bSPhilip Reames; CHECK:       vector.memcheck:
1618eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr [[PAIR_I32:%.*]], %pair.i32* [[P:%.*]], i64 0, i32 1
1619eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP1:%.*]] = bitcast i32* [[SCEVGEP]] to i8*
1620eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = add i32 [[N]], -1
1621eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = zext i32 [[TMP3]] to i64
1622eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP5:%.*]] = add nuw nsw i64 [[TMP4]], 1
1623eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP2:%.*]] = getelementptr [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP5]]
1624eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP23:%.*]] = bitcast %pair.i32* [[SCEVGEP2]] to i8*
1625eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP6:%.*]] = shl nuw nsw i64 [[TMP4]], 2
1626eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP7:%.*]] = add nuw nsw i64 [[TMP6]], 1
1627eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP5:%.*]] = getelementptr i32, i32* [[A]], i64 [[TMP7]]
1628eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCEVGEP56:%.*]] = bitcast i32* [[SCEVGEP5]] to i8*
1629eb052f6bSPhilip Reames; CHECK-NEXT:    [[BOUND0:%.*]] = icmp ult i8* [[SCEVGEP1]], [[SCEVGEP56]]
1630eb052f6bSPhilip Reames; CHECK-NEXT:    [[BOUND1:%.*]] = icmp ult i8* [[A4]], [[SCEVGEP23]]
1631eb052f6bSPhilip Reames; CHECK-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
1632eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
1633eb052f6bSPhilip Reames; CHECK:       vector.ph:
1634eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 2
1635eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
1636eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
1637eb052f6bSPhilip Reames; CHECK:       vector.body:
1638eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1639eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <2 x i64> [ <i64 0, i64 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
1640eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP8:%.*]] = add i64 [[INDEX]], 0
1641eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP9:%.*]] = add i64 [[INDEX]], 1
1642eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP10:%.*]] = shl nsw <2 x i64> [[VEC_IND]], <i64 2, i64 2>
1643eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP11:%.*]] = extractelement <2 x i64> [[TMP10]], i32 0
1644eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP12:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP11]]
1645eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP13:%.*]] = extractelement <2 x i64> [[TMP10]], i32 1
1646eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP14:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP13]]
1647eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP15:%.*]] = load i32, i32* [[TMP12]], align 1, !alias.scope !17
1648eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP16:%.*]] = load i32, i32* [[TMP14]], align 1, !alias.scope !17
1649eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP17:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP8]], i32 1
1650eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP18:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP9]], i32 1
1651eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[TMP15]], i32* [[TMP17]], align 1, !alias.scope !20, !noalias !17
1652eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[TMP16]], i32* [[TMP18]], align 1, !alias.scope !20, !noalias !17
1653eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
1654eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i64> [[VEC_IND]], <i64 2, i64 2>
1655eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP19:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1656eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP19]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP22:![0-9]+]]
1657eb052f6bSPhilip Reames; CHECK:       middle.block:
1658eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
1659eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
1660eb052f6bSPhilip Reames; CHECK:       scalar.ph:
1661eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
1662eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
1663eb052f6bSPhilip Reames; CHECK:       for.body:
1664eb052f6bSPhilip Reames; CHECK-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
1665eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP20:%.*]] = shl nsw i64 [[I]], 2
1666eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP21:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP20]]
1667eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP22:%.*]] = load i32, i32* [[TMP21]], align 1
1668eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP23:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[I]], i32 1
1669eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[TMP22]], i32* [[TMP23]], align 1
1670eb052f6bSPhilip Reames; CHECK-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
1671eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP24:%.*]] = trunc i64 [[I_NEXT]] to i32
1672eb052f6bSPhilip Reames; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 [[TMP24]], [[N]]
1673eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[COND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP23:![0-9]+]]
1674eb052f6bSPhilip Reames; CHECK:       for.end:
1675eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
1676eb052f6bSPhilip Reames;
1677eb052f6bSPhilip Reames; IND-LABEL: @scalarize_induction_variable_04(
1678eb052f6bSPhilip Reames; IND-NEXT:  entry:
1679eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
1680eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
1681eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
1682eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp eq i32 [[TMP0]], 0
1683eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
1684eb052f6bSPhilip Reames; IND:       vector.memcheck:
1685eb052f6bSPhilip Reames; IND-NEXT:    [[SCEVGEP:%.*]] = getelementptr [[PAIR_I32:%.*]], %pair.i32* [[P:%.*]], i64 0, i32 1
1686eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = add i32 [[N]], -1
1687eb052f6bSPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = zext i32 [[TMP3]] to i64
1688eb052f6bSPhilip Reames; IND-NEXT:    [[TMP5:%.*]] = add nuw nsw i64 [[TMP4]], 1
1689eb052f6bSPhilip Reames; IND-NEXT:    [[TMP6:%.*]] = shl nuw nsw i64 [[TMP4]], 2
1690eb052f6bSPhilip Reames; IND-NEXT:    [[TMP7:%.*]] = or i64 [[TMP6]], 1
1691eb052f6bSPhilip Reames; IND-NEXT:    [[SCEVGEP5:%.*]] = getelementptr i32, i32* [[A:%.*]], i64 [[TMP7]]
1692eb052f6bSPhilip Reames; IND-NEXT:    [[BOUND0:%.*]] = icmp ult i32* [[SCEVGEP]], [[SCEVGEP5]]
1693eb052f6bSPhilip Reames; IND-NEXT:    [[TMP8:%.*]] = getelementptr [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP5]], i32 0
1694eb052f6bSPhilip Reames; IND-NEXT:    [[BOUND1:%.*]] = icmp ugt i32* [[TMP8]], [[A]]
1695eb052f6bSPhilip Reames; IND-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
1696eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
1697eb052f6bSPhilip Reames; IND:       vector.ph:
1698eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i64 [[TMP2]], 8589934590
1699eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
1700eb052f6bSPhilip Reames; IND:       vector.body:
1701eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1702eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_IND:%.*]] = phi <2 x i64> [ <i64 0, i64 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
1703eb052f6bSPhilip Reames; IND-NEXT:    [[TMP9:%.*]] = or i64 [[INDEX]], 1
1704eb052f6bSPhilip Reames; IND-NEXT:    [[TMP10:%.*]] = shl nsw <2 x i64> [[VEC_IND]], <i64 2, i64 2>
1705e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP11:%.*]] = extractelement <2 x i64> [[TMP10]], i64 0
1706eb052f6bSPhilip Reames; IND-NEXT:    [[TMP12:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP11]]
1707e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP13:%.*]] = extractelement <2 x i64> [[TMP10]], i64 1
1708eb052f6bSPhilip Reames; IND-NEXT:    [[TMP14:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP13]]
1709eb052f6bSPhilip Reames; IND-NEXT:    [[TMP15:%.*]] = load i32, i32* [[TMP12]], align 1, !alias.scope !17
1710eb052f6bSPhilip Reames; IND-NEXT:    [[TMP16:%.*]] = load i32, i32* [[TMP14]], align 1, !alias.scope !17
1711eb052f6bSPhilip Reames; IND-NEXT:    [[TMP17:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[INDEX]], i32 1
1712eb052f6bSPhilip Reames; IND-NEXT:    [[TMP18:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP9]], i32 1
1713eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[TMP15]], i32* [[TMP17]], align 1, !alias.scope !20, !noalias !17
1714eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[TMP16]], i32* [[TMP18]], align 1, !alias.scope !20, !noalias !17
1715eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
1716eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i64> [[VEC_IND]], <i64 2, i64 2>
1717eb052f6bSPhilip Reames; IND-NEXT:    [[TMP19:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1718eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP19]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP22:![0-9]+]]
1719eb052f6bSPhilip Reames; IND:       middle.block:
1720eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
1721eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
1722eb052f6bSPhilip Reames; IND:       scalar.ph:
1723eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
1724eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
1725eb052f6bSPhilip Reames; IND:       for.body:
1726eb052f6bSPhilip Reames; IND-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
1727eb052f6bSPhilip Reames; IND-NEXT:    [[TMP20:%.*]] = shl nsw i64 [[I]], 2
1728eb052f6bSPhilip Reames; IND-NEXT:    [[TMP21:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP20]]
1729eb052f6bSPhilip Reames; IND-NEXT:    [[TMP22:%.*]] = load i32, i32* [[TMP21]], align 1
1730eb052f6bSPhilip Reames; IND-NEXT:    [[TMP23:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[I]], i32 1
1731eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[TMP22]], i32* [[TMP23]], align 1
1732eb052f6bSPhilip Reames; IND-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
1733eb052f6bSPhilip Reames; IND-NEXT:    [[TMP24:%.*]] = trunc i64 [[I_NEXT]] to i32
1734eb052f6bSPhilip Reames; IND-NEXT:    [[COND:%.*]] = icmp eq i32 [[TMP24]], [[N]]
1735eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[COND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP23:![0-9]+]]
1736eb052f6bSPhilip Reames; IND:       for.end:
1737eb052f6bSPhilip Reames; IND-NEXT:    ret void
1738eb052f6bSPhilip Reames;
1739eb052f6bSPhilip Reames; UNROLL-LABEL: @scalarize_induction_variable_04(
1740eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
1741eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
1742eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
1743eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
1744eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 3
1745eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
1746eb052f6bSPhilip Reames; UNROLL:       vector.memcheck:
1747eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SCEVGEP:%.*]] = getelementptr [[PAIR_I32:%.*]], %pair.i32* [[P:%.*]], i64 0, i32 1
1748eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = add i32 [[N]], -1
1749eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = zext i32 [[TMP3]] to i64
1750eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = add nuw nsw i64 [[TMP4]], 1
1751eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP6:%.*]] = shl nuw nsw i64 [[TMP4]], 2
1752eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP7:%.*]] = or i64 [[TMP6]], 1
1753eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SCEVGEP5:%.*]] = getelementptr i32, i32* [[A:%.*]], i64 [[TMP7]]
1754eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BOUND0:%.*]] = icmp ult i32* [[SCEVGEP]], [[SCEVGEP5]]
1755eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP8:%.*]] = getelementptr [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP5]], i32 0
1756eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BOUND1:%.*]] = icmp ugt i32* [[TMP8]], [[A]]
1757eb052f6bSPhilip Reames; UNROLL-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
1758eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
1759eb052f6bSPhilip Reames; UNROLL:       vector.ph:
1760eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i64 [[TMP2]], 8589934588
1761eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
1762eb052f6bSPhilip Reames; UNROLL:       vector.body:
1763eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1764eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i64> [ <i64 0, i64 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
1765eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP9:%.*]] = or i64 [[INDEX]], 1
1766eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP10:%.*]] = or i64 [[INDEX]], 2
1767eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP11:%.*]] = or i64 [[INDEX]], 3
1768eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP12:%.*]] = shl nsw <2 x i64> [[VEC_IND]], <i64 2, i64 2>
1769eb052f6bSPhilip Reames; UNROLL-NEXT:    [[STEP_ADD:%.*]] = shl <2 x i64> [[VEC_IND]], <i64 2, i64 2>
1770eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP13:%.*]] = add <2 x i64> [[STEP_ADD]], <i64 8, i64 8>
1771e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP14:%.*]] = extractelement <2 x i64> [[TMP12]], i64 0
1772eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP15:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP14]]
1773e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP16:%.*]] = extractelement <2 x i64> [[TMP12]], i64 1
1774eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP17:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP16]]
1775e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP18:%.*]] = extractelement <2 x i64> [[TMP13]], i64 0
1776eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP19:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP18]]
1777e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP20:%.*]] = extractelement <2 x i64> [[TMP13]], i64 1
1778eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP21:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP20]]
1779eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP22:%.*]] = load i32, i32* [[TMP15]], align 1, !alias.scope !17
1780eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP23:%.*]] = load i32, i32* [[TMP17]], align 1, !alias.scope !17
1781eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP24:%.*]] = load i32, i32* [[TMP19]], align 1, !alias.scope !17
1782eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP25:%.*]] = load i32, i32* [[TMP21]], align 1, !alias.scope !17
1783eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP26:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[INDEX]], i32 1
1784eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP27:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP9]], i32 1
1785eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP28:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP10]], i32 1
1786eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP29:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP11]], i32 1
1787eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[TMP22]], i32* [[TMP26]], align 1, !alias.scope !20, !noalias !17
1788eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[TMP23]], i32* [[TMP27]], align 1, !alias.scope !20, !noalias !17
1789eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[TMP24]], i32* [[TMP28]], align 1, !alias.scope !20, !noalias !17
1790eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[TMP25]], i32* [[TMP29]], align 1, !alias.scope !20, !noalias !17
1791eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
1792eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i64> [[VEC_IND]], <i64 4, i64 4>
1793eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP30:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1794eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP30]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP22:![0-9]+]]
1795eb052f6bSPhilip Reames; UNROLL:       middle.block:
1796eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
1797eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
1798eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
1799eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
1800eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
1801eb052f6bSPhilip Reames; UNROLL:       for.body:
1802eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
1803eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP31:%.*]] = shl nsw i64 [[I]], 2
1804eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP32:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP31]]
1805eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP33:%.*]] = load i32, i32* [[TMP32]], align 1
1806eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP34:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[I]], i32 1
1807eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[TMP33]], i32* [[TMP34]], align 1
1808eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
1809eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP35:%.*]] = trunc i64 [[I_NEXT]] to i32
1810eb052f6bSPhilip Reames; UNROLL-NEXT:    [[COND:%.*]] = icmp eq i32 [[TMP35]], [[N]]
1811eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[COND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP23:![0-9]+]]
1812eb052f6bSPhilip Reames; UNROLL:       for.end:
1813eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
1814eb052f6bSPhilip Reames;
1815eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @scalarize_induction_variable_04(
1816eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
1817eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[A4:%.*]] = bitcast i32* [[A:%.*]] to i8*
1818eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
1819eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
1820eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
1821eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], 4
1822eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
1823eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.memcheck:
1824eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP:%.*]] = getelementptr [[PAIR_I32:%.*]], %pair.i32* [[P:%.*]], i64 0, i32 1
1825eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP1:%.*]] = bitcast i32* [[SCEVGEP]] to i8*
1826eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = add i32 [[N]], -1
1827eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = zext i32 [[TMP3]] to i64
1828eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = add nuw nsw i64 [[TMP4]], 1
1829eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP2:%.*]] = getelementptr [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP5]]
1830eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP23:%.*]] = bitcast %pair.i32* [[SCEVGEP2]] to i8*
1831eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = shl nuw nsw i64 [[TMP4]], 2
1832eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = add nuw nsw i64 [[TMP6]], 1
1833eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP5:%.*]] = getelementptr i32, i32* [[A]], i64 [[TMP7]]
1834eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCEVGEP56:%.*]] = bitcast i32* [[SCEVGEP5]] to i8*
1835eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BOUND0:%.*]] = icmp ult i8* [[SCEVGEP1]], [[SCEVGEP56]]
1836eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BOUND1:%.*]] = icmp ult i8* [[A4]], [[SCEVGEP23]]
1837eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
1838eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
1839eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
1840eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 4
1841eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
1842eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
1843eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
1844eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1845eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i64> [ <i64 0, i64 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
1846eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[STEP_ADD:%.*]] = add <2 x i64> [[VEC_IND]], <i64 2, i64 2>
1847eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = add i64 [[INDEX]], 0
1848eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = add i64 [[INDEX]], 1
1849eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = add i64 [[INDEX]], 2
1850eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = add i64 [[INDEX]], 3
1851eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = shl nsw <2 x i64> [[VEC_IND]], <i64 2, i64 2>
1852eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = shl nsw <2 x i64> [[STEP_ADD]], <i64 2, i64 2>
1853eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = extractelement <2 x i64> [[TMP12]], i32 0
1854eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP14]]
1855eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP16:%.*]] = extractelement <2 x i64> [[TMP12]], i32 1
1856eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP17:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP16]]
1857eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP18:%.*]] = extractelement <2 x i64> [[TMP13]], i32 0
1858eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP19:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP18]]
1859eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP20:%.*]] = extractelement <2 x i64> [[TMP13]], i32 1
1860eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP21:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP20]]
1861eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP22:%.*]] = load i32, i32* [[TMP15]], align 1, !alias.scope !17
1862eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP23:%.*]] = load i32, i32* [[TMP17]], align 1, !alias.scope !17
1863eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP24:%.*]] = load i32, i32* [[TMP19]], align 1, !alias.scope !17
1864eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP25:%.*]] = load i32, i32* [[TMP21]], align 1, !alias.scope !17
1865eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP26:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP8]], i32 1
1866eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP27:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP9]], i32 1
1867eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP28:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP10]], i32 1
1868eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP29:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP11]], i32 1
1869eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[TMP22]], i32* [[TMP26]], align 1, !alias.scope !20, !noalias !17
1870eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[TMP23]], i32* [[TMP27]], align 1, !alias.scope !20, !noalias !17
1871eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[TMP24]], i32* [[TMP28]], align 1, !alias.scope !20, !noalias !17
1872eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[TMP25]], i32* [[TMP29]], align 1, !alias.scope !20, !noalias !17
1873eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
1874eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i64> [[STEP_ADD]], <i64 2, i64 2>
1875eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP30:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1876eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP30]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP22:![0-9]+]]
1877eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
1878eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
1879eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
1880eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
1881eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
1882eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
1883eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
1884eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
1885eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP31:%.*]] = shl nsw i64 [[I]], 2
1886eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP32:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP31]]
1887eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP33:%.*]] = load i32, i32* [[TMP32]], align 1
1888eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP34:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[I]], i32 1
1889eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[TMP33]], i32* [[TMP34]], align 1
1890eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
1891eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP35:%.*]] = trunc i64 [[I_NEXT]] to i32
1892eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[COND:%.*]] = icmp eq i32 [[TMP35]], [[N]]
1893eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[COND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP23:![0-9]+]]
1894eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.end:
1895eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
1896eb052f6bSPhilip Reames;
1897eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @scalarize_induction_variable_04(
1898eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
1899eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
1900eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
1901eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
1902eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 8
1903eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
1904eb052f6bSPhilip Reames; INTERLEAVE:       vector.memcheck:
1905eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SCEVGEP:%.*]] = getelementptr [[PAIR_I32:%.*]], %pair.i32* [[P:%.*]], i64 0, i32 1
1906eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = add i32 [[N]], -1
1907eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = zext i32 [[TMP3]] to i64
1908eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = add nuw nsw i64 [[TMP4]], 1
1909eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = shl nuw nsw i64 [[TMP4]], 2
1910eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP7:%.*]] = or i64 [[TMP6]], 1
1911eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SCEVGEP5:%.*]] = getelementptr i32, i32* [[A:%.*]], i64 [[TMP7]]
1912eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BOUND0:%.*]] = icmp ult i32* [[SCEVGEP]], [[SCEVGEP5]]
1913eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP8:%.*]] = getelementptr [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP5]], i32 0
1914eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BOUND1:%.*]] = icmp ugt i32* [[TMP8]], [[A]]
1915eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
1916eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
1917eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
1918eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_MOD_VF:%.*]] = and i64 [[TMP2]], 7
1919eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP9:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
1920eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP10:%.*]] = select i1 [[TMP9]], i64 8, i64 [[N_MOD_VF]]
1921eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = sub nsw i64 [[TMP2]], [[TMP10]]
1922eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
1923eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
1924eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
1925eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP11:%.*]] = or i64 [[INDEX]], 1
1926eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP12:%.*]] = or i64 [[INDEX]], 2
1927eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP13:%.*]] = or i64 [[INDEX]], 3
1928eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP14:%.*]] = or i64 [[INDEX]], 4
1929eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP15:%.*]] = or i64 [[INDEX]], 5
1930eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP16:%.*]] = or i64 [[INDEX]], 6
1931eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP17:%.*]] = or i64 [[INDEX]], 7
1932eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP18:%.*]] = shl nsw i64 [[INDEX]], 2
1933eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP19:%.*]] = shl nsw i64 [[TMP14]], 2
1934eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP20:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP18]]
1935eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP21:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP19]]
1936eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP22:%.*]] = bitcast i32* [[TMP20]] to <16 x i32>*
1937eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP23:%.*]] = bitcast i32* [[TMP21]] to <16 x i32>*
1938eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_VEC:%.*]] = load <16 x i32>, <16 x i32>* [[TMP22]], align 1
1939eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_VEC7:%.*]] = load <16 x i32>, <16 x i32>* [[TMP23]], align 1
1940eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP24:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[INDEX]], i32 1
1941eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP25:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP11]], i32 1
1942eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP26:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP12]], i32 1
1943eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP27:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP13]], i32 1
1944eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP28:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP14]], i32 1
1945eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP29:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP15]], i32 1
1946eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP30:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP16]], i32 1
1947eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP31:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[TMP17]], i32 1
1948e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP32:%.*]] = extractelement <16 x i32> [[WIDE_VEC]], i64 0
1949eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP32]], i32* [[TMP24]], align 1, !alias.scope !17, !noalias !20
1950e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP33:%.*]] = extractelement <16 x i32> [[WIDE_VEC]], i64 4
1951eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP33]], i32* [[TMP25]], align 1, !alias.scope !17, !noalias !20
1952e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP34:%.*]] = extractelement <16 x i32> [[WIDE_VEC]], i64 8
1953eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP34]], i32* [[TMP26]], align 1, !alias.scope !17, !noalias !20
1954e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP35:%.*]] = extractelement <16 x i32> [[WIDE_VEC]], i64 12
1955eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP35]], i32* [[TMP27]], align 1, !alias.scope !17, !noalias !20
1956e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP36:%.*]] = extractelement <16 x i32> [[WIDE_VEC7]], i64 0
1957eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP36]], i32* [[TMP28]], align 1, !alias.scope !17, !noalias !20
1958e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP37:%.*]] = extractelement <16 x i32> [[WIDE_VEC7]], i64 4
1959eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP37]], i32* [[TMP29]], align 1, !alias.scope !17, !noalias !20
1960e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP38:%.*]] = extractelement <16 x i32> [[WIDE_VEC7]], i64 8
1961eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP38]], i32* [[TMP30]], align 1, !alias.scope !17, !noalias !20
1962e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP39:%.*]] = extractelement <16 x i32> [[WIDE_VEC7]], i64 12
1963eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP39]], i32* [[TMP31]], align 1, !alias.scope !17, !noalias !20
1964eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
1965eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP40:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
1966eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP40]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP22:![0-9]+]]
1967eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
1968eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[SCALAR_PH]]
1969eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
1970eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
1971eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
1972eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
1973eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
1974eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP41:%.*]] = shl nsw i64 [[I]], 2
1975eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP42:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP41]]
1976eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP43:%.*]] = load i32, i32* [[TMP42]], align 1
1977eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP44:%.*]] = getelementptr inbounds [[PAIR_I32]], %pair.i32* [[P]], i64 [[I]], i32 1
1978eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TMP43]], i32* [[TMP44]], align 1
1979eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
1980eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP45:%.*]] = trunc i64 [[I_NEXT]] to i32
1981eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[COND:%.*]] = icmp eq i32 [[TMP45]], [[N]]
1982eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[COND]], label [[FOR_END:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP23:![0-9]+]]
1983eb052f6bSPhilip Reames; INTERLEAVE:       for.end:
1984eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
1985eb052f6bSPhilip Reames;
1986cee313d2SEric Christopherentry:
1987cee313d2SEric Christopher  br label %for.body
1988cee313d2SEric Christopher
1989cee313d2SEric Christopherfor.body:
1990cee313d2SEric Christopher  %i = phi i64 [ %i.next, %for.body ], [ 0, %entry]
1991cee313d2SEric Christopher  %0 = shl nsw i64 %i, 2
1992cee313d2SEric Christopher  %1 = getelementptr inbounds i32, i32* %a, i64 %0
1993cee313d2SEric Christopher  %2 = load i32, i32* %1, align 1
1994cee313d2SEric Christopher  %3 = getelementptr inbounds %pair.i32, %pair.i32* %p, i64 %i, i32 1
1995cee313d2SEric Christopher  store i32 %2, i32* %3, align 1
1996cee313d2SEric Christopher  %i.next = add nuw nsw i64 %i, 1
1997cee313d2SEric Christopher  %4 = trunc i64 %i.next to i32
1998cee313d2SEric Christopher  %cond = icmp eq i32 %4, %n
1999cee313d2SEric Christopher  br i1 %cond, label %for.end, label %for.body
2000cee313d2SEric Christopher
2001cee313d2SEric Christopherfor.end:
2002cee313d2SEric Christopher  ret void
2003cee313d2SEric Christopher}
2004cee313d2SEric Christopher
2005cee313d2SEric Christopher; PR30542. Ensure we generate all the scalar steps for the induction variable.
2006cee313d2SEric Christopher; The scalar induction variable is used by a getelementptr instruction
2007cee313d2SEric Christopher; (uniform), and a udiv (non-uniform).
2008cee313d2SEric Christopher;
2009cee313d2SEric Christopher; int sum = 0;
2010cee313d2SEric Christopher; for (int i = 0; i < n; ++i) {
2011cee313d2SEric Christopher;   int x = a[i];
2012cee313d2SEric Christopher;   if (c)
2013cee313d2SEric Christopher;     x /= i;
2014cee313d2SEric Christopher;   sum += x;
2015cee313d2SEric Christopher; }
2016cee313d2SEric Christopher;
2017bbba8676SPhilip Reames;
2018bbfaf0b1SPhilip Reames;
2019bbfaf0b1SPhilip Reames;
2020bbba8676SPhilip Reames
2021bbba8676SPhilip Reamesdefine i32 @scalarize_induction_variable_05(i32* %a, i32 %x, i1 %c, i32 %n) {
2022eb052f6bSPhilip Reames; CHECK-LABEL: @scalarize_induction_variable_05(
2023eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
2024eb052f6bSPhilip Reames; CHECK-NEXT:    [[SMAX:%.*]] = call i32 @llvm.smax.i32(i32 [[N:%.*]], i32 1)
2025eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[SMAX]], 2
2026eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2027eb052f6bSPhilip Reames; CHECK:       vector.ph:
2028eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[SMAX]], 2
2029eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i32 [[SMAX]], [[N_MOD_VF]]
2030eb052f6bSPhilip Reames; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i1> poison, i1 [[C:%.*]], i32 0
2031eb052f6bSPhilip Reames; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i1> [[BROADCAST_SPLATINSERT]], <2 x i1> poison, <2 x i32> zeroinitializer
2032eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
2033eb052f6bSPhilip Reames; CHECK:       vector.body:
2034eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_UDIV_CONTINUE2:%.*]] ]
2035eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP16:%.*]], [[PRED_UDIV_CONTINUE2]] ]
2036eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[INDEX]], 0
2037eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i32 [[TMP0]]
2038eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[TMP1]], i32 0
2039eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <2 x i32>*
2040eb052f6bSPhilip Reames; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x i32>, <2 x i32>* [[TMP3]], align 4
2041eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = extractelement <2 x i1> [[BROADCAST_SPLAT]], i32 0
2042eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP4]], label [[PRED_UDIV_IF:%.*]], label [[PRED_UDIV_CONTINUE:%.*]]
2043eb052f6bSPhilip Reames; CHECK:       pred.udiv.if:
2044eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP5:%.*]] = extractelement <2 x i32> [[WIDE_LOAD]], i32 0
2045eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP6:%.*]] = udiv i32 [[TMP5]], [[TMP0]]
2046eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP7:%.*]] = insertelement <2 x i32> poison, i32 [[TMP6]], i32 0
2047eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[PRED_UDIV_CONTINUE]]
2048eb052f6bSPhilip Reames; CHECK:       pred.udiv.continue:
2049eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP8:%.*]] = phi <2 x i32> [ poison, [[VECTOR_BODY]] ], [ [[TMP7]], [[PRED_UDIV_IF]] ]
2050eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP9:%.*]] = extractelement <2 x i1> [[BROADCAST_SPLAT]], i32 1
2051eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP9]], label [[PRED_UDIV_IF1:%.*]], label [[PRED_UDIV_CONTINUE2]]
2052eb052f6bSPhilip Reames; CHECK:       pred.udiv.if1:
2053eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP10:%.*]] = add i32 [[INDEX]], 1
2054eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP11:%.*]] = extractelement <2 x i32> [[WIDE_LOAD]], i32 1
2055eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP12:%.*]] = udiv i32 [[TMP11]], [[TMP10]]
2056eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP13:%.*]] = insertelement <2 x i32> [[TMP8]], i32 [[TMP12]], i32 1
2057eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[PRED_UDIV_CONTINUE2]]
2058eb052f6bSPhilip Reames; CHECK:       pred.udiv.continue2:
2059eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP14:%.*]] = phi <2 x i32> [ [[TMP8]], [[PRED_UDIV_CONTINUE]] ], [ [[TMP13]], [[PRED_UDIV_IF1]] ]
2060eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP15:%.*]] = xor <2 x i1> [[BROADCAST_SPLAT]], <i1 true, i1 true>
2061eb052f6bSPhilip Reames; CHECK-NEXT:    [[PREDPHI:%.*]] = select <2 x i1> [[TMP15]], <2 x i32> [[WIDE_LOAD]], <2 x i32> [[TMP14]]
2062eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP16]] = add <2 x i32> [[PREDPHI]], [[VEC_PHI]]
2063eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
2064eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP17:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
2065eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP17]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP24:![0-9]+]]
2066eb052f6bSPhilip Reames; CHECK:       middle.block:
2067eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP18:%.*]] = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> [[TMP16]])
2068eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[SMAX]], [[N_VEC]]
2069eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
2070eb052f6bSPhilip Reames; CHECK:       scalar.ph:
2071eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
2072eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[TMP18]], [[MIDDLE_BLOCK]] ]
2073eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
2074eb052f6bSPhilip Reames; CHECK:       for.body:
2075eb052f6bSPhilip Reames; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[IF_END:%.*]] ]
2076eb052f6bSPhilip Reames; CHECK-NEXT:    [[SUM:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[VAR4:%.*]], [[IF_END]] ]
2077eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR0:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[I]]
2078eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR1:%.*]] = load i32, i32* [[VAR0]], align 4
2079eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[C]], label [[IF_THEN:%.*]], label [[IF_END]]
2080eb052f6bSPhilip Reames; CHECK:       if.then:
2081eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR2:%.*]] = udiv i32 [[VAR1]], [[I]]
2082eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[IF_END]]
2083eb052f6bSPhilip Reames; CHECK:       if.end:
2084eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR3:%.*]] = phi i32 [ [[VAR2]], [[IF_THEN]] ], [ [[VAR1]], [[FOR_BODY]] ]
2085eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR4]] = add i32 [[VAR3]], [[SUM]]
2086eb052f6bSPhilip Reames; CHECK-NEXT:    [[I_NEXT]] = add nuw nsw i32 [[I]], 1
2087eb052f6bSPhilip Reames; CHECK-NEXT:    [[COND:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
2088eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP25:![0-9]+]]
2089eb052f6bSPhilip Reames; CHECK:       for.end:
2090eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR5:%.*]] = phi i32 [ [[VAR4]], [[IF_END]] ], [ [[TMP18]], [[MIDDLE_BLOCK]] ]
2091eb052f6bSPhilip Reames; CHECK-NEXT:    ret i32 [[VAR5]]
2092eb052f6bSPhilip Reames;
2093eb052f6bSPhilip Reames; IND-LABEL: @scalarize_induction_variable_05(
2094eb052f6bSPhilip Reames; IND-NEXT:  entry:
2095eb052f6bSPhilip Reames; IND-NEXT:    [[SMAX:%.*]] = call i32 @llvm.smax.i32(i32 [[N:%.*]], i32 1)
2096eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[SMAX]], 2
2097eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2098eb052f6bSPhilip Reames; IND:       vector.ph:
2099eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i32 [[SMAX]], 2147483646
2100e6ad9ef4SPhilip Reames; IND-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i1> poison, i1 [[C:%.*]], i64 0
2101eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
2102eb052f6bSPhilip Reames; IND:       vector.body:
2103eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_UDIV_CONTINUE2:%.*]] ]
2104eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP14:%.*]], [[PRED_UDIV_CONTINUE2]] ]
2105eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = sext i32 [[INDEX]] to i64
2106eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP0]]
2107eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = bitcast i32* [[TMP1]] to <2 x i32>*
2108eb052f6bSPhilip Reames; IND-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x i32>, <2 x i32>* [[TMP2]], align 4
2109eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF:%.*]], label [[PRED_UDIV_CONTINUE:%.*]]
2110eb052f6bSPhilip Reames; IND:       pred.udiv.if:
2111e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = extractelement <2 x i32> [[WIDE_LOAD]], i64 0
2112eb052f6bSPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = udiv i32 [[TMP3]], [[INDEX]]
2113e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP5:%.*]] = insertelement <2 x i32> poison, i32 [[TMP4]], i64 0
2114eb052f6bSPhilip Reames; IND-NEXT:    br label [[PRED_UDIV_CONTINUE]]
2115eb052f6bSPhilip Reames; IND:       pred.udiv.continue:
2116eb052f6bSPhilip Reames; IND-NEXT:    [[TMP6:%.*]] = phi <2 x i32> [ poison, [[VECTOR_BODY]] ], [ [[TMP5]], [[PRED_UDIV_IF]] ]
2117eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF1:%.*]], label [[PRED_UDIV_CONTINUE2]]
2118eb052f6bSPhilip Reames; IND:       pred.udiv.if1:
2119eb052f6bSPhilip Reames; IND-NEXT:    [[TMP7:%.*]] = or i32 [[INDEX]], 1
2120e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP8:%.*]] = extractelement <2 x i32> [[WIDE_LOAD]], i64 1
2121eb052f6bSPhilip Reames; IND-NEXT:    [[TMP9:%.*]] = udiv i32 [[TMP8]], [[TMP7]]
2122e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP10:%.*]] = insertelement <2 x i32> [[TMP6]], i32 [[TMP9]], i64 1
2123eb052f6bSPhilip Reames; IND-NEXT:    br label [[PRED_UDIV_CONTINUE2]]
2124eb052f6bSPhilip Reames; IND:       pred.udiv.continue2:
2125eb052f6bSPhilip Reames; IND-NEXT:    [[TMP11:%.*]] = phi <2 x i32> [ [[TMP6]], [[PRED_UDIV_CONTINUE]] ], [ [[TMP10]], [[PRED_UDIV_IF1]] ]
2126eb052f6bSPhilip Reames; IND-NEXT:    [[TMP12:%.*]] = xor <2 x i1> [[BROADCAST_SPLATINSERT]], <i1 true, i1 poison>
2127eb052f6bSPhilip Reames; IND-NEXT:    [[TMP13:%.*]] = shufflevector <2 x i1> [[TMP12]], <2 x i1> poison, <2 x i32> zeroinitializer
2128eb052f6bSPhilip Reames; IND-NEXT:    [[PREDPHI:%.*]] = select <2 x i1> [[TMP13]], <2 x i32> [[WIDE_LOAD]], <2 x i32> [[TMP11]]
2129eb052f6bSPhilip Reames; IND-NEXT:    [[TMP14]] = add <2 x i32> [[PREDPHI]], [[VEC_PHI]]
2130eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
2131eb052f6bSPhilip Reames; IND-NEXT:    [[TMP15:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
2132eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP15]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP24:![0-9]+]]
2133eb052f6bSPhilip Reames; IND:       middle.block:
2134eb052f6bSPhilip Reames; IND-NEXT:    [[TMP16:%.*]] = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> [[TMP14]])
2135eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[SMAX]], [[N_VEC]]
2136eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
2137eb052f6bSPhilip Reames; IND:       scalar.ph:
2138eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
2139eb052f6bSPhilip Reames; IND-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP16]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
2140eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
2141eb052f6bSPhilip Reames; IND:       for.body:
2142eb052f6bSPhilip Reames; IND-NEXT:    [[I:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[IF_END:%.*]] ]
2143eb052f6bSPhilip Reames; IND-NEXT:    [[SUM:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[VAR4:%.*]], [[IF_END]] ]
2144eb052f6bSPhilip Reames; IND-NEXT:    [[TMP17:%.*]] = zext i32 [[I]] to i64
2145eb052f6bSPhilip Reames; IND-NEXT:    [[VAR0:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP17]]
2146eb052f6bSPhilip Reames; IND-NEXT:    [[VAR1:%.*]] = load i32, i32* [[VAR0]], align 4
2147eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[C]], label [[IF_THEN:%.*]], label [[IF_END]]
2148eb052f6bSPhilip Reames; IND:       if.then:
2149eb052f6bSPhilip Reames; IND-NEXT:    [[VAR2:%.*]] = udiv i32 [[VAR1]], [[I]]
2150eb052f6bSPhilip Reames; IND-NEXT:    br label [[IF_END]]
2151eb052f6bSPhilip Reames; IND:       if.end:
2152eb052f6bSPhilip Reames; IND-NEXT:    [[VAR3:%.*]] = phi i32 [ [[VAR2]], [[IF_THEN]] ], [ [[VAR1]], [[FOR_BODY]] ]
2153eb052f6bSPhilip Reames; IND-NEXT:    [[VAR4]] = add i32 [[VAR3]], [[SUM]]
2154eb052f6bSPhilip Reames; IND-NEXT:    [[I_NEXT]] = add nuw nsw i32 [[I]], 1
2155eb052f6bSPhilip Reames; IND-NEXT:    [[COND:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
2156eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP25:![0-9]+]]
2157eb052f6bSPhilip Reames; IND:       for.end:
2158eb052f6bSPhilip Reames; IND-NEXT:    [[VAR5:%.*]] = phi i32 [ [[VAR4]], [[IF_END]] ], [ [[TMP16]], [[MIDDLE_BLOCK]] ]
2159eb052f6bSPhilip Reames; IND-NEXT:    ret i32 [[VAR5]]
2160eb052f6bSPhilip Reames;
2161eb052f6bSPhilip Reames; UNROLL-LABEL: @scalarize_induction_variable_05(
2162eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
2163eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SMAX:%.*]] = call i32 @llvm.smax.i32(i32 [[N:%.*]], i32 1)
2164eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[SMAX]], 4
2165eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2166eb052f6bSPhilip Reames; UNROLL:       vector.ph:
2167eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i32 [[SMAX]], 2147483644
2168e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i1> poison, i1 [[C:%.*]], i64 0
21690c00dbb9SNikita Popov; UNROLL-NEXT:    [[BROADCAST_SPLATINSERT5:%.*]] = insertelement <2 x i1> poison, i1 [[C]], i64 0
2170eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
2171eb052f6bSPhilip Reames; UNROLL:       vector.body:
21720c00dbb9SNikita Popov; UNROLL-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_UDIV_CONTINUE10:%.*]] ]
21730c00dbb9SNikita Popov; UNROLL-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP28:%.*]], [[PRED_UDIV_CONTINUE10]] ]
21740c00dbb9SNikita Popov; UNROLL-NEXT:    [[VEC_PHI1:%.*]] = phi <2 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP29:%.*]], [[PRED_UDIV_CONTINUE10]] ]
2175eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = or i32 [[INDEX]], 2
2176eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = sext i32 [[INDEX]] to i64
2177eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP1]]
2178eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <2 x i32>*
2179eb052f6bSPhilip Reames; UNROLL-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x i32>, <2 x i32>* [[TMP3]], align 4
2180eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i64 2
2181eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP4]] to <2 x i32>*
21820c00dbb9SNikita Popov; UNROLL-NEXT:    [[WIDE_LOAD2:%.*]] = load <2 x i32>, <2 x i32>* [[TMP5]], align 4
2183eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF:%.*]], label [[PRED_UDIV_CONTINUE:%.*]]
2184eb052f6bSPhilip Reames; UNROLL:       pred.udiv.if:
2185e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP6:%.*]] = extractelement <2 x i32> [[WIDE_LOAD]], i64 0
2186eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP7:%.*]] = udiv i32 [[TMP6]], [[INDEX]]
2187e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP8:%.*]] = insertelement <2 x i32> poison, i32 [[TMP7]], i64 0
2188eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[PRED_UDIV_CONTINUE]]
2189eb052f6bSPhilip Reames; UNROLL:       pred.udiv.continue:
2190eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP9:%.*]] = phi <2 x i32> [ poison, [[VECTOR_BODY]] ], [ [[TMP8]], [[PRED_UDIV_IF]] ]
21910c00dbb9SNikita Popov; UNROLL-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF3:%.*]], label [[PRED_UDIV_CONTINUE4:%.*]]
219295f76bffSFlorian Hahn; UNROLL:       pred.udiv.if3:
2193eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP10:%.*]] = or i32 [[INDEX]], 1
2194e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP11:%.*]] = extractelement <2 x i32> [[WIDE_LOAD]], i64 1
2195eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP12:%.*]] = udiv i32 [[TMP11]], [[TMP10]]
2196e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP13:%.*]] = insertelement <2 x i32> [[TMP9]], i32 [[TMP12]], i64 1
21970c00dbb9SNikita Popov; UNROLL-NEXT:    br label [[PRED_UDIV_CONTINUE4]]
219895f76bffSFlorian Hahn; UNROLL:       pred.udiv.continue4:
21990c00dbb9SNikita Popov; UNROLL-NEXT:    [[TMP14:%.*]] = phi <2 x i32> [ [[TMP9]], [[PRED_UDIV_CONTINUE]] ], [ [[TMP13]], [[PRED_UDIV_IF3]] ]
22000c00dbb9SNikita Popov; UNROLL-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF7:%.*]], label [[PRED_UDIV_CONTINUE8:%.*]]
220195f76bffSFlorian Hahn; UNROLL:       pred.udiv.if7:
22020c00dbb9SNikita Popov; UNROLL-NEXT:    [[TMP15:%.*]] = extractelement <2 x i32> [[WIDE_LOAD2]], i64 0
2203eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP16:%.*]] = udiv i32 [[TMP15]], [[TMP0]]
2204e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP17:%.*]] = insertelement <2 x i32> poison, i32 [[TMP16]], i64 0
22050c00dbb9SNikita Popov; UNROLL-NEXT:    br label [[PRED_UDIV_CONTINUE8]]
220695f76bffSFlorian Hahn; UNROLL:       pred.udiv.continue8:
22070c00dbb9SNikita Popov; UNROLL-NEXT:    [[TMP18:%.*]] = phi <2 x i32> [ poison, [[PRED_UDIV_CONTINUE4]] ], [ [[TMP17]], [[PRED_UDIV_IF7]] ]
22080c00dbb9SNikita Popov; UNROLL-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF9:%.*]], label [[PRED_UDIV_CONTINUE10]]
220995f76bffSFlorian Hahn; UNROLL:       pred.udiv.if9:
2210eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP19:%.*]] = or i32 [[INDEX]], 3
22110c00dbb9SNikita Popov; UNROLL-NEXT:    [[TMP20:%.*]] = extractelement <2 x i32> [[WIDE_LOAD2]], i64 1
2212eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP21:%.*]] = udiv i32 [[TMP20]], [[TMP19]]
2213e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP22:%.*]] = insertelement <2 x i32> [[TMP18]], i32 [[TMP21]], i64 1
22140c00dbb9SNikita Popov; UNROLL-NEXT:    br label [[PRED_UDIV_CONTINUE10]]
221595f76bffSFlorian Hahn; UNROLL:       pred.udiv.continue10:
22160c00dbb9SNikita Popov; UNROLL-NEXT:    [[TMP23:%.*]] = phi <2 x i32> [ [[TMP18]], [[PRED_UDIV_CONTINUE8]] ], [ [[TMP22]], [[PRED_UDIV_IF9]] ]
2217eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP24:%.*]] = xor <2 x i1> [[BROADCAST_SPLATINSERT]], <i1 true, i1 poison>
2218eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP25:%.*]] = shufflevector <2 x i1> [[TMP24]], <2 x i1> poison, <2 x i32> zeroinitializer
22190c00dbb9SNikita Popov; UNROLL-NEXT:    [[TMP26:%.*]] = xor <2 x i1> [[BROADCAST_SPLATINSERT5]], <i1 true, i1 poison>
2220eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP27:%.*]] = shufflevector <2 x i1> [[TMP26]], <2 x i1> poison, <2 x i32> zeroinitializer
2221eb052f6bSPhilip Reames; UNROLL-NEXT:    [[PREDPHI:%.*]] = select <2 x i1> [[TMP25]], <2 x i32> [[WIDE_LOAD]], <2 x i32> [[TMP14]]
22220c00dbb9SNikita Popov; UNROLL-NEXT:    [[PREDPHI11:%.*]] = select <2 x i1> [[TMP27]], <2 x i32> [[WIDE_LOAD2]], <2 x i32> [[TMP23]]
2223eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP28]] = add <2 x i32> [[PREDPHI]], [[VEC_PHI]]
22240c00dbb9SNikita Popov; UNROLL-NEXT:    [[TMP29]] = add <2 x i32> [[PREDPHI11]], [[VEC_PHI1]]
2225eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
2226eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP30:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
2227eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP30]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP24:![0-9]+]]
2228eb052f6bSPhilip Reames; UNROLL:       middle.block:
2229eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BIN_RDX:%.*]] = add <2 x i32> [[TMP29]], [[TMP28]]
2230eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP31:%.*]] = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> [[BIN_RDX]])
2231eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[SMAX]], [[N_VEC]]
2232eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
2233eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
2234eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
2235eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP31]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
2236eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
2237eb052f6bSPhilip Reames; UNROLL:       for.body:
2238eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[IF_END:%.*]] ]
2239eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SUM:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[VAR4:%.*]], [[IF_END]] ]
2240eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP32:%.*]] = zext i32 [[I]] to i64
2241eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VAR0:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP32]]
2242eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VAR1:%.*]] = load i32, i32* [[VAR0]], align 4
2243eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[C]], label [[IF_THEN:%.*]], label [[IF_END]]
2244eb052f6bSPhilip Reames; UNROLL:       if.then:
2245eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VAR2:%.*]] = udiv i32 [[VAR1]], [[I]]
2246eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[IF_END]]
2247eb052f6bSPhilip Reames; UNROLL:       if.end:
2248eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VAR3:%.*]] = phi i32 [ [[VAR2]], [[IF_THEN]] ], [ [[VAR1]], [[FOR_BODY]] ]
2249eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VAR4]] = add i32 [[VAR3]], [[SUM]]
2250eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I_NEXT]] = add nuw nsw i32 [[I]], 1
2251eb052f6bSPhilip Reames; UNROLL-NEXT:    [[COND:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
2252eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP25:![0-9]+]]
2253eb052f6bSPhilip Reames; UNROLL:       for.end:
2254eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VAR5:%.*]] = phi i32 [ [[VAR4]], [[IF_END]] ], [ [[TMP31]], [[MIDDLE_BLOCK]] ]
2255eb052f6bSPhilip Reames; UNROLL-NEXT:    ret i32 [[VAR5]]
2256eb052f6bSPhilip Reames;
2257eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @scalarize_induction_variable_05(
2258eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
2259eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SMAX:%.*]] = call i32 @llvm.smax.i32(i32 [[N:%.*]], i32 1)
2260eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[SMAX]], 4
2261eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2262eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
2263eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[SMAX]], 4
2264eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i32 [[SMAX]], [[N_MOD_VF]]
2265eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i1> poison, i1 [[C:%.*]], i32 0
2266eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i1> [[BROADCAST_SPLATINSERT]], <2 x i1> poison, <2 x i32> zeroinitializer
22670c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLATINSERT5:%.*]] = insertelement <2 x i1> poison, i1 [[C]], i32 0
22680c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLAT6:%.*]] = shufflevector <2 x i1> [[BROADCAST_SPLATINSERT5]], <2 x i1> poison, <2 x i32> zeroinitializer
2269eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
2270eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
22710c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_UDIV_CONTINUE10:%.*]] ]
22720c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP32:%.*]], [[PRED_UDIV_CONTINUE10]] ]
22730c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_PHI1:%.*]] = phi <2 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP33:%.*]], [[PRED_UDIV_CONTINUE10]] ]
2274eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i32 [[INDEX]], 0
2275eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = add i32 [[INDEX]], 2
2276eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i32 [[TMP0]]
2277eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[TMP1]]
2278eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i32 0
2279eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP4]] to <2 x i32>*
2280eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x i32>, <2 x i32>* [[TMP5]], align 4
2281eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i32 2
2282eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = bitcast i32* [[TMP6]] to <2 x i32>*
22830c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[WIDE_LOAD2:%.*]] = load <2 x i32>, <2 x i32>* [[TMP7]], align 4
2284eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = extractelement <2 x i1> [[BROADCAST_SPLAT]], i32 0
2285eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP8]], label [[PRED_UDIV_IF:%.*]], label [[PRED_UDIV_CONTINUE:%.*]]
2286eb052f6bSPhilip Reames; UNROLL-NO-IC:       pred.udiv.if:
2287eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = extractelement <2 x i32> [[WIDE_LOAD]], i32 0
2288eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = udiv i32 [[TMP9]], [[TMP0]]
2289eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = insertelement <2 x i32> poison, i32 [[TMP10]], i32 0
2290eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[PRED_UDIV_CONTINUE]]
2291eb052f6bSPhilip Reames; UNROLL-NO-IC:       pred.udiv.continue:
2292eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = phi <2 x i32> [ poison, [[VECTOR_BODY]] ], [ [[TMP11]], [[PRED_UDIV_IF]] ]
2293eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = extractelement <2 x i1> [[BROADCAST_SPLAT]], i32 1
22940c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP13]], label [[PRED_UDIV_IF3:%.*]], label [[PRED_UDIV_CONTINUE4:%.*]]
229595f76bffSFlorian Hahn; UNROLL-NO-IC:       pred.udiv.if3:
2296eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = add i32 [[INDEX]], 1
2297eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = extractelement <2 x i32> [[WIDE_LOAD]], i32 1
2298eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP16:%.*]] = udiv i32 [[TMP15]], [[TMP14]]
2299eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP17:%.*]] = insertelement <2 x i32> [[TMP12]], i32 [[TMP16]], i32 1
23000c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    br label [[PRED_UDIV_CONTINUE4]]
230195f76bffSFlorian Hahn; UNROLL-NO-IC:       pred.udiv.continue4:
23020c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP18:%.*]] = phi <2 x i32> [ [[TMP12]], [[PRED_UDIV_CONTINUE]] ], [ [[TMP17]], [[PRED_UDIV_IF3]] ]
23030c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP19:%.*]] = extractelement <2 x i1> [[BROADCAST_SPLAT6]], i32 0
23040c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP19]], label [[PRED_UDIV_IF7:%.*]], label [[PRED_UDIV_CONTINUE8:%.*]]
230595f76bffSFlorian Hahn; UNROLL-NO-IC:       pred.udiv.if7:
23060c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP20:%.*]] = extractelement <2 x i32> [[WIDE_LOAD2]], i32 0
2307eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP21:%.*]] = udiv i32 [[TMP20]], [[TMP1]]
2308eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP22:%.*]] = insertelement <2 x i32> poison, i32 [[TMP21]], i32 0
23090c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    br label [[PRED_UDIV_CONTINUE8]]
231095f76bffSFlorian Hahn; UNROLL-NO-IC:       pred.udiv.continue8:
23110c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP23:%.*]] = phi <2 x i32> [ poison, [[PRED_UDIV_CONTINUE4]] ], [ [[TMP22]], [[PRED_UDIV_IF7]] ]
23120c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP24:%.*]] = extractelement <2 x i1> [[BROADCAST_SPLAT6]], i32 1
23130c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP24]], label [[PRED_UDIV_IF9:%.*]], label [[PRED_UDIV_CONTINUE10]]
231495f76bffSFlorian Hahn; UNROLL-NO-IC:       pred.udiv.if9:
2315eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP25:%.*]] = add i32 [[INDEX]], 3
23160c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP26:%.*]] = extractelement <2 x i32> [[WIDE_LOAD2]], i32 1
2317eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP27:%.*]] = udiv i32 [[TMP26]], [[TMP25]]
2318eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP28:%.*]] = insertelement <2 x i32> [[TMP23]], i32 [[TMP27]], i32 1
23190c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    br label [[PRED_UDIV_CONTINUE10]]
232095f76bffSFlorian Hahn; UNROLL-NO-IC:       pred.udiv.continue10:
23210c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP29:%.*]] = phi <2 x i32> [ [[TMP23]], [[PRED_UDIV_CONTINUE8]] ], [ [[TMP28]], [[PRED_UDIV_IF9]] ]
2322eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP30:%.*]] = xor <2 x i1> [[BROADCAST_SPLAT]], <i1 true, i1 true>
23230c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP31:%.*]] = xor <2 x i1> [[BROADCAST_SPLAT6]], <i1 true, i1 true>
2324eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[PREDPHI:%.*]] = select <2 x i1> [[TMP30]], <2 x i32> [[WIDE_LOAD]], <2 x i32> [[TMP18]]
23250c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[PREDPHI11:%.*]] = select <2 x i1> [[TMP31]], <2 x i32> [[WIDE_LOAD2]], <2 x i32> [[TMP29]]
2326eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP32]] = add <2 x i32> [[PREDPHI]], [[VEC_PHI]]
23270c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP33]] = add <2 x i32> [[PREDPHI11]], [[VEC_PHI1]]
2328eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
2329eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP34:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
2330eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP34]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP24:![0-9]+]]
2331eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
2332eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BIN_RDX:%.*]] = add <2 x i32> [[TMP33]], [[TMP32]]
2333eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP35:%.*]] = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> [[BIN_RDX]])
2334eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[SMAX]], [[N_VEC]]
2335eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
2336eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
2337eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
2338eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[TMP35]], [[MIDDLE_BLOCK]] ]
2339eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
2340eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
2341eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[IF_END:%.*]] ]
2342eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SUM:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[VAR4:%.*]], [[IF_END]] ]
2343eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR0:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[I]]
2344eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR1:%.*]] = load i32, i32* [[VAR0]], align 4
2345eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[C]], label [[IF_THEN:%.*]], label [[IF_END]]
2346eb052f6bSPhilip Reames; UNROLL-NO-IC:       if.then:
2347eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR2:%.*]] = udiv i32 [[VAR1]], [[I]]
2348eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[IF_END]]
2349eb052f6bSPhilip Reames; UNROLL-NO-IC:       if.end:
2350eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR3:%.*]] = phi i32 [ [[VAR2]], [[IF_THEN]] ], [ [[VAR1]], [[FOR_BODY]] ]
2351eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR4]] = add i32 [[VAR3]], [[SUM]]
2352eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I_NEXT]] = add nuw nsw i32 [[I]], 1
2353eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[COND:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
2354eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP25:![0-9]+]]
2355eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.end:
2356eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR5:%.*]] = phi i32 [ [[VAR4]], [[IF_END]] ], [ [[TMP35]], [[MIDDLE_BLOCK]] ]
2357eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret i32 [[VAR5]]
2358eb052f6bSPhilip Reames;
2359eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @scalarize_induction_variable_05(
2360eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
2361eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SMAX:%.*]] = call i32 @llvm.smax.i32(i32 [[N:%.*]], i32 1)
2362eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[SMAX]], 8
2363eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2364eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
2365eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i32 [[SMAX]], 2147483640
2366e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i1> poison, i1 [[C:%.*]], i64 0
23670c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[BROADCAST_SPLATINSERT9:%.*]] = insertelement <4 x i1> poison, i1 [[C]], i64 0
2368eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
2369eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
23700c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_UDIV_CONTINUE18:%.*]] ]
23710c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[VEC_PHI:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP48:%.*]], [[PRED_UDIV_CONTINUE18]] ]
23720c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[VEC_PHI1:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP49:%.*]], [[PRED_UDIV_CONTINUE18]] ]
2373eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = or i32 [[INDEX]], 4
2374eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = sext i32 [[INDEX]] to i64
2375eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP1]]
2376eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <4 x i32>*
2377eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x i32>, <4 x i32>* [[TMP3]], align 4
2378eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i64 4
2379eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP4]] to <4 x i32>*
23800c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[WIDE_LOAD2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP5]], align 4
2381eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF:%.*]], label [[PRED_UDIV_CONTINUE:%.*]]
2382eb052f6bSPhilip Reames; INTERLEAVE:       pred.udiv.if:
2383e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = extractelement <4 x i32> [[WIDE_LOAD]], i64 0
2384eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP7:%.*]] = udiv i32 [[TMP6]], [[INDEX]]
2385e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP8:%.*]] = insertelement <4 x i32> poison, i32 [[TMP7]], i64 0
2386eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[PRED_UDIV_CONTINUE]]
2387eb052f6bSPhilip Reames; INTERLEAVE:       pred.udiv.continue:
2388eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP9:%.*]] = phi <4 x i32> [ poison, [[VECTOR_BODY]] ], [ [[TMP8]], [[PRED_UDIV_IF]] ]
23890c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF3:%.*]], label [[PRED_UDIV_CONTINUE4:%.*]]
239095f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.if3:
2391eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP10:%.*]] = or i32 [[INDEX]], 1
2392e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP11:%.*]] = extractelement <4 x i32> [[WIDE_LOAD]], i64 1
2393eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP12:%.*]] = udiv i32 [[TMP11]], [[TMP10]]
2394e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP13:%.*]] = insertelement <4 x i32> [[TMP9]], i32 [[TMP12]], i64 1
23950c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UDIV_CONTINUE4]]
239695f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.continue4:
23970c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP14:%.*]] = phi <4 x i32> [ [[TMP9]], [[PRED_UDIV_CONTINUE]] ], [ [[TMP13]], [[PRED_UDIV_IF3]] ]
23980c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF5:%.*]], label [[PRED_UDIV_CONTINUE6:%.*]]
239995f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.if5:
2400eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP15:%.*]] = or i32 [[INDEX]], 2
2401e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP16:%.*]] = extractelement <4 x i32> [[WIDE_LOAD]], i64 2
2402eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP17:%.*]] = udiv i32 [[TMP16]], [[TMP15]]
2403e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP18:%.*]] = insertelement <4 x i32> [[TMP14]], i32 [[TMP17]], i64 2
24040c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UDIV_CONTINUE6]]
240595f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.continue6:
24060c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP19:%.*]] = phi <4 x i32> [ [[TMP14]], [[PRED_UDIV_CONTINUE4]] ], [ [[TMP18]], [[PRED_UDIV_IF5]] ]
24070c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF7:%.*]], label [[PRED_UDIV_CONTINUE8:%.*]]
240895f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.if7:
2409eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP20:%.*]] = or i32 [[INDEX]], 3
2410e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP21:%.*]] = extractelement <4 x i32> [[WIDE_LOAD]], i64 3
2411eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP22:%.*]] = udiv i32 [[TMP21]], [[TMP20]]
2412e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP23:%.*]] = insertelement <4 x i32> [[TMP19]], i32 [[TMP22]], i64 3
24130c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UDIV_CONTINUE8]]
241495f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.continue8:
24150c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP24:%.*]] = phi <4 x i32> [ [[TMP19]], [[PRED_UDIV_CONTINUE6]] ], [ [[TMP23]], [[PRED_UDIV_IF7]] ]
24160c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF11:%.*]], label [[PRED_UDIV_CONTINUE12:%.*]]
241795f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.if11:
24180c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP25:%.*]] = extractelement <4 x i32> [[WIDE_LOAD2]], i64 0
2419eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP26:%.*]] = udiv i32 [[TMP25]], [[TMP0]]
2420e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP27:%.*]] = insertelement <4 x i32> poison, i32 [[TMP26]], i64 0
24210c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UDIV_CONTINUE12]]
242295f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.continue12:
24230c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP28:%.*]] = phi <4 x i32> [ poison, [[PRED_UDIV_CONTINUE8]] ], [ [[TMP27]], [[PRED_UDIV_IF11]] ]
24240c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF13:%.*]], label [[PRED_UDIV_CONTINUE14:%.*]]
242595f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.if13:
2426eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP29:%.*]] = or i32 [[INDEX]], 5
24270c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP30:%.*]] = extractelement <4 x i32> [[WIDE_LOAD2]], i64 1
2428eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP31:%.*]] = udiv i32 [[TMP30]], [[TMP29]]
2429e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP32:%.*]] = insertelement <4 x i32> [[TMP28]], i32 [[TMP31]], i64 1
24300c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UDIV_CONTINUE14]]
243195f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.continue14:
24320c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP33:%.*]] = phi <4 x i32> [ [[TMP28]], [[PRED_UDIV_CONTINUE12]] ], [ [[TMP32]], [[PRED_UDIV_IF13]] ]
24330c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF15:%.*]], label [[PRED_UDIV_CONTINUE16:%.*]]
243495f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.if15:
2435eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP34:%.*]] = or i32 [[INDEX]], 6
24360c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP35:%.*]] = extractelement <4 x i32> [[WIDE_LOAD2]], i64 2
2437eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP36:%.*]] = udiv i32 [[TMP35]], [[TMP34]]
2438e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP37:%.*]] = insertelement <4 x i32> [[TMP33]], i32 [[TMP36]], i64 2
24390c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UDIV_CONTINUE16]]
244095f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.continue16:
24410c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP38:%.*]] = phi <4 x i32> [ [[TMP33]], [[PRED_UDIV_CONTINUE14]] ], [ [[TMP37]], [[PRED_UDIV_IF15]] ]
24420c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br i1 [[C]], label [[PRED_UDIV_IF17:%.*]], label [[PRED_UDIV_CONTINUE18]]
244395f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.if17:
2444eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP39:%.*]] = or i32 [[INDEX]], 7
24450c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP40:%.*]] = extractelement <4 x i32> [[WIDE_LOAD2]], i64 3
2446eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP41:%.*]] = udiv i32 [[TMP40]], [[TMP39]]
2447e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP42:%.*]] = insertelement <4 x i32> [[TMP38]], i32 [[TMP41]], i64 3
24480c00dbb9SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UDIV_CONTINUE18]]
244995f76bffSFlorian Hahn; INTERLEAVE:       pred.udiv.continue18:
24500c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP43:%.*]] = phi <4 x i32> [ [[TMP38]], [[PRED_UDIV_CONTINUE16]] ], [ [[TMP42]], [[PRED_UDIV_IF17]] ]
2451eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP44:%.*]] = xor <4 x i1> [[BROADCAST_SPLATINSERT]], <i1 true, i1 poison, i1 poison, i1 poison>
2452eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP45:%.*]] = shufflevector <4 x i1> [[TMP44]], <4 x i1> poison, <4 x i32> zeroinitializer
24530c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP46:%.*]] = xor <4 x i1> [[BROADCAST_SPLATINSERT9]], <i1 true, i1 poison, i1 poison, i1 poison>
2454eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP47:%.*]] = shufflevector <4 x i1> [[TMP46]], <4 x i1> poison, <4 x i32> zeroinitializer
2455eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[PREDPHI:%.*]] = select <4 x i1> [[TMP45]], <4 x i32> [[WIDE_LOAD]], <4 x i32> [[TMP24]]
24560c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[PREDPHI19:%.*]] = select <4 x i1> [[TMP47]], <4 x i32> [[WIDE_LOAD2]], <4 x i32> [[TMP43]]
2457eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP48]] = add <4 x i32> [[PREDPHI]], [[VEC_PHI]]
24580c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP49]] = add <4 x i32> [[PREDPHI19]], [[VEC_PHI1]]
2459eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8
2460eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP50:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
2461eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP50]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP24:![0-9]+]]
2462eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
2463eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BIN_RDX:%.*]] = add <4 x i32> [[TMP49]], [[TMP48]]
2464eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP51:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[BIN_RDX]])
2465eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[SMAX]], [[N_VEC]]
2466eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
2467eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
2468eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
2469eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP51]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
2470eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
2471eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
2472eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[IF_END:%.*]] ]
2473eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SUM:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[VAR4:%.*]], [[IF_END]] ]
2474eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP52:%.*]] = zext i32 [[I]] to i64
2475eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR0:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP52]]
2476eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR1:%.*]] = load i32, i32* [[VAR0]], align 4
2477eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[C]], label [[IF_THEN:%.*]], label [[IF_END]]
2478eb052f6bSPhilip Reames; INTERLEAVE:       if.then:
2479eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR2:%.*]] = udiv i32 [[VAR1]], [[I]]
2480eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[IF_END]]
2481eb052f6bSPhilip Reames; INTERLEAVE:       if.end:
2482eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR3:%.*]] = phi i32 [ [[VAR2]], [[IF_THEN]] ], [ [[VAR1]], [[FOR_BODY]] ]
2483eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR4]] = add i32 [[VAR3]], [[SUM]]
2484eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I_NEXT]] = add nuw nsw i32 [[I]], 1
2485eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[COND:%.*]] = icmp slt i32 [[I_NEXT]], [[N]]
2486eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP25:![0-9]+]]
2487eb052f6bSPhilip Reames; INTERLEAVE:       for.end:
2488eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR5:%.*]] = phi i32 [ [[VAR4]], [[IF_END]] ], [ [[TMP51]], [[MIDDLE_BLOCK]] ]
2489eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret i32 [[VAR5]]
2490eb052f6bSPhilip Reames;
2491cee313d2SEric Christopherentry:
2492cee313d2SEric Christopher  br label %for.body
2493cee313d2SEric Christopher
2494cee313d2SEric Christopherfor.body:
2495cee313d2SEric Christopher  %i = phi i32 [ 0, %entry ], [ %i.next, %if.end ]
2496eb052f6bSPhilip Reames  %sum = phi i32 [ 0, %entry ], [ %var4, %if.end ]
2497eb052f6bSPhilip Reames  %var0 = getelementptr inbounds i32, i32* %a, i32 %i
2498eb052f6bSPhilip Reames  %var1 = load i32, i32* %var0, align 4
2499cee313d2SEric Christopher  br i1 %c, label %if.then, label %if.end
2500cee313d2SEric Christopher
2501cee313d2SEric Christopherif.then:
2502eb052f6bSPhilip Reames  %var2 = udiv i32 %var1, %i
2503cee313d2SEric Christopher  br label %if.end
2504cee313d2SEric Christopher
2505cee313d2SEric Christopherif.end:
2506eb052f6bSPhilip Reames  %var3 = phi i32 [ %var2, %if.then ], [ %var1, %for.body ]
2507eb052f6bSPhilip Reames  %var4 = add i32 %var3, %sum
2508cee313d2SEric Christopher  %i.next = add nuw nsw i32 %i, 1
2509cee313d2SEric Christopher  %cond = icmp slt i32 %i.next, %n
2510cee313d2SEric Christopher  br i1 %cond, label %for.body, label %for.end
2511cee313d2SEric Christopher
2512cee313d2SEric Christopherfor.end:
2513eb052f6bSPhilip Reames  %var5  = phi i32 [ %var4, %if.end ]
2514eb052f6bSPhilip Reames  ret i32 %var5
2515cee313d2SEric Christopher}
2516cee313d2SEric Christopher
2517cee313d2SEric Christopher; Ensure we generate both a vector and a scalar induction variable. In this
2518cee313d2SEric Christopher; test, the induction variable is used by an instruction that will be
2519cee313d2SEric Christopher; vectorized (trunc) as well as an instruction that will remain in scalar form
2520cee313d2SEric Christopher; (gepelementptr).
2521cee313d2SEric Christopher;
2522cee313d2SEric Christopher;
2523cee313d2SEric Christopher;
2524cee313d2SEric Christopher
2525cee313d2SEric Christopher%pair.i16 = type { i16, i16 }
2526cee313d2SEric Christopherdefine void @iv_vector_and_scalar_users(%pair.i16* %p, i32 %a, i32 %n) {
2527eb052f6bSPhilip Reames; CHECK-LABEL: @iv_vector_and_scalar_users(
2528eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
2529eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
2530eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
2531eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
2532eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], 2
2533eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2534eb052f6bSPhilip Reames; CHECK:       vector.ph:
2535eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 2
2536eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
2537eb052f6bSPhilip Reames; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[A:%.*]], i32 0
2538eb052f6bSPhilip Reames; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
2539eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
2540eb052f6bSPhilip Reames; CHECK:       vector.body:
2541eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
25420c00dbb9SNikita Popov; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
2543eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = add i64 [[INDEX]], 0
2544eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = add i64 [[INDEX]], 1
25450c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP5:%.*]] = add <2 x i32> [[BROADCAST_SPLAT]], [[VEC_IND]]
2546eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP6:%.*]] = trunc <2 x i32> [[TMP5]] to <2 x i16>
2547eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds [[PAIR_I16:%.*]], %pair.i16* [[P:%.*]], i64 [[TMP3]], i32 1
2548eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP4]], i32 1
2549eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP9:%.*]] = extractelement <2 x i16> [[TMP6]], i32 0
2550eb052f6bSPhilip Reames; CHECK-NEXT:    store i16 [[TMP9]], i16* [[TMP7]], align 2
2551eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP10:%.*]] = extractelement <2 x i16> [[TMP6]], i32 1
2552eb052f6bSPhilip Reames; CHECK-NEXT:    store i16 [[TMP10]], i16* [[TMP8]], align 2
2553eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
25540c00dbb9SNikita Popov; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
2555eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
2556eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP11]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP26:![0-9]+]]
2557eb052f6bSPhilip Reames; CHECK:       middle.block:
2558eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
2559eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
2560eb052f6bSPhilip Reames; CHECK:       scalar.ph:
2561eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
2562eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
2563eb052f6bSPhilip Reames; CHECK:       for.body:
2564eb052f6bSPhilip Reames; CHECK-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
2565eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP12:%.*]] = trunc i64 [[I]] to i32
2566eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP13:%.*]] = add i32 [[A]], [[TMP12]]
2567eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP14:%.*]] = trunc i32 [[TMP13]] to i16
2568eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP15:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[I]], i32 1
2569eb052f6bSPhilip Reames; CHECK-NEXT:    store i16 [[TMP14]], i16* [[TMP15]], align 2
2570eb052f6bSPhilip Reames; CHECK-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
2571eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP16:%.*]] = trunc i64 [[I_NEXT]] to i32
2572eb052f6bSPhilip Reames; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 [[TMP16]], [[N]]
2573eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[COND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP27:![0-9]+]]
2574eb052f6bSPhilip Reames; CHECK:       for.end:
2575eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
2576eb052f6bSPhilip Reames;
2577eb052f6bSPhilip Reames; IND-LABEL: @iv_vector_and_scalar_users(
2578eb052f6bSPhilip Reames; IND-NEXT:  entry:
2579eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
2580eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
2581eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
2582eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp eq i32 [[TMP0]], 0
2583eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2584eb052f6bSPhilip Reames; IND:       vector.ph:
2585eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i64 [[TMP2]], 8589934590
2586e6ad9ef4SPhilip Reames; IND-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[A:%.*]], i64 0
2587eb052f6bSPhilip Reames; IND-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
2588eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
2589eb052f6bSPhilip Reames; IND:       vector.body:
2590eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
25910c00dbb9SNikita Popov; IND-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
2592eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = or i64 [[INDEX]], 1
25930c00dbb9SNikita Popov; IND-NEXT:    [[TMP4:%.*]] = add <2 x i32> [[BROADCAST_SPLAT]], [[VEC_IND]]
2594eb052f6bSPhilip Reames; IND-NEXT:    [[TMP5:%.*]] = trunc <2 x i32> [[TMP4]] to <2 x i16>
2595eb052f6bSPhilip Reames; IND-NEXT:    [[TMP6:%.*]] = getelementptr inbounds [[PAIR_I16:%.*]], %pair.i16* [[P:%.*]], i64 [[INDEX]], i32 1
2596eb052f6bSPhilip Reames; IND-NEXT:    [[TMP7:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP3]], i32 1
2597e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP8:%.*]] = extractelement <2 x i16> [[TMP5]], i64 0
2598eb052f6bSPhilip Reames; IND-NEXT:    store i16 [[TMP8]], i16* [[TMP6]], align 2
2599e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP9:%.*]] = extractelement <2 x i16> [[TMP5]], i64 1
2600eb052f6bSPhilip Reames; IND-NEXT:    store i16 [[TMP9]], i16* [[TMP7]], align 2
2601eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
26020c00dbb9SNikita Popov; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
2603eb052f6bSPhilip Reames; IND-NEXT:    [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
2604eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP26:![0-9]+]]
2605eb052f6bSPhilip Reames; IND:       middle.block:
2606eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
2607eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
2608eb052f6bSPhilip Reames; IND:       scalar.ph:
2609eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
2610eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
2611eb052f6bSPhilip Reames; IND:       for.body:
2612eb052f6bSPhilip Reames; IND-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
2613eb052f6bSPhilip Reames; IND-NEXT:    [[TMP11:%.*]] = trunc i64 [[I]] to i32
2614eb052f6bSPhilip Reames; IND-NEXT:    [[TMP12:%.*]] = add i32 [[TMP11]], [[A]]
2615eb052f6bSPhilip Reames; IND-NEXT:    [[TMP13:%.*]] = trunc i32 [[TMP12]] to i16
2616eb052f6bSPhilip Reames; IND-NEXT:    [[TMP14:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[I]], i32 1
2617eb052f6bSPhilip Reames; IND-NEXT:    store i16 [[TMP13]], i16* [[TMP14]], align 2
2618eb052f6bSPhilip Reames; IND-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
2619eb052f6bSPhilip Reames; IND-NEXT:    [[TMP15:%.*]] = trunc i64 [[I_NEXT]] to i32
2620eb052f6bSPhilip Reames; IND-NEXT:    [[COND:%.*]] = icmp eq i32 [[TMP15]], [[N]]
2621eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[COND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP27:![0-9]+]]
2622eb052f6bSPhilip Reames; IND:       for.end:
2623eb052f6bSPhilip Reames; IND-NEXT:    ret void
2624eb052f6bSPhilip Reames;
2625eb052f6bSPhilip Reames; UNROLL-LABEL: @iv_vector_and_scalar_users(
2626eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
2627eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
2628eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
2629eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
2630eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 3
2631eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2632eb052f6bSPhilip Reames; UNROLL:       vector.ph:
2633eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i64 [[TMP2]], 8589934588
2634e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[A:%.*]], i64 0
2635eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
26360c00dbb9SNikita Popov; UNROLL-NEXT:    [[BROADCAST_SPLATINSERT2:%.*]] = insertelement <2 x i32> poison, i32 [[A]], i64 0
2637eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
2638eb052f6bSPhilip Reames; UNROLL:       vector.body:
2639eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
26400c00dbb9SNikita Popov; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
2641eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = or i64 [[INDEX]], 1
2642eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = or i64 [[INDEX]], 2
2643eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = or i64 [[INDEX]], 3
26440c00dbb9SNikita Popov; UNROLL-NEXT:    [[TMP6:%.*]] = add <2 x i32> [[BROADCAST_SPLAT]], [[VEC_IND]]
26450c00dbb9SNikita Popov; UNROLL-NEXT:    [[TMP7:%.*]] = add <2 x i32> [[BROADCAST_SPLATINSERT2]], <i32 2, i32 poison>
2646eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP8:%.*]] = shufflevector <2 x i32> [[TMP7]], <2 x i32> poison, <2 x i32> zeroinitializer
26470c00dbb9SNikita Popov; UNROLL-NEXT:    [[TMP9:%.*]] = add <2 x i32> [[TMP8]], [[VEC_IND]]
2648eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP10:%.*]] = trunc <2 x i32> [[TMP6]] to <2 x i16>
2649eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP11:%.*]] = trunc <2 x i32> [[TMP9]] to <2 x i16>
2650eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP12:%.*]] = getelementptr inbounds [[PAIR_I16:%.*]], %pair.i16* [[P:%.*]], i64 [[INDEX]], i32 1
2651eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP13:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP3]], i32 1
2652eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP14:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP4]], i32 1
2653eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP15:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP5]], i32 1
2654e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP16:%.*]] = extractelement <2 x i16> [[TMP10]], i64 0
2655eb052f6bSPhilip Reames; UNROLL-NEXT:    store i16 [[TMP16]], i16* [[TMP12]], align 2
2656e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP17:%.*]] = extractelement <2 x i16> [[TMP10]], i64 1
2657eb052f6bSPhilip Reames; UNROLL-NEXT:    store i16 [[TMP17]], i16* [[TMP13]], align 2
2658e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP18:%.*]] = extractelement <2 x i16> [[TMP11]], i64 0
2659eb052f6bSPhilip Reames; UNROLL-NEXT:    store i16 [[TMP18]], i16* [[TMP14]], align 2
2660e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP19:%.*]] = extractelement <2 x i16> [[TMP11]], i64 1
2661eb052f6bSPhilip Reames; UNROLL-NEXT:    store i16 [[TMP19]], i16* [[TMP15]], align 2
2662eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
26630c00dbb9SNikita Popov; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 4, i32 4>
2664eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP20:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
2665eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP20]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP26:![0-9]+]]
2666eb052f6bSPhilip Reames; UNROLL:       middle.block:
2667eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
2668eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
2669eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
2670eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
2671eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
2672eb052f6bSPhilip Reames; UNROLL:       for.body:
2673eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
2674eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP21:%.*]] = trunc i64 [[I]] to i32
2675eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP22:%.*]] = add i32 [[TMP21]], [[A]]
2676eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP23:%.*]] = trunc i32 [[TMP22]] to i16
2677eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP24:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[I]], i32 1
2678eb052f6bSPhilip Reames; UNROLL-NEXT:    store i16 [[TMP23]], i16* [[TMP24]], align 2
2679eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
2680eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP25:%.*]] = trunc i64 [[I_NEXT]] to i32
2681eb052f6bSPhilip Reames; UNROLL-NEXT:    [[COND:%.*]] = icmp eq i32 [[TMP25]], [[N]]
2682eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[COND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP27:![0-9]+]]
2683eb052f6bSPhilip Reames; UNROLL:       for.end:
2684eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
2685eb052f6bSPhilip Reames;
2686eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @iv_vector_and_scalar_users(
2687eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
2688eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
2689eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
2690eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
2691eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], 4
2692eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2693eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
2694eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 4
2695eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
2696eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[A:%.*]], i32 0
2697eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
26980c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLATINSERT2:%.*]] = insertelement <2 x i32> poison, i32 [[A]], i32 0
26990c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLAT3:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT2]], <2 x i32> poison, <2 x i32> zeroinitializer
2700eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
2701eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
2702eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
27030c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
27040c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
2705eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = add i64 [[INDEX]], 0
2706eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = add i64 [[INDEX]], 1
2707eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = add i64 [[INDEX]], 2
2708eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = add i64 [[INDEX]], 3
27090c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = add <2 x i32> [[BROADCAST_SPLAT]], [[VEC_IND]]
27100c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = add <2 x i32> [[BROADCAST_SPLAT3]], [[STEP_ADD]]
2711eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = trunc <2 x i32> [[TMP7]] to <2 x i16>
2712eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = trunc <2 x i32> [[TMP8]] to <2 x i16>
2713eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = getelementptr inbounds [[PAIR_I16:%.*]], %pair.i16* [[P:%.*]], i64 [[TMP3]], i32 1
2714eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP4]], i32 1
2715eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP5]], i32 1
2716eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP6]], i32 1
2717eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = extractelement <2 x i16> [[TMP9]], i32 0
2718eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i16 [[TMP15]], i16* [[TMP11]], align 2
2719eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP16:%.*]] = extractelement <2 x i16> [[TMP9]], i32 1
2720eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i16 [[TMP16]], i16* [[TMP12]], align 2
2721eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP17:%.*]] = extractelement <2 x i16> [[TMP10]], i32 0
2722eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i16 [[TMP17]], i16* [[TMP13]], align 2
2723eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP18:%.*]] = extractelement <2 x i16> [[TMP10]], i32 1
2724eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i16 [[TMP18]], i16* [[TMP14]], align 2
2725eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
27260c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[STEP_ADD]], <i32 2, i32 2>
2727eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP19:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
2728eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP19]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP26:![0-9]+]]
2729eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
2730eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
2731eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
2732eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
2733eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
2734eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
2735eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
2736eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
2737eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP20:%.*]] = trunc i64 [[I]] to i32
2738eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP21:%.*]] = add i32 [[A]], [[TMP20]]
2739eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP22:%.*]] = trunc i32 [[TMP21]] to i16
2740eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP23:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[I]], i32 1
2741eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i16 [[TMP22]], i16* [[TMP23]], align 2
2742eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
2743eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP24:%.*]] = trunc i64 [[I_NEXT]] to i32
2744eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[COND:%.*]] = icmp eq i32 [[TMP24]], [[N]]
2745eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[COND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP27:![0-9]+]]
2746eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.end:
2747eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
2748eb052f6bSPhilip Reames;
2749eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @iv_vector_and_scalar_users(
2750eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
2751eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = add i32 [[N:%.*]], -1
2752eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
2753eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
2754eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 7
2755eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2756eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
2757eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i64 [[TMP2]], 8589934584
2758e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[A:%.*]], i64 0
2759eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
27600c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[BROADCAST_SPLATINSERT2:%.*]] = insertelement <4 x i32> poison, i32 [[A]], i64 0
2761eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
2762eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
2763eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
27640c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
2765eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = or i64 [[INDEX]], 1
2766eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = or i64 [[INDEX]], 2
2767eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = or i64 [[INDEX]], 3
2768eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = or i64 [[INDEX]], 4
2769eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP7:%.*]] = or i64 [[INDEX]], 5
2770eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP8:%.*]] = or i64 [[INDEX]], 6
2771eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP9:%.*]] = or i64 [[INDEX]], 7
27720c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP10:%.*]] = add <4 x i32> [[BROADCAST_SPLAT]], [[VEC_IND]]
27730c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP11:%.*]] = add <4 x i32> [[BROADCAST_SPLATINSERT2]], <i32 4, i32 poison, i32 poison, i32 poison>
2774eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP12:%.*]] = shufflevector <4 x i32> [[TMP11]], <4 x i32> poison, <4 x i32> zeroinitializer
27750c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[TMP13:%.*]] = add <4 x i32> [[TMP12]], [[VEC_IND]]
2776eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP14:%.*]] = trunc <4 x i32> [[TMP10]] to <4 x i16>
2777eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP15:%.*]] = trunc <4 x i32> [[TMP13]] to <4 x i16>
2778eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP16:%.*]] = getelementptr inbounds [[PAIR_I16:%.*]], %pair.i16* [[P:%.*]], i64 [[INDEX]], i32 1
2779eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP17:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP3]], i32 1
2780eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP18:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP4]], i32 1
2781eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP19:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP5]], i32 1
2782eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP20:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP6]], i32 1
2783eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP21:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP7]], i32 1
2784eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP22:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP8]], i32 1
2785eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP23:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[TMP9]], i32 1
2786e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP24:%.*]] = extractelement <4 x i16> [[TMP14]], i64 0
2787eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i16 [[TMP24]], i16* [[TMP16]], align 2
2788e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP25:%.*]] = extractelement <4 x i16> [[TMP14]], i64 1
2789eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i16 [[TMP25]], i16* [[TMP17]], align 2
2790e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP26:%.*]] = extractelement <4 x i16> [[TMP14]], i64 2
2791eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i16 [[TMP26]], i16* [[TMP18]], align 2
2792e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP27:%.*]] = extractelement <4 x i16> [[TMP14]], i64 3
2793eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i16 [[TMP27]], i16* [[TMP19]], align 2
2794e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP28:%.*]] = extractelement <4 x i16> [[TMP15]], i64 0
2795eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i16 [[TMP28]], i16* [[TMP20]], align 2
2796e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP29:%.*]] = extractelement <4 x i16> [[TMP15]], i64 1
2797eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i16 [[TMP29]], i16* [[TMP21]], align 2
2798e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP30:%.*]] = extractelement <4 x i16> [[TMP15]], i64 2
2799eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i16 [[TMP30]], i16* [[TMP22]], align 2
2800e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP31:%.*]] = extractelement <4 x i16> [[TMP15]], i64 3
2801eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i16 [[TMP31]], i16* [[TMP23]], align 2
2802eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
28030c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND_NEXT]] = add <4 x i32> [[VEC_IND]], <i32 8, i32 8, i32 8, i32 8>
2804eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP32:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
2805eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP32]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP26:![0-9]+]]
2806eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
2807eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
2808eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
2809eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
2810eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
2811eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
2812eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
2813eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
2814eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP33:%.*]] = trunc i64 [[I]] to i32
2815eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP34:%.*]] = add i32 [[TMP33]], [[A]]
2816eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP35:%.*]] = trunc i32 [[TMP34]] to i16
2817eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP36:%.*]] = getelementptr inbounds [[PAIR_I16]], %pair.i16* [[P]], i64 [[I]], i32 1
2818eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i16 [[TMP35]], i16* [[TMP36]], align 2
2819eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
2820eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP37:%.*]] = trunc i64 [[I_NEXT]] to i32
2821eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[COND:%.*]] = icmp eq i32 [[TMP37]], [[N]]
2822eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[COND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP27:![0-9]+]]
2823eb052f6bSPhilip Reames; INTERLEAVE:       for.end:
2824eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
2825eb052f6bSPhilip Reames;
2826cee313d2SEric Christopherentry:
2827cee313d2SEric Christopher  br label %for.body
2828cee313d2SEric Christopher
2829cee313d2SEric Christopherfor.body:
2830cee313d2SEric Christopher  %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
2831cee313d2SEric Christopher  %0 = trunc i64 %i to i32
2832cee313d2SEric Christopher  %1 = add i32 %a, %0
2833cee313d2SEric Christopher  %2 = trunc i32 %1 to i16
2834cee313d2SEric Christopher  %3 = getelementptr inbounds %pair.i16, %pair.i16* %p, i64 %i, i32 1
2835cee313d2SEric Christopher  store i16 %2, i16* %3, align 2
2836cee313d2SEric Christopher  %i.next = add nuw nsw i64 %i, 1
2837cee313d2SEric Christopher  %4 = trunc i64 %i.next to i32
2838cee313d2SEric Christopher  %cond = icmp eq i32 %4, %n
2839cee313d2SEric Christopher  br i1 %cond, label %for.end, label %for.body
2840cee313d2SEric Christopher
2841cee313d2SEric Christopherfor.end:
2842cee313d2SEric Christopher  ret void
2843cee313d2SEric Christopher}
2844cee313d2SEric Christopher
2845cee313d2SEric Christopher; Make sure that the loop exit count computation does not overflow for i8 and
2846cee313d2SEric Christopher; i16. The exit count of these loops is i8/i16 max + 1. If we don't cast the
2847cee313d2SEric Christopher; induction variable to a bigger type the exit count computation will overflow
2848cee313d2SEric Christopher; to 0.
2849cee313d2SEric Christopher; PR17532
2850cee313d2SEric Christopher
2851cee313d2SEric Christopherdefine i32 @i8_loop() nounwind readnone ssp uwtable {
2852eb052f6bSPhilip Reames; CHECK-LABEL: @i8_loop(
2853b7f69b8dSFlorian Hahn; CHECK-NEXT:  entry:
2854eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2855eb052f6bSPhilip Reames; CHECK:       vector.ph:
2856eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
2857eb052f6bSPhilip Reames; CHECK:       vector.body:
2858eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
28597c080e46SNikita Popov; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ <i32 1, i32 -1>, [[VECTOR_PH]] ], [ [[TMP0:%.*]], [[VECTOR_BODY]] ]
28607c080e46SNikita Popov; CHECK-NEXT:    [[TMP0]] = and <2 x i32> [[VEC_PHI]], <i32 4, i32 4>
2861eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
28627c080e46SNikita Popov; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[INDEX_NEXT]], 256
28637c080e46SNikita Popov; CHECK-NEXT:    br i1 [[TMP1]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP28:![0-9]+]]
2864eb052f6bSPhilip Reames; CHECK:       middle.block:
28657c080e46SNikita Popov; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @llvm.vector.reduce.and.v2i32(<2 x i32> [[TMP0]])
2866eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i32 256, 256
28677c080e46SNikita Popov; CHECK-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
2868eb052f6bSPhilip Reames; CHECK:       scalar.ph:
28697c080e46SNikita Popov; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ 0, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
28707c080e46SNikita Popov; CHECK-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[TMP2]], [[MIDDLE_BLOCK]] ]
28717c080e46SNikita Popov; CHECK-NEXT:    br label [[LOOP:%.*]]
2872b7f69b8dSFlorian Hahn; CHECK:       loop:
28737c080e46SNikita Popov; CHECK-NEXT:    [[A_0:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[A_0_AND:%.*]], [[LOOP]] ]
28747c080e46SNikita Popov; CHECK-NEXT:    [[B_0:%.*]] = phi i8 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[B_NEXT:%.*]], [[LOOP]] ]
28757c080e46SNikita Popov; CHECK-NEXT:    [[A_0_AND]] = and i32 [[A_0]], 4
28767c080e46SNikita Popov; CHECK-NEXT:    [[B_NEXT]] = add i8 [[B_0]], -1
28777c080e46SNikita Popov; CHECK-NEXT:    [[EC:%.*]] = icmp eq i8 [[B_NEXT]], 0
28787c080e46SNikita Popov; CHECK-NEXT:    br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP29:![0-9]+]]
2879b7f69b8dSFlorian Hahn; CHECK:       exit:
28807c080e46SNikita Popov; CHECK-NEXT:    [[A_0_AND_LCSSA:%.*]] = phi i32 [ [[A_0_AND]], [[LOOP]] ], [ [[TMP2]], [[MIDDLE_BLOCK]] ]
28817c080e46SNikita Popov; CHECK-NEXT:    ret i32 [[A_0_AND_LCSSA]]
2882eb052f6bSPhilip Reames;
2883eb052f6bSPhilip Reames; IND-LABEL: @i8_loop(
2884b7f69b8dSFlorian Hahn; IND-NEXT:  entry:
2885eb052f6bSPhilip Reames; IND-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2886eb052f6bSPhilip Reames; IND:       vector.ph:
2887eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
2888eb052f6bSPhilip Reames; IND:       vector.body:
2889eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
2890eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
28917c080e46SNikita Popov; IND-NEXT:    [[TMP0:%.*]] = icmp eq i32 [[INDEX_NEXT]], 256
28927c080e46SNikita Popov; IND-NEXT:    br i1 [[TMP0]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP28:![0-9]+]]
2893eb052f6bSPhilip Reames; IND:       middle.block:
28947c080e46SNikita Popov; IND-NEXT:    br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]
2895eb052f6bSPhilip Reames; IND:       scalar.ph:
28967c080e46SNikita Popov; IND-NEXT:    br label [[LOOP:%.*]]
2897b7f69b8dSFlorian Hahn; IND:       loop:
2898*9df0b254SNuno Lopes; IND-NEXT:    br i1 poison, label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP29:![0-9]+]]
2899b7f69b8dSFlorian Hahn; IND:       exit:
2900eb052f6bSPhilip Reames; IND-NEXT:    ret i32 0
2901eb052f6bSPhilip Reames;
2902eb052f6bSPhilip Reames; UNROLL-LABEL: @i8_loop(
2903b7f69b8dSFlorian Hahn; UNROLL-NEXT:  entry:
2904eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2905eb052f6bSPhilip Reames; UNROLL:       vector.ph:
2906eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
2907eb052f6bSPhilip Reames; UNROLL:       vector.body:
2908eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
2909eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
29107c080e46SNikita Popov; UNROLL-NEXT:    [[TMP0:%.*]] = icmp eq i32 [[INDEX_NEXT]], 256
29117c080e46SNikita Popov; UNROLL-NEXT:    br i1 [[TMP0]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP28:![0-9]+]]
2912eb052f6bSPhilip Reames; UNROLL:       middle.block:
29137c080e46SNikita Popov; UNROLL-NEXT:    br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]
2914eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
29157c080e46SNikita Popov; UNROLL-NEXT:    br label [[LOOP:%.*]]
2916b7f69b8dSFlorian Hahn; UNROLL:       loop:
2917*9df0b254SNuno Lopes; UNROLL-NEXT:    br i1 poison, label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP29:![0-9]+]]
2918b7f69b8dSFlorian Hahn; UNROLL:       exit:
2919eb052f6bSPhilip Reames; UNROLL-NEXT:    ret i32 0
2920eb052f6bSPhilip Reames;
2921eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @i8_loop(
2922b7f69b8dSFlorian Hahn; UNROLL-NO-IC-NEXT:  entry:
2923eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2924eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
2925eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
2926eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
2927eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
29287c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ <i32 1, i32 -1>, [[VECTOR_PH]] ], [ [[TMP0:%.*]], [[VECTOR_BODY]] ]
29297c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_PHI1:%.*]] = phi <2 x i32> [ <i32 -1, i32 -1>, [[VECTOR_PH]] ], [ [[TMP1:%.*]], [[VECTOR_BODY]] ]
29307c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP0]] = and <2 x i32> [[VEC_PHI]], <i32 4, i32 4>
29317c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP1]] = and <2 x i32> [[VEC_PHI1]], <i32 4, i32 4>
2932eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
29337c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = icmp eq i32 [[INDEX_NEXT]], 256
29347c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP2]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP28:![0-9]+]]
2935eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
29367c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[BIN_RDX:%.*]] = and <2 x i32> [[TMP1]], [[TMP0]]
29377c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = call i32 @llvm.vector.reduce.and.v2i32(<2 x i32> [[BIN_RDX]])
2938eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i32 256, 256
29397c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
2940eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
29417c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ 0, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
29427c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[TMP3]], [[MIDDLE_BLOCK]] ]
29437c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br label [[LOOP:%.*]]
2944b7f69b8dSFlorian Hahn; UNROLL-NO-IC:       loop:
29457c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[A_0:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[A_0_AND:%.*]], [[LOOP]] ]
29467c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[B_0:%.*]] = phi i8 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[B_NEXT:%.*]], [[LOOP]] ]
29477c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[A_0_AND]] = and i32 [[A_0]], 4
29487c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[B_NEXT]] = add i8 [[B_0]], -1
29497c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[EC:%.*]] = icmp eq i8 [[B_NEXT]], 0
29507c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP29:![0-9]+]]
2951b7f69b8dSFlorian Hahn; UNROLL-NO-IC:       exit:
29527c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[A_0_AND_LCSSA:%.*]] = phi i32 [ [[A_0_AND]], [[LOOP]] ], [ [[TMP3]], [[MIDDLE_BLOCK]] ]
29537c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    ret i32 [[A_0_AND_LCSSA]]
2954eb052f6bSPhilip Reames;
2955eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @i8_loop(
2956b7f69b8dSFlorian Hahn; INTERLEAVE-NEXT:  entry:
2957eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2958eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
2959eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
2960eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
2961eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
2962eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8
29637c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP0:%.*]] = icmp eq i32 [[INDEX_NEXT]], 256
29647c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP0]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP28:![0-9]+]]
2965eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
29667c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]
2967eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
29687c080e46SNikita Popov; INTERLEAVE-NEXT:    br label [[LOOP:%.*]]
2969b7f69b8dSFlorian Hahn; INTERLEAVE:       loop:
2970*9df0b254SNuno Lopes; INTERLEAVE-NEXT:    br i1 poison, label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP29:![0-9]+]]
2971b7f69b8dSFlorian Hahn; INTERLEAVE:       exit:
2972eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret i32 0
2973eb052f6bSPhilip Reames;
2974b7f69b8dSFlorian Hahnentry:
2975b7f69b8dSFlorian Hahn  br label %loop
2976cee313d2SEric Christopher
2977b7f69b8dSFlorian Hahnloop:
2978b7f69b8dSFlorian Hahn  %a.0 = phi i32 [ 1, %entry ], [ %a.0.and, %loop ]
2979b7f69b8dSFlorian Hahn  %b.0 = phi i8 [ 0, %entry ], [ %b.next, %loop ]
2980b7f69b8dSFlorian Hahn  %a.0.and = and i32 %a.0, 4
2981b7f69b8dSFlorian Hahn  %b.next = add i8 %b.0, -1
2982b7f69b8dSFlorian Hahn  %ec = icmp eq i8 %b.next, 0
2983b7f69b8dSFlorian Hahn  br i1 %ec, label %exit, label %loop
2984cee313d2SEric Christopher
2985b7f69b8dSFlorian Hahnexit:
2986b7f69b8dSFlorian Hahn  ret i32 %a.0.and
2987cee313d2SEric Christopher}
2988cee313d2SEric Christopher
2989cee313d2SEric Christopher
2990cee313d2SEric Christopherdefine i32 @i16_loop() nounwind readnone ssp uwtable {
2991eb052f6bSPhilip Reames; CHECK-LABEL: @i16_loop(
2992b7f69b8dSFlorian Hahn; CHECK-NEXT:  entry:
2993eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
2994eb052f6bSPhilip Reames; CHECK:       vector.ph:
2995eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
2996eb052f6bSPhilip Reames; CHECK:       vector.body:
2997eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
29987c080e46SNikita Popov; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ <i32 1, i32 -1>, [[VECTOR_PH]] ], [ [[TMP0:%.*]], [[VECTOR_BODY]] ]
29997c080e46SNikita Popov; CHECK-NEXT:    [[TMP0]] = and <2 x i32> [[VEC_PHI]], <i32 4, i32 4>
3000eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
30017c080e46SNikita Popov; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[INDEX_NEXT]], 65536
30027c080e46SNikita Popov; CHECK-NEXT:    br i1 [[TMP1]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP30:![0-9]+]]
3003eb052f6bSPhilip Reames; CHECK:       middle.block:
30047c080e46SNikita Popov; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @llvm.vector.reduce.and.v2i32(<2 x i32> [[TMP0]])
3005eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i32 65536, 65536
30067c080e46SNikita Popov; CHECK-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
3007eb052f6bSPhilip Reames; CHECK:       scalar.ph:
30087c080e46SNikita Popov; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i16 [ 0, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
30097c080e46SNikita Popov; CHECK-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[TMP2]], [[MIDDLE_BLOCK]] ]
30107c080e46SNikita Popov; CHECK-NEXT:    br label [[LOOP:%.*]]
3011b7f69b8dSFlorian Hahn; CHECK:       loop:
30127c080e46SNikita Popov; CHECK-NEXT:    [[A_0:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[A_0_AND:%.*]], [[LOOP]] ]
30137c080e46SNikita Popov; CHECK-NEXT:    [[B_0:%.*]] = phi i16 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[B_0_NEXT:%.*]], [[LOOP]] ]
30147c080e46SNikita Popov; CHECK-NEXT:    [[A_0_AND]] = and i32 [[A_0]], 4
30157c080e46SNikita Popov; CHECK-NEXT:    [[B_0_NEXT]] = add i16 [[B_0]], -1
30167c080e46SNikita Popov; CHECK-NEXT:    [[EC:%.*]] = icmp eq i16 [[B_0_NEXT]], 0
30177c080e46SNikita Popov; CHECK-NEXT:    br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP31:![0-9]+]]
3018b7f69b8dSFlorian Hahn; CHECK:       exit:
30197c080e46SNikita Popov; CHECK-NEXT:    [[A_0_AND_LCSSA:%.*]] = phi i32 [ [[A_0_AND]], [[LOOP]] ], [ [[TMP2]], [[MIDDLE_BLOCK]] ]
30207c080e46SNikita Popov; CHECK-NEXT:    ret i32 [[A_0_AND_LCSSA]]
3021eb052f6bSPhilip Reames;
3022eb052f6bSPhilip Reames; IND-LABEL: @i16_loop(
3023b7f69b8dSFlorian Hahn; IND-NEXT:  entry:
3024eb052f6bSPhilip Reames; IND-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3025eb052f6bSPhilip Reames; IND:       vector.ph:
3026eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
3027eb052f6bSPhilip Reames; IND:       vector.body:
3028eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
3029eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
30307c080e46SNikita Popov; IND-NEXT:    [[TMP0:%.*]] = icmp eq i32 [[INDEX_NEXT]], 65536
30317c080e46SNikita Popov; IND-NEXT:    br i1 [[TMP0]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP30:![0-9]+]]
3032eb052f6bSPhilip Reames; IND:       middle.block:
30337c080e46SNikita Popov; IND-NEXT:    br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]
3034eb052f6bSPhilip Reames; IND:       scalar.ph:
30357c080e46SNikita Popov; IND-NEXT:    br label [[LOOP:%.*]]
3036b7f69b8dSFlorian Hahn; IND:       loop:
3037*9df0b254SNuno Lopes; IND-NEXT:    br i1 poison, label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP31:![0-9]+]]
3038b7f69b8dSFlorian Hahn; IND:       exit:
3039eb052f6bSPhilip Reames; IND-NEXT:    ret i32 0
3040eb052f6bSPhilip Reames;
3041eb052f6bSPhilip Reames; UNROLL-LABEL: @i16_loop(
3042b7f69b8dSFlorian Hahn; UNROLL-NEXT:  entry:
3043eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3044eb052f6bSPhilip Reames; UNROLL:       vector.ph:
3045eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
3046eb052f6bSPhilip Reames; UNROLL:       vector.body:
3047eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
3048eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
30497c080e46SNikita Popov; UNROLL-NEXT:    [[TMP0:%.*]] = icmp eq i32 [[INDEX_NEXT]], 65536
30507c080e46SNikita Popov; UNROLL-NEXT:    br i1 [[TMP0]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP30:![0-9]+]]
3051eb052f6bSPhilip Reames; UNROLL:       middle.block:
30527c080e46SNikita Popov; UNROLL-NEXT:    br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]
3053eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
30547c080e46SNikita Popov; UNROLL-NEXT:    br label [[LOOP:%.*]]
3055b7f69b8dSFlorian Hahn; UNROLL:       loop:
3056*9df0b254SNuno Lopes; UNROLL-NEXT:    br i1 poison, label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP31:![0-9]+]]
3057b7f69b8dSFlorian Hahn; UNROLL:       exit:
3058eb052f6bSPhilip Reames; UNROLL-NEXT:    ret i32 0
3059eb052f6bSPhilip Reames;
3060eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @i16_loop(
3061b7f69b8dSFlorian Hahn; UNROLL-NO-IC-NEXT:  entry:
3062eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3063eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
3064eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
3065eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
3066eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
30677c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ <i32 1, i32 -1>, [[VECTOR_PH]] ], [ [[TMP0:%.*]], [[VECTOR_BODY]] ]
30687c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_PHI1:%.*]] = phi <2 x i32> [ <i32 -1, i32 -1>, [[VECTOR_PH]] ], [ [[TMP1:%.*]], [[VECTOR_BODY]] ]
30697c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP0]] = and <2 x i32> [[VEC_PHI]], <i32 4, i32 4>
30707c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP1]] = and <2 x i32> [[VEC_PHI1]], <i32 4, i32 4>
3071eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
30727c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = icmp eq i32 [[INDEX_NEXT]], 65536
30737c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP2]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP30:![0-9]+]]
3074eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
30757c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[BIN_RDX:%.*]] = and <2 x i32> [[TMP1]], [[TMP0]]
30767c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = call i32 @llvm.vector.reduce.and.v2i32(<2 x i32> [[BIN_RDX]])
3077eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i32 65536, 65536
30787c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
3079eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
30807c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i16 [ 0, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
30817c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[TMP3]], [[MIDDLE_BLOCK]] ]
30827c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br label [[LOOP:%.*]]
3083b7f69b8dSFlorian Hahn; UNROLL-NO-IC:       loop:
30847c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[A_0:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[A_0_AND:%.*]], [[LOOP]] ]
30857c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[B_0:%.*]] = phi i16 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[B_0_NEXT:%.*]], [[LOOP]] ]
30867c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[A_0_AND]] = and i32 [[A_0]], 4
30877c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[B_0_NEXT]] = add i16 [[B_0]], -1
30887c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[EC:%.*]] = icmp eq i16 [[B_0_NEXT]], 0
30897c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP31:![0-9]+]]
3090b7f69b8dSFlorian Hahn; UNROLL-NO-IC:       exit:
30917c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[A_0_AND_LCSSA:%.*]] = phi i32 [ [[A_0_AND]], [[LOOP]] ], [ [[TMP3]], [[MIDDLE_BLOCK]] ]
30927c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    ret i32 [[A_0_AND_LCSSA]]
3093eb052f6bSPhilip Reames;
3094eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @i16_loop(
3095b7f69b8dSFlorian Hahn; INTERLEAVE-NEXT:  entry:
3096eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3097eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
3098eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
3099eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
3100eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
3101eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8
31027c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP0:%.*]] = icmp eq i32 [[INDEX_NEXT]], 65536
31037c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP0]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP30:![0-9]+]]
3104eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
31057c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]
3106eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
31077c080e46SNikita Popov; INTERLEAVE-NEXT:    br label [[LOOP:%.*]]
3108b7f69b8dSFlorian Hahn; INTERLEAVE:       loop:
3109*9df0b254SNuno Lopes; INTERLEAVE-NEXT:    br i1 poison, label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP31:![0-9]+]]
3110b7f69b8dSFlorian Hahn; INTERLEAVE:       exit:
3111eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret i32 0
3112eb052f6bSPhilip Reames;
3113b7f69b8dSFlorian Hahnentry:
3114b7f69b8dSFlorian Hahn  br label %loop
3115cee313d2SEric Christopher
3116b7f69b8dSFlorian Hahnloop:
3117b7f69b8dSFlorian Hahn  %a.0 = phi i32 [ 1, %entry ], [ %a.0.and, %loop ]
3118b7f69b8dSFlorian Hahn  %b.0 = phi i16 [ 0, %entry ], [ %b.0.next, %loop ]
3119b7f69b8dSFlorian Hahn  %a.0.and = and i32 %a.0, 4
3120b7f69b8dSFlorian Hahn  %b.0.next = add i16 %b.0, -1
3121b7f69b8dSFlorian Hahn  %ec = icmp eq i16 %b.0.next, 0
3122b7f69b8dSFlorian Hahn  br i1 %ec, label %exit, label %loop
3123cee313d2SEric Christopher
3124b7f69b8dSFlorian Hahnexit:
3125b7f69b8dSFlorian Hahn  ret i32 %a.0.and
3126cee313d2SEric Christopher}
3127cee313d2SEric Christopher
3128cee313d2SEric Christopher; This loop has a backedge taken count of i32_max. We need to check for this
3129cee313d2SEric Christopher; condition and branch directly to the scalar loop.
3130cee313d2SEric Christopher
3131cee313d2SEric Christopher
3132cee313d2SEric Christopher
3133cee313d2SEric Christopherdefine i32 @max_i32_backedgetaken() nounwind readnone ssp uwtable {
3134eb052f6bSPhilip Reames; CHECK-LABEL: @max_i32_backedgetaken(
3135b7f69b8dSFlorian Hahn; CHECK-NEXT:  entry:
3136eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 true, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3137eb052f6bSPhilip Reames; CHECK:       vector.ph:
3138eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
3139eb052f6bSPhilip Reames; CHECK:       vector.body:
3140eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
31417c080e46SNikita Popov; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ <i32 1, i32 -1>, [[VECTOR_PH]] ], [ [[TMP0:%.*]], [[VECTOR_BODY]] ]
31427c080e46SNikita Popov; CHECK-NEXT:    [[TMP0]] = and <2 x i32> [[VEC_PHI]], <i32 4, i32 4>
3143eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
31447c080e46SNikita Popov; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[INDEX_NEXT]], 0
31457c080e46SNikita Popov; CHECK-NEXT:    br i1 [[TMP1]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP32:![0-9]+]]
3146eb052f6bSPhilip Reames; CHECK:       middle.block:
31477c080e46SNikita Popov; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @llvm.vector.reduce.and.v2i32(<2 x i32> [[TMP0]])
3148eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i32 0, 0
31497c080e46SNikita Popov; CHECK-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
3150eb052f6bSPhilip Reames; CHECK:       scalar.ph:
31517c080e46SNikita Popov; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ 0, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
31527c080e46SNikita Popov; CHECK-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[TMP2]], [[MIDDLE_BLOCK]] ]
31537c080e46SNikita Popov; CHECK-NEXT:    br label [[LOOP:%.*]]
3154b7f69b8dSFlorian Hahn; CHECK:       loop:
31557c080e46SNikita Popov; CHECK-NEXT:    [[A_0:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[A_0_AND:%.*]], [[LOOP]] ]
31567c080e46SNikita Popov; CHECK-NEXT:    [[B_0:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[B_NEXT:%.*]], [[LOOP]] ]
31577c080e46SNikita Popov; CHECK-NEXT:    [[A_0_AND]] = and i32 [[A_0]], 4
31587c080e46SNikita Popov; CHECK-NEXT:    [[B_NEXT]] = add i32 [[B_0]], -1
31597c080e46SNikita Popov; CHECK-NEXT:    [[EC:%.*]] = icmp eq i32 [[B_NEXT]], 0
31607c080e46SNikita Popov; CHECK-NEXT:    br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP33:![0-9]+]]
3161b7f69b8dSFlorian Hahn; CHECK:       exit:
31627c080e46SNikita Popov; CHECK-NEXT:    [[A_0_AND_LCSSA:%.*]] = phi i32 [ [[A_0_AND]], [[LOOP]] ], [ [[TMP2]], [[MIDDLE_BLOCK]] ]
31637c080e46SNikita Popov; CHECK-NEXT:    ret i32 [[A_0_AND_LCSSA]]
3164eb052f6bSPhilip Reames;
3165eb052f6bSPhilip Reames; IND-LABEL: @max_i32_backedgetaken(
3166b7f69b8dSFlorian Hahn; IND-NEXT:  entry:
3167eb052f6bSPhilip Reames; IND-NEXT:    br i1 true, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3168eb052f6bSPhilip Reames; IND:       vector.ph:
3169eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
3170eb052f6bSPhilip Reames; IND:       vector.body:
3171*9df0b254SNuno Lopes; IND-NEXT:    br i1 poison, label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP32:![0-9]+]]
3172eb052f6bSPhilip Reames; IND:       middle.block:
3173*9df0b254SNuno Lopes; IND-NEXT:    br i1 poison, label [[EXIT:%.*]], label [[SCALAR_PH]]
3174eb052f6bSPhilip Reames; IND:       scalar.ph:
31757c080e46SNikita Popov; IND-NEXT:    br label [[LOOP:%.*]]
3176b7f69b8dSFlorian Hahn; IND:       loop:
31777c080e46SNikita Popov; IND-NEXT:    [[B_0:%.*]] = phi i32 [ 0, [[SCALAR_PH]] ], [ [[B_NEXT:%.*]], [[LOOP]] ]
31787c080e46SNikita Popov; IND-NEXT:    [[B_NEXT]] = add i32 [[B_0]], -1
31797c080e46SNikita Popov; IND-NEXT:    [[EC:%.*]] = icmp eq i32 [[B_NEXT]], 0
31807c080e46SNikita Popov; IND-NEXT:    br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP33:![0-9]+]]
3181b7f69b8dSFlorian Hahn; IND:       exit:
3182eb052f6bSPhilip Reames; IND-NEXT:    ret i32 0
3183eb052f6bSPhilip Reames;
3184eb052f6bSPhilip Reames; UNROLL-LABEL: @max_i32_backedgetaken(
3185b7f69b8dSFlorian Hahn; UNROLL-NEXT:  entry:
3186eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 true, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3187eb052f6bSPhilip Reames; UNROLL:       vector.ph:
3188eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
3189eb052f6bSPhilip Reames; UNROLL:       vector.body:
3190*9df0b254SNuno Lopes; UNROLL-NEXT:    br i1 poison, label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP32:![0-9]+]]
3191eb052f6bSPhilip Reames; UNROLL:       middle.block:
3192*9df0b254SNuno Lopes; UNROLL-NEXT:    br i1 poison, label [[EXIT:%.*]], label [[SCALAR_PH]]
3193eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
31947c080e46SNikita Popov; UNROLL-NEXT:    br label [[LOOP:%.*]]
3195b7f69b8dSFlorian Hahn; UNROLL:       loop:
31967c080e46SNikita Popov; UNROLL-NEXT:    [[B_0:%.*]] = phi i32 [ 0, [[SCALAR_PH]] ], [ [[B_NEXT:%.*]], [[LOOP]] ]
31977c080e46SNikita Popov; UNROLL-NEXT:    [[B_NEXT]] = add i32 [[B_0]], -1
31987c080e46SNikita Popov; UNROLL-NEXT:    [[EC:%.*]] = icmp eq i32 [[B_NEXT]], 0
31997c080e46SNikita Popov; UNROLL-NEXT:    br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP33:![0-9]+]]
3200b7f69b8dSFlorian Hahn; UNROLL:       exit:
3201eb052f6bSPhilip Reames; UNROLL-NEXT:    ret i32 0
3202eb052f6bSPhilip Reames;
3203eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @max_i32_backedgetaken(
3204b7f69b8dSFlorian Hahn; UNROLL-NO-IC-NEXT:  entry:
3205eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 true, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3206eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
3207eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
3208eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
3209eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
32107c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ <i32 1, i32 -1>, [[VECTOR_PH]] ], [ [[TMP0:%.*]], [[VECTOR_BODY]] ]
32117c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_PHI1:%.*]] = phi <2 x i32> [ <i32 -1, i32 -1>, [[VECTOR_PH]] ], [ [[TMP1:%.*]], [[VECTOR_BODY]] ]
32127c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP0]] = and <2 x i32> [[VEC_PHI]], <i32 4, i32 4>
32137c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP1]] = and <2 x i32> [[VEC_PHI1]], <i32 4, i32 4>
3214eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
32157c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = icmp eq i32 [[INDEX_NEXT]], 0
32167c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP2]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP32:![0-9]+]]
3217eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
32187c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[BIN_RDX:%.*]] = and <2 x i32> [[TMP1]], [[TMP0]]
32197c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = call i32 @llvm.vector.reduce.and.v2i32(<2 x i32> [[BIN_RDX]])
3220eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i32 0, 0
32217c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
3222eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
32237c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ 0, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
32247c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[TMP3]], [[MIDDLE_BLOCK]] ]
32257c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br label [[LOOP:%.*]]
3226b7f69b8dSFlorian Hahn; UNROLL-NO-IC:       loop:
32277c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[A_0:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[A_0_AND:%.*]], [[LOOP]] ]
32287c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[B_0:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[B_NEXT:%.*]], [[LOOP]] ]
32297c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[A_0_AND]] = and i32 [[A_0]], 4
32307c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[B_NEXT]] = add i32 [[B_0]], -1
32317c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[EC:%.*]] = icmp eq i32 [[B_NEXT]], 0
32327c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP33:![0-9]+]]
3233b7f69b8dSFlorian Hahn; UNROLL-NO-IC:       exit:
32347c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[A_0_AND_LCSSA:%.*]] = phi i32 [ [[A_0_AND]], [[LOOP]] ], [ [[TMP3]], [[MIDDLE_BLOCK]] ]
32357c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    ret i32 [[A_0_AND_LCSSA]]
3236eb052f6bSPhilip Reames;
3237eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @max_i32_backedgetaken(
3238b7f69b8dSFlorian Hahn; INTERLEAVE-NEXT:  entry:
3239eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 true, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3240eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
3241eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
3242eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
3243*9df0b254SNuno Lopes; INTERLEAVE-NEXT:    br i1 poison, label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP32:![0-9]+]]
3244eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
3245*9df0b254SNuno Lopes; INTERLEAVE-NEXT:    br i1 poison, label [[EXIT:%.*]], label [[SCALAR_PH]]
3246eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
32477c080e46SNikita Popov; INTERLEAVE-NEXT:    br label [[LOOP:%.*]]
3248b7f69b8dSFlorian Hahn; INTERLEAVE:       loop:
32497c080e46SNikita Popov; INTERLEAVE-NEXT:    [[B_0:%.*]] = phi i32 [ 0, [[SCALAR_PH]] ], [ [[B_NEXT:%.*]], [[LOOP]] ]
32507c080e46SNikita Popov; INTERLEAVE-NEXT:    [[B_NEXT]] = add i32 [[B_0]], -1
32517c080e46SNikita Popov; INTERLEAVE-NEXT:    [[EC:%.*]] = icmp eq i32 [[B_NEXT]], 0
32527c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 [[EC]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP33:![0-9]+]]
3253b7f69b8dSFlorian Hahn; INTERLEAVE:       exit:
3254eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret i32 0
3255eb052f6bSPhilip Reames;
3256b7f69b8dSFlorian Hahnentry:
3257b7f69b8dSFlorian Hahn  br label %loop
3258cee313d2SEric Christopher
3259b7f69b8dSFlorian Hahnloop:
3260b7f69b8dSFlorian Hahn  %a.0 = phi i32 [ 1, %entry ], [ %a.0.and, %loop ]
3261b7f69b8dSFlorian Hahn  %b.0 = phi i32 [ 0, %entry ], [ %b.next, %loop ]
3262b7f69b8dSFlorian Hahn  %a.0.and = and i32 %a.0, 4
3263b7f69b8dSFlorian Hahn  %b.next = add i32 %b.0, -1
3264b7f69b8dSFlorian Hahn  %ec = icmp eq i32 %b.next, 0
3265b7f69b8dSFlorian Hahn  br i1 %ec, label %exit, label %loop
3266cee313d2SEric Christopher
3267b7f69b8dSFlorian Hahnexit:
3268b7f69b8dSFlorian Hahn  ret i32 %a.0.and
3269cee313d2SEric Christopher}
3270cee313d2SEric Christopher
3271cee313d2SEric Christopher; When generating the overflow check we must sure that the induction start value
3272cee313d2SEric Christopher; is defined before the branch to the scalar preheader.
3273cee313d2SEric Christopher
3274cee313d2SEric Christopher
3275cee313d2SEric Christopher
3276cee313d2SEric Christopher@e = global i8 1, align 1
3277cee313d2SEric Christopher@d = common global i32 0, align 4
3278cee313d2SEric Christopher@c = common global i32 0, align 4
3279cee313d2SEric Christopherdefine i32 @testoverflowcheck() {
3280eb052f6bSPhilip Reames; CHECK-LABEL: @testoverflowcheck(
3281eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
3282eb052f6bSPhilip Reames; CHECK-NEXT:    [[DOTPR_I:%.*]] = load i8, i8* @e, align 1
3283eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* @d, align 4
3284eb052f6bSPhilip Reames; CHECK-NEXT:    [[C_PROMOTED_I:%.*]] = load i32, i32* @c, align 4
3285eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = sub i8 -1, [[DOTPR_I]]
3286eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = zext i8 [[TMP1]] to i32
3287eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = add nuw nsw i32 [[TMP2]], 1
3288eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP3]], 2
3289eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3290eb052f6bSPhilip Reames; CHECK:       vector.ph:
3291eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[TMP3]], 2
3292eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i32 [[TMP3]], [[N_MOD_VF]]
32930c00dbb9SNikita Popov; CHECK-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
32940c00dbb9SNikita Popov; CHECK-NEXT:    [[IND_END:%.*]] = add i8 [[DOTPR_I]], [[CAST_VTC]]
3295eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = insertelement <2 x i32> <i32 -1, i32 -1>, i32 [[C_PROMOTED_I]], i32 0
3296eb052f6bSPhilip Reames; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[TMP0]], i32 0
3297eb052f6bSPhilip Reames; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
3298eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
3299eb052f6bSPhilip Reames; CHECK:       vector.body:
3300eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
33017c080e46SNikita Popov; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ [[TMP4]], [[VECTOR_PH]] ], [ [[TMP5:%.*]], [[VECTOR_BODY]] ]
33027c080e46SNikita Popov; CHECK-NEXT:    [[TMP5]] = and <2 x i32> [[BROADCAST_SPLAT]], [[VEC_PHI]]
3303eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
33047c080e46SNikita Popov; CHECK-NEXT:    [[TMP6:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
33057c080e46SNikita Popov; CHECK-NEXT:    br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP34:![0-9]+]]
3306eb052f6bSPhilip Reames; CHECK:       middle.block:
33077c080e46SNikita Popov; CHECK-NEXT:    [[TMP7:%.*]] = call i32 @llvm.vector.reduce.and.v2i32(<2 x i32> [[TMP5]])
3308eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP3]], [[N_VEC]]
3309eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
3310eb052f6bSPhilip Reames; CHECK:       scalar.ph:
3311eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[DOTPR_I]], [[ENTRY:%.*]] ]
33127c080e46SNikita Popov; CHECK-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ [[C_PROMOTED_I]], [[ENTRY]] ], [ [[TMP7]], [[MIDDLE_BLOCK]] ]
3313eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[COND_END_I:%.*]]
3314eb052f6bSPhilip Reames; CHECK:       cond.end.i:
3315eb052f6bSPhilip Reames; CHECK-NEXT:    [[INC4_I:%.*]] = phi i8 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INC_I:%.*]], [[COND_END_I]] ]
3316eb052f6bSPhilip Reames; CHECK-NEXT:    [[AND3_I:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[AND_I:%.*]], [[COND_END_I]] ]
3317eb052f6bSPhilip Reames; CHECK-NEXT:    [[AND_I]] = and i32 [[TMP0]], [[AND3_I]]
3318eb052f6bSPhilip Reames; CHECK-NEXT:    [[INC_I]] = add i8 [[INC4_I]], 1
3319eb052f6bSPhilip Reames; CHECK-NEXT:    [[TOBOOL_I:%.*]] = icmp eq i8 [[INC_I]], 0
3320eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TOBOOL_I]], label [[LOOPEXIT]], label [[COND_END_I]], !llvm.loop [[LOOP35:![0-9]+]]
3321eb052f6bSPhilip Reames; CHECK:       loopexit:
33227c080e46SNikita Popov; CHECK-NEXT:    [[AND_I_LCSSA:%.*]] = phi i32 [ [[AND_I]], [[COND_END_I]] ], [ [[TMP7]], [[MIDDLE_BLOCK]] ]
3323eb052f6bSPhilip Reames; CHECK-NEXT:    ret i32 [[AND_I_LCSSA]]
3324eb052f6bSPhilip Reames;
3325eb052f6bSPhilip Reames; IND-LABEL: @testoverflowcheck(
3326eb052f6bSPhilip Reames; IND-NEXT:  entry:
3327eb052f6bSPhilip Reames; IND-NEXT:    [[DOTPR_I:%.*]] = load i8, i8* @e, align 1
3328eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = load i32, i32* @d, align 4
3329eb052f6bSPhilip Reames; IND-NEXT:    [[C_PROMOTED_I:%.*]] = load i32, i32* @c, align 4
3330eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = xor i8 [[DOTPR_I]], -1
3331eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = zext i8 [[TMP1]] to i32
3332eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = add nuw nsw i32 [[TMP2]], 1
3333eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp eq i8 [[DOTPR_I]], -1
3334eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3335eb052f6bSPhilip Reames; IND:       vector.ph:
3336eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i32 [[TMP3]], 510
33370c00dbb9SNikita Popov; IND-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
33380c00dbb9SNikita Popov; IND-NEXT:    [[IND_END:%.*]] = add i8 [[DOTPR_I]], [[CAST_VTC]]
3339e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = insertelement <2 x i32> <i32 poison, i32 -1>, i32 [[C_PROMOTED_I]], i64 0
3340e6ad9ef4SPhilip Reames; IND-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[TMP0]], i64 0
3341eb052f6bSPhilip Reames; IND-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
3342eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
3343eb052f6bSPhilip Reames; IND:       vector.body:
3344eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
3345eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
3346eb052f6bSPhilip Reames; IND-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
3347eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP34:![0-9]+]]
3348eb052f6bSPhilip Reames; IND:       middle.block:
3349eb052f6bSPhilip Reames; IND-NEXT:    [[TMP6:%.*]] = and <2 x i32> [[TMP4]], [[BROADCAST_SPLAT]]
3350eb052f6bSPhilip Reames; IND-NEXT:    [[TMP7:%.*]] = call i32 @llvm.vector.reduce.and.v2i32(<2 x i32> [[TMP6]])
3351eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP3]], [[N_VEC]]
3352eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
3353eb052f6bSPhilip Reames; IND:       scalar.ph:
3354eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[DOTPR_I]], [[ENTRY:%.*]] ]
3355eb052f6bSPhilip Reames; IND-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP7]], [[MIDDLE_BLOCK]] ], [ [[C_PROMOTED_I]], [[ENTRY]] ]
3356eb052f6bSPhilip Reames; IND-NEXT:    br label [[COND_END_I:%.*]]
3357eb052f6bSPhilip Reames; IND:       cond.end.i:
3358eb052f6bSPhilip Reames; IND-NEXT:    [[INC4_I:%.*]] = phi i8 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INC_I:%.*]], [[COND_END_I]] ]
3359eb052f6bSPhilip Reames; IND-NEXT:    [[TMP8:%.*]] = and i32 [[BC_MERGE_RDX]], [[TMP0]]
3360eb052f6bSPhilip Reames; IND-NEXT:    [[INC_I]] = add i8 [[INC4_I]], 1
3361eb052f6bSPhilip Reames; IND-NEXT:    [[TOBOOL_I:%.*]] = icmp eq i8 [[INC_I]], 0
3362eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TOBOOL_I]], label [[LOOPEXIT]], label [[COND_END_I]], !llvm.loop [[LOOP35:![0-9]+]]
3363eb052f6bSPhilip Reames; IND:       loopexit:
3364eb052f6bSPhilip Reames; IND-NEXT:    [[AND_I_LCSSA:%.*]] = phi i32 [ [[TMP8]], [[COND_END_I]] ], [ [[TMP7]], [[MIDDLE_BLOCK]] ]
3365eb052f6bSPhilip Reames; IND-NEXT:    ret i32 [[AND_I_LCSSA]]
3366eb052f6bSPhilip Reames;
3367eb052f6bSPhilip Reames; UNROLL-LABEL: @testoverflowcheck(
3368eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
3369eb052f6bSPhilip Reames; UNROLL-NEXT:    [[DOTPR_I:%.*]] = load i8, i8* @e, align 1
3370eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = load i32, i32* @d, align 4
3371eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C_PROMOTED_I:%.*]] = load i32, i32* @c, align 4
3372eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = xor i8 [[DOTPR_I]], -1
3373eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = zext i8 [[TMP1]] to i32
3374eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = add nuw nsw i32 [[TMP2]], 1
3375eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ugt i8 [[DOTPR_I]], -4
3376eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3377eb052f6bSPhilip Reames; UNROLL:       vector.ph:
3378eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i32 [[TMP3]], 508
33790c00dbb9SNikita Popov; UNROLL-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
33800c00dbb9SNikita Popov; UNROLL-NEXT:    [[IND_END:%.*]] = add i8 [[DOTPR_I]], [[CAST_VTC]]
3381e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = insertelement <2 x i32> <i32 poison, i32 -1>, i32 [[C_PROMOTED_I]], i64 0
3382e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[TMP0]], i64 0
3383e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLATINSERT2:%.*]] = insertelement <2 x i32> poison, i32 [[TMP0]], i64 0
3384eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
3385eb052f6bSPhilip Reames; UNROLL:       vector.body:
3386eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
3387eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
3388eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
3389eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP34:![0-9]+]]
3390eb052f6bSPhilip Reames; UNROLL:       middle.block:
3391eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP6:%.*]] = and <2 x i32> [[BROADCAST_SPLATINSERT2]], [[BROADCAST_SPLATINSERT]]
3392eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP7:%.*]] = shufflevector <2 x i32> [[TMP6]], <2 x i32> poison, <2 x i32> zeroinitializer
3393eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BIN_RDX:%.*]] = and <2 x i32> [[TMP7]], [[TMP4]]
3394eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP8:%.*]] = call i32 @llvm.vector.reduce.and.v2i32(<2 x i32> [[BIN_RDX]])
3395eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP3]], [[N_VEC]]
3396eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
3397eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
3398eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[DOTPR_I]], [[ENTRY:%.*]] ]
3399eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP8]], [[MIDDLE_BLOCK]] ], [ [[C_PROMOTED_I]], [[ENTRY]] ]
3400eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[COND_END_I:%.*]]
3401eb052f6bSPhilip Reames; UNROLL:       cond.end.i:
3402eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INC4_I:%.*]] = phi i8 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INC_I:%.*]], [[COND_END_I]] ]
3403eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP9:%.*]] = and i32 [[BC_MERGE_RDX]], [[TMP0]]
3404eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INC_I]] = add i8 [[INC4_I]], 1
3405eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TOBOOL_I:%.*]] = icmp eq i8 [[INC_I]], 0
3406eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TOBOOL_I]], label [[LOOPEXIT]], label [[COND_END_I]], !llvm.loop [[LOOP35:![0-9]+]]
3407eb052f6bSPhilip Reames; UNROLL:       loopexit:
3408eb052f6bSPhilip Reames; UNROLL-NEXT:    [[AND_I_LCSSA:%.*]] = phi i32 [ [[TMP9]], [[COND_END_I]] ], [ [[TMP8]], [[MIDDLE_BLOCK]] ]
3409eb052f6bSPhilip Reames; UNROLL-NEXT:    ret i32 [[AND_I_LCSSA]]
3410eb052f6bSPhilip Reames;
3411eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @testoverflowcheck(
3412eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
3413eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[DOTPR_I:%.*]] = load i8, i8* @e, align 1
3414eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = load i32, i32* @d, align 4
3415eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C_PROMOTED_I:%.*]] = load i32, i32* @c, align 4
3416eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = sub i8 -1, [[DOTPR_I]]
3417eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = zext i8 [[TMP1]] to i32
3418eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = add nuw nsw i32 [[TMP2]], 1
3419eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP3]], 4
3420eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3421eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
3422eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[TMP3]], 4
3423eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i32 [[TMP3]], [[N_MOD_VF]]
34240c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
34250c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[IND_END:%.*]] = add i8 [[DOTPR_I]], [[CAST_VTC]]
3426eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = insertelement <2 x i32> <i32 -1, i32 -1>, i32 [[C_PROMOTED_I]], i32 0
3427eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[TMP0]], i32 0
3428eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
3429eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLATINSERT2:%.*]] = insertelement <2 x i32> poison, i32 [[TMP0]], i32 0
3430eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLAT3:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT2]], <2 x i32> poison, <2 x i32> zeroinitializer
3431eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
3432eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
3433eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
34347c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ [[TMP4]], [[VECTOR_PH]] ], [ [[TMP5:%.*]], [[VECTOR_BODY]] ]
34357c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_PHI1:%.*]] = phi <2 x i32> [ <i32 -1, i32 -1>, [[VECTOR_PH]] ], [ [[TMP6:%.*]], [[VECTOR_BODY]] ]
34367c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP5]] = and <2 x i32> [[BROADCAST_SPLAT]], [[VEC_PHI]]
34377c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP6]] = and <2 x i32> [[BROADCAST_SPLAT3]], [[VEC_PHI1]]
3438eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
34397c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
34407c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP7]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP34:![0-9]+]]
3441eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
34427c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[BIN_RDX:%.*]] = and <2 x i32> [[TMP6]], [[TMP5]]
34437c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = call i32 @llvm.vector.reduce.and.v2i32(<2 x i32> [[BIN_RDX]])
3444eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP3]], [[N_VEC]]
3445eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
3446eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
3447eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[DOTPR_I]], [[ENTRY:%.*]] ]
34487c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ [[C_PROMOTED_I]], [[ENTRY]] ], [ [[TMP8]], [[MIDDLE_BLOCK]] ]
3449eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[COND_END_I:%.*]]
3450eb052f6bSPhilip Reames; UNROLL-NO-IC:       cond.end.i:
3451eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INC4_I:%.*]] = phi i8 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INC_I:%.*]], [[COND_END_I]] ]
3452eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[AND3_I:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[AND_I:%.*]], [[COND_END_I]] ]
3453eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[AND_I]] = and i32 [[TMP0]], [[AND3_I]]
3454eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INC_I]] = add i8 [[INC4_I]], 1
3455eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TOBOOL_I:%.*]] = icmp eq i8 [[INC_I]], 0
3456eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TOBOOL_I]], label [[LOOPEXIT]], label [[COND_END_I]], !llvm.loop [[LOOP35:![0-9]+]]
3457eb052f6bSPhilip Reames; UNROLL-NO-IC:       loopexit:
34587c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[AND_I_LCSSA:%.*]] = phi i32 [ [[AND_I]], [[COND_END_I]] ], [ [[TMP8]], [[MIDDLE_BLOCK]] ]
3459eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret i32 [[AND_I_LCSSA]]
3460eb052f6bSPhilip Reames;
3461eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @testoverflowcheck(
3462eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
3463eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[DOTPR_I:%.*]] = load i8, i8* @e, align 1
3464eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = load i32, i32* @d, align 4
3465eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C_PROMOTED_I:%.*]] = load i32, i32* @c, align 4
3466eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = xor i8 [[DOTPR_I]], -1
3467eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = zext i8 [[TMP1]] to i32
3468eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = add nuw nsw i32 [[TMP2]], 1
3469eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ugt i8 [[DOTPR_I]], -8
3470eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
3471eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
3472eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i32 [[TMP3]], 504
34730c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
34740c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[IND_END:%.*]] = add i8 [[DOTPR_I]], [[CAST_VTC]]
3475e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = insertelement <4 x i32> <i32 poison, i32 -1, i32 -1, i32 -1>, i32 [[C_PROMOTED_I]], i64 0
3476e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[TMP0]], i64 0
3477e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLATINSERT2:%.*]] = insertelement <4 x i32> poison, i32 [[TMP0]], i64 0
3478eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
3479eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
3480eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
3481eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8
3482eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
3483eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP34:![0-9]+]]
3484eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
3485eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = and <4 x i32> [[BROADCAST_SPLATINSERT2]], [[BROADCAST_SPLATINSERT]]
3486eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP7:%.*]] = shufflevector <4 x i32> [[TMP6]], <4 x i32> poison, <4 x i32> zeroinitializer
3487eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BIN_RDX:%.*]] = and <4 x i32> [[TMP7]], [[TMP4]]
3488eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP8:%.*]] = call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> [[BIN_RDX]])
3489eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP3]], [[N_VEC]]
3490eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
3491eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
3492eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[DOTPR_I]], [[ENTRY:%.*]] ]
3493eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP8]], [[MIDDLE_BLOCK]] ], [ [[C_PROMOTED_I]], [[ENTRY]] ]
3494eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[COND_END_I:%.*]]
3495eb052f6bSPhilip Reames; INTERLEAVE:       cond.end.i:
3496eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INC4_I:%.*]] = phi i8 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INC_I:%.*]], [[COND_END_I]] ]
3497eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP9:%.*]] = and i32 [[BC_MERGE_RDX]], [[TMP0]]
3498eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INC_I]] = add i8 [[INC4_I]], 1
3499eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TOBOOL_I:%.*]] = icmp eq i8 [[INC_I]], 0
3500eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TOBOOL_I]], label [[LOOPEXIT]], label [[COND_END_I]], !llvm.loop [[LOOP35:![0-9]+]]
3501eb052f6bSPhilip Reames; INTERLEAVE:       loopexit:
3502eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[AND_I_LCSSA:%.*]] = phi i32 [ [[TMP9]], [[COND_END_I]] ], [ [[TMP8]], [[MIDDLE_BLOCK]] ]
3503eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret i32 [[AND_I_LCSSA]]
3504eb052f6bSPhilip Reames;
3505cee313d2SEric Christopherentry:
3506cee313d2SEric Christopher  %.pr.i = load i8, i8* @e, align 1
3507cee313d2SEric Christopher  %0 = load i32, i32* @d, align 4
3508cee313d2SEric Christopher  %c.promoted.i = load i32, i32* @c, align 4
3509cee313d2SEric Christopher  br label %cond.end.i
3510cee313d2SEric Christopher
3511cee313d2SEric Christophercond.end.i:
3512cee313d2SEric Christopher  %inc4.i = phi i8 [ %.pr.i, %entry ], [ %inc.i, %cond.end.i ]
3513cee313d2SEric Christopher  %and3.i = phi i32 [ %c.promoted.i, %entry ], [ %and.i, %cond.end.i ]
3514cee313d2SEric Christopher  %and.i = and i32 %0, %and3.i
3515cee313d2SEric Christopher  %inc.i = add i8 %inc4.i, 1
3516cee313d2SEric Christopher  %tobool.i = icmp eq i8 %inc.i, 0
3517cee313d2SEric Christopher  br i1 %tobool.i, label %loopexit, label %cond.end.i
3518cee313d2SEric Christopher
3519cee313d2SEric Christopherloopexit:
3520cee313d2SEric Christopher  ret i32 %and.i
3521cee313d2SEric Christopher}
3522cee313d2SEric Christopher
3523cee313d2SEric Christopher; The SCEV expression of %sphi is (zext i8 {%t,+,1}<%loop> to i32)
3524cee313d2SEric Christopher; In order to recognize %sphi as an induction PHI and vectorize this loop,
3525cee313d2SEric Christopher; we need to convert the SCEV expression into an AddRecExpr.
3526cee313d2SEric Christopher; The expression gets converted to {zext i8 %t to i32,+,1}.
3527cee313d2SEric Christopher
3528cee313d2SEric Christopherdefine void @wrappingindvars1(i8 %t, i32 %len, i32 *%A) {
3529eb052f6bSPhilip Reames; CHECK-LABEL: @wrappingindvars1(
3530eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
3531eb052f6bSPhilip Reames; CHECK-NEXT:    [[ST:%.*]] = zext i8 [[T:%.*]] to i16
3532eb052f6bSPhilip Reames; CHECK-NEXT:    [[EXT:%.*]] = zext i8 [[T]] to i32
3533eb052f6bSPhilip Reames; CHECK-NEXT:    [[ECMP:%.*]] = icmp ult i16 [[ST]], 42
3534eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[ECMP]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
3535eb052f6bSPhilip Reames; CHECK:       loop.preheader:
3536eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[LEN:%.*]], 1
3537eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 2
3538eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
3539eb052f6bSPhilip Reames; CHECK:       vector.scevcheck:
3540eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = trunc i32 [[LEN]] to i8
3541eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = add i8 [[T]], [[TMP1]]
35427c080e46SNikita Popov; CHECK-NEXT:    [[TMP3:%.*]] = icmp ult i8 [[TMP2]], [[T]]
35437c080e46SNikita Popov; CHECK-NEXT:    [[TMP4:%.*]] = icmp ugt i32 [[LEN]], 255
35447c080e46SNikita Popov; CHECK-NEXT:    [[TMP5:%.*]] = or i1 [[TMP3]], [[TMP4]]
35457c080e46SNikita Popov; CHECK-NEXT:    [[TMP6:%.*]] = trunc i32 [[LEN]] to i8
35467c080e46SNikita Popov; CHECK-NEXT:    [[TMP7:%.*]] = add i8 [[T]], [[TMP6]]
35477c080e46SNikita Popov; CHECK-NEXT:    [[TMP8:%.*]] = icmp slt i8 [[TMP7]], [[T]]
35487c080e46SNikita Popov; CHECK-NEXT:    [[TMP9:%.*]] = icmp ugt i32 [[LEN]], 255
35497c080e46SNikita Popov; CHECK-NEXT:    [[TMP10:%.*]] = or i1 [[TMP8]], [[TMP9]]
35507c080e46SNikita Popov; CHECK-NEXT:    [[TMP11:%.*]] = or i1 [[TMP5]], [[TMP10]]
35517c080e46SNikita Popov; CHECK-NEXT:    br i1 [[TMP11]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
3552eb052f6bSPhilip Reames; CHECK:       vector.ph:
3553eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[TMP0]], 2
3554eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i32 [[TMP0]], [[N_MOD_VF]]
35550c00dbb9SNikita Popov; CHECK-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
35560c00dbb9SNikita Popov; CHECK-NEXT:    [[IND_END:%.*]] = add i8 [[T]], [[CAST_VTC]]
3557be25f52fSPhilip Reames; CHECK-NEXT:    [[IND_END2:%.*]] = add i32 [[EXT]], [[N_VEC]]
35580c00dbb9SNikita Popov; CHECK-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[EXT]], i32 0
35590c00dbb9SNikita Popov; CHECK-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
35600c00dbb9SNikita Popov; CHECK-NEXT:    [[INDUCTION:%.*]] = add <2 x i32> [[DOTSPLAT]], <i32 0, i32 1>
3561eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
3562eb052f6bSPhilip Reames; CHECK:       vector.body:
3563eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
35640c00dbb9SNikita Popov; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
35657c080e46SNikita Popov; CHECK-NEXT:    [[TMP12:%.*]] = trunc i32 [[INDEX]] to i8
35667c080e46SNikita Popov; CHECK-NEXT:    [[OFFSET_IDX:%.*]] = add i8 [[T]], [[TMP12]]
35677c080e46SNikita Popov; CHECK-NEXT:    [[TMP13:%.*]] = add i8 [[OFFSET_IDX]], 0
35687c080e46SNikita Popov; CHECK-NEXT:    [[TMP14:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i8 [[TMP13]]
35697c080e46SNikita Popov; CHECK-NEXT:    [[TMP15:%.*]] = getelementptr inbounds i32, i32* [[TMP14]], i32 0
35707c080e46SNikita Popov; CHECK-NEXT:    [[TMP16:%.*]] = bitcast i32* [[TMP15]] to <2 x i32>*
35710c00dbb9SNikita Popov; CHECK-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP16]], align 4
3572eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
35730c00dbb9SNikita Popov; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
35747c080e46SNikita Popov; CHECK-NEXT:    [[TMP17:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
35757c080e46SNikita Popov; CHECK-NEXT:    br i1 [[TMP17]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP36:![0-9]+]]
3576eb052f6bSPhilip Reames; CHECK:       middle.block:
3577eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
3578eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[EXIT_LOOPEXIT:%.*]], label [[SCALAR_PH]]
3579eb052f6bSPhilip Reames; CHECK:       scalar.ph:
3580eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[T]], [[LOOP_PREHEADER]] ], [ [[T]], [[VECTOR_SCEVCHECK]] ]
3581eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_PREHEADER]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
3582be25f52fSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL3:%.*]] = phi i32 [ [[IND_END2]], [[MIDDLE_BLOCK]] ], [ [[EXT]], [[LOOP_PREHEADER]] ], [ [[EXT]], [[VECTOR_SCEVCHECK]] ]
3583eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[LOOP:%.*]]
3584eb052f6bSPhilip Reames; CHECK:       loop:
3585eb052f6bSPhilip Reames; CHECK-NEXT:    [[IDX:%.*]] = phi i8 [ [[IDX_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
3586eb052f6bSPhilip Reames; CHECK-NEXT:    [[IDX_B:%.*]] = phi i32 [ [[IDX_B_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
3587be25f52fSPhilip Reames; CHECK-NEXT:    [[SPHI:%.*]] = phi i32 [ [[IDX_INC_EXT:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ]
3588eb052f6bSPhilip Reames; CHECK-NEXT:    [[PTR:%.*]] = getelementptr inbounds i32, i32* [[A]], i8 [[IDX]]
3589eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[SPHI]], i32* [[PTR]], align 4
3590eb052f6bSPhilip Reames; CHECK-NEXT:    [[IDX_INC]] = add i8 [[IDX]], 1
3591eb052f6bSPhilip Reames; CHECK-NEXT:    [[IDX_INC_EXT]] = zext i8 [[IDX_INC]] to i32
3592eb052f6bSPhilip Reames; CHECK-NEXT:    [[IDX_B_INC]] = add nuw nsw i32 [[IDX_B]], 1
3593eb052f6bSPhilip Reames; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[IDX_B]], [[LEN]]
3594eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[C]], label [[LOOP]], label [[EXIT_LOOPEXIT]], !llvm.loop [[LOOP37:![0-9]+]]
3595eb052f6bSPhilip Reames; CHECK:       exit.loopexit:
3596eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[EXIT]]
3597eb052f6bSPhilip Reames; CHECK:       exit:
3598eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
3599eb052f6bSPhilip Reames;
3600eb052f6bSPhilip Reames; IND-LABEL: @wrappingindvars1(
3601eb052f6bSPhilip Reames; IND-NEXT:  entry:
3602eb052f6bSPhilip Reames; IND-NEXT:    [[EXT:%.*]] = zext i8 [[T:%.*]] to i32
3603eb052f6bSPhilip Reames; IND-NEXT:    [[ECMP:%.*]] = icmp ult i8 [[T]], 42
3604eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[ECMP]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
3605eb052f6bSPhilip Reames; IND:       loop.preheader:
3606eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = add i32 [[LEN:%.*]], 1
3607eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 2
3608eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
3609eb052f6bSPhilip Reames; IND:       vector.scevcheck:
3610eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = trunc i32 [[LEN]] to i8
3611eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = xor i8 [[T]], -1
3612eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = icmp ult i8 [[TMP2]], [[TMP1]]
3613356d47ccSNikita Popov; IND-NEXT:    [[TMP4:%.*]] = trunc i32 [[LEN]] to i8
3614356d47ccSNikita Popov; IND-NEXT:    [[TMP5:%.*]] = add i8 [[TMP4]], [[T]]
3615356d47ccSNikita Popov; IND-NEXT:    [[TMP6:%.*]] = icmp slt i8 [[TMP5]], [[T]]
3616356d47ccSNikita Popov; IND-NEXT:    [[TMP7:%.*]] = icmp ugt i32 [[LEN]], 255
3617356d47ccSNikita Popov; IND-NEXT:    [[TMP8:%.*]] = or i1 [[TMP6]], [[TMP7]]
3618356d47ccSNikita Popov; IND-NEXT:    [[TMP9:%.*]] = or i1 [[TMP3]], [[TMP8]]
3619356d47ccSNikita Popov; IND-NEXT:    br i1 [[TMP9]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
3620eb052f6bSPhilip Reames; IND:       vector.ph:
3621eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i32 [[TMP0]], -2
36220c00dbb9SNikita Popov; IND-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
36230c00dbb9SNikita Popov; IND-NEXT:    [[IND_END:%.*]] = add i8 [[CAST_VTC]], [[T]]
3624be25f52fSPhilip Reames; IND-NEXT:    [[IND_END2:%.*]] = add i32 [[N_VEC]], [[EXT]]
36250c00dbb9SNikita Popov; IND-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[EXT]], i64 0
36260c00dbb9SNikita Popov; IND-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
36270c00dbb9SNikita Popov; IND-NEXT:    [[INDUCTION:%.*]] = add nuw nsw <2 x i32> [[DOTSPLAT]], <i32 0, i32 1>
3628eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
3629eb052f6bSPhilip Reames; IND:       vector.body:
3630eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
36310c00dbb9SNikita Popov; IND-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
3632356d47ccSNikita Popov; IND-NEXT:    [[TMP10:%.*]] = trunc i32 [[INDEX]] to i8
3633356d47ccSNikita Popov; IND-NEXT:    [[OFFSET_IDX:%.*]] = add i8 [[TMP10]], [[T]]
3634356d47ccSNikita Popov; IND-NEXT:    [[TMP11:%.*]] = sext i8 [[OFFSET_IDX]] to i64
3635356d47ccSNikita Popov; IND-NEXT:    [[TMP12:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP11]]
3636356d47ccSNikita Popov; IND-NEXT:    [[TMP13:%.*]] = bitcast i32* [[TMP12]] to <2 x i32>*
3637356d47ccSNikita Popov; IND-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP13]], align 4
3638eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
36390c00dbb9SNikita Popov; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
3640356d47ccSNikita Popov; IND-NEXT:    [[TMP14:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
3641356d47ccSNikita Popov; IND-NEXT:    br i1 [[TMP14]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP36:![0-9]+]]
3642eb052f6bSPhilip Reames; IND:       middle.block:
3643eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
3644eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[EXIT_LOOPEXIT:%.*]], label [[SCALAR_PH]]
3645eb052f6bSPhilip Reames; IND:       scalar.ph:
3646eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[T]], [[LOOP_PREHEADER]] ], [ [[T]], [[VECTOR_SCEVCHECK]] ]
3647eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_PREHEADER]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
3648be25f52fSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL3:%.*]] = phi i32 [ [[IND_END2]], [[MIDDLE_BLOCK]] ], [ [[EXT]], [[LOOP_PREHEADER]] ], [ [[EXT]], [[VECTOR_SCEVCHECK]] ]
3649eb052f6bSPhilip Reames; IND-NEXT:    br label [[LOOP:%.*]]
3650eb052f6bSPhilip Reames; IND:       loop:
3651eb052f6bSPhilip Reames; IND-NEXT:    [[IDX:%.*]] = phi i8 [ [[IDX_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
3652eb052f6bSPhilip Reames; IND-NEXT:    [[IDX_B:%.*]] = phi i32 [ [[IDX_B_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
3653be25f52fSPhilip Reames; IND-NEXT:    [[SPHI:%.*]] = phi i32 [ [[IDX_INC_EXT:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ]
3654356d47ccSNikita Popov; IND-NEXT:    [[TMP15:%.*]] = sext i8 [[IDX]] to i64
3655356d47ccSNikita Popov; IND-NEXT:    [[PTR:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP15]]
3656eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[SPHI]], i32* [[PTR]], align 4
3657eb052f6bSPhilip Reames; IND-NEXT:    [[IDX_INC]] = add i8 [[IDX]], 1
3658eb052f6bSPhilip Reames; IND-NEXT:    [[IDX_INC_EXT]] = zext i8 [[IDX_INC]] to i32
3659eb052f6bSPhilip Reames; IND-NEXT:    [[IDX_B_INC]] = add nuw nsw i32 [[IDX_B]], 1
3660eb052f6bSPhilip Reames; IND-NEXT:    [[C:%.*]] = icmp ult i32 [[IDX_B]], [[LEN]]
3661eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[C]], label [[LOOP]], label [[EXIT_LOOPEXIT]], !llvm.loop [[LOOP37:![0-9]+]]
3662eb052f6bSPhilip Reames; IND:       exit.loopexit:
3663eb052f6bSPhilip Reames; IND-NEXT:    br label [[EXIT]]
3664eb052f6bSPhilip Reames; IND:       exit:
3665eb052f6bSPhilip Reames; IND-NEXT:    ret void
3666eb052f6bSPhilip Reames;
3667eb052f6bSPhilip Reames; UNROLL-LABEL: @wrappingindvars1(
3668eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
3669eb052f6bSPhilip Reames; UNROLL-NEXT:    [[EXT:%.*]] = zext i8 [[T:%.*]] to i32
3670eb052f6bSPhilip Reames; UNROLL-NEXT:    [[ECMP:%.*]] = icmp ult i8 [[T]], 42
3671eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[ECMP]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
3672eb052f6bSPhilip Reames; UNROLL:       loop.preheader:
3673eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = add i32 [[LEN:%.*]], 1
3674eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 4
3675eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
3676eb052f6bSPhilip Reames; UNROLL:       vector.scevcheck:
3677eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = trunc i32 [[LEN]] to i8
3678eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = xor i8 [[T]], -1
3679eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = icmp ult i8 [[TMP2]], [[TMP1]]
3680356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP4:%.*]] = trunc i32 [[LEN]] to i8
3681356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP5:%.*]] = add i8 [[TMP4]], [[T]]
3682356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP6:%.*]] = icmp slt i8 [[TMP5]], [[T]]
3683356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP7:%.*]] = icmp ugt i32 [[LEN]], 255
3684356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP8:%.*]] = or i1 [[TMP6]], [[TMP7]]
3685356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP9:%.*]] = or i1 [[TMP3]], [[TMP8]]
3686356d47ccSNikita Popov; UNROLL-NEXT:    br i1 [[TMP9]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
3687eb052f6bSPhilip Reames; UNROLL:       vector.ph:
3688eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i32 [[TMP0]], -4
36890c00dbb9SNikita Popov; UNROLL-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
36900c00dbb9SNikita Popov; UNROLL-NEXT:    [[IND_END:%.*]] = add i8 [[CAST_VTC]], [[T]]
3691be25f52fSPhilip Reames; UNROLL-NEXT:    [[IND_END2:%.*]] = add i32 [[N_VEC]], [[EXT]]
36920c00dbb9SNikita Popov; UNROLL-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[EXT]], i64 0
36930c00dbb9SNikita Popov; UNROLL-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
36940c00dbb9SNikita Popov; UNROLL-NEXT:    [[INDUCTION:%.*]] = add nuw nsw <2 x i32> [[DOTSPLAT]], <i32 0, i32 1>
3695eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
3696eb052f6bSPhilip Reames; UNROLL:       vector.body:
3697eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
36980c00dbb9SNikita Popov; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
36990c00dbb9SNikita Popov; UNROLL-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
3700356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP10:%.*]] = trunc i32 [[INDEX]] to i8
3701356d47ccSNikita Popov; UNROLL-NEXT:    [[OFFSET_IDX:%.*]] = add i8 [[TMP10]], [[T]]
3702356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP11:%.*]] = sext i8 [[OFFSET_IDX]] to i64
3703356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP12:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP11]]
3704356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP13:%.*]] = bitcast i32* [[TMP12]] to <2 x i32>*
3705356d47ccSNikita Popov; UNROLL-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP13]], align 4
3706356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP14:%.*]] = getelementptr inbounds i32, i32* [[TMP12]], i64 2
3707eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP15:%.*]] = bitcast i32* [[TMP14]] to <2 x i32>*
3708356d47ccSNikita Popov; UNROLL-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP15]], align 4
3709eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
37100c00dbb9SNikita Popov; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 4, i32 4>
3711356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP16:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
3712356d47ccSNikita Popov; UNROLL-NEXT:    br i1 [[TMP16]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP36:![0-9]+]]
3713eb052f6bSPhilip Reames; UNROLL:       middle.block:
3714eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
3715eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[EXIT_LOOPEXIT:%.*]], label [[SCALAR_PH]]
3716eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
3717eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[T]], [[LOOP_PREHEADER]] ], [ [[T]], [[VECTOR_SCEVCHECK]] ]
3718eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_PREHEADER]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
3719be25f52fSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL3:%.*]] = phi i32 [ [[IND_END2]], [[MIDDLE_BLOCK]] ], [ [[EXT]], [[LOOP_PREHEADER]] ], [ [[EXT]], [[VECTOR_SCEVCHECK]] ]
3720eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[LOOP:%.*]]
3721eb052f6bSPhilip Reames; UNROLL:       loop:
3722eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IDX:%.*]] = phi i8 [ [[IDX_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
3723eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IDX_B:%.*]] = phi i32 [ [[IDX_B_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
3724be25f52fSPhilip Reames; UNROLL-NEXT:    [[SPHI:%.*]] = phi i32 [ [[IDX_INC_EXT:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ]
3725356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP17:%.*]] = sext i8 [[IDX]] to i64
3726356d47ccSNikita Popov; UNROLL-NEXT:    [[PTR:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP17]]
3727eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[SPHI]], i32* [[PTR]], align 4
3728eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IDX_INC]] = add i8 [[IDX]], 1
3729eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IDX_INC_EXT]] = zext i8 [[IDX_INC]] to i32
3730eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IDX_B_INC]] = add nuw nsw i32 [[IDX_B]], 1
3731eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C:%.*]] = icmp ult i32 [[IDX_B]], [[LEN]]
3732eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[C]], label [[LOOP]], label [[EXIT_LOOPEXIT]], !llvm.loop [[LOOP37:![0-9]+]]
3733eb052f6bSPhilip Reames; UNROLL:       exit.loopexit:
3734eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[EXIT]]
3735eb052f6bSPhilip Reames; UNROLL:       exit:
3736eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
3737eb052f6bSPhilip Reames;
3738eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @wrappingindvars1(
3739eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
3740eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[ST:%.*]] = zext i8 [[T:%.*]] to i16
3741eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[EXT:%.*]] = zext i8 [[T]] to i32
3742eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[ECMP:%.*]] = icmp ult i16 [[ST]], 42
3743eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[ECMP]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
3744eb052f6bSPhilip Reames; UNROLL-NO-IC:       loop.preheader:
3745eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i32 [[LEN:%.*]], 1
3746eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 4
3747eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
3748eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.scevcheck:
3749eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = trunc i32 [[LEN]] to i8
3750eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = add i8 [[T]], [[TMP1]]
37517c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = icmp ult i8 [[TMP2]], [[T]]
37527c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = icmp ugt i32 [[LEN]], 255
37537c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = or i1 [[TMP3]], [[TMP4]]
37547c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = trunc i32 [[LEN]] to i8
37557c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = add i8 [[T]], [[TMP6]]
37567c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = icmp slt i8 [[TMP7]], [[T]]
37577c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = icmp ugt i32 [[LEN]], 255
37587c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = or i1 [[TMP8]], [[TMP9]]
37597c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = or i1 [[TMP5]], [[TMP10]]
37607c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP11]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
3761eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
3762eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[TMP0]], 4
3763eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i32 [[TMP0]], [[N_MOD_VF]]
37640c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
37650c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[IND_END:%.*]] = add i8 [[T]], [[CAST_VTC]]
3766be25f52fSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IND_END2:%.*]] = add i32 [[EXT]], [[N_VEC]]
37670c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[EXT]], i32 0
37680c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
37690c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[INDUCTION:%.*]] = add <2 x i32> [[DOTSPLAT]], <i32 0, i32 1>
3770eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
3771eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
3772eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
37730c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
37740c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
37757c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = trunc i32 [[INDEX]] to i8
37767c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[OFFSET_IDX:%.*]] = add i8 [[T]], [[TMP12]]
37777c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = add i8 [[OFFSET_IDX]], 0
37787c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = add i8 [[OFFSET_IDX]], 2
37797c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i8 [[TMP13]]
37807c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP16:%.*]] = getelementptr inbounds i32, i32* [[A]], i8 [[TMP14]]
37817c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP17:%.*]] = getelementptr inbounds i32, i32* [[TMP15]], i32 0
37827c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP18:%.*]] = bitcast i32* [[TMP17]] to <2 x i32>*
37830c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP18]], align 4
37847c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP19:%.*]] = getelementptr inbounds i32, i32* [[TMP15]], i32 2
37857c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP20:%.*]] = bitcast i32* [[TMP19]] to <2 x i32>*
37860c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP20]], align 4
3787eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
37880c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[STEP_ADD]], <i32 2, i32 2>
37897c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP21:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
37907c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP21]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP36:![0-9]+]]
3791eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
3792eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
3793eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[EXIT_LOOPEXIT:%.*]], label [[SCALAR_PH]]
3794eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
3795eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[T]], [[LOOP_PREHEADER]] ], [ [[T]], [[VECTOR_SCEVCHECK]] ]
3796eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_PREHEADER]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
3797be25f52fSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL3:%.*]] = phi i32 [ [[IND_END2]], [[MIDDLE_BLOCK]] ], [ [[EXT]], [[LOOP_PREHEADER]] ], [ [[EXT]], [[VECTOR_SCEVCHECK]] ]
3798eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[LOOP:%.*]]
3799eb052f6bSPhilip Reames; UNROLL-NO-IC:       loop:
3800eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IDX:%.*]] = phi i8 [ [[IDX_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
3801eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IDX_B:%.*]] = phi i32 [ [[IDX_B_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
3802be25f52fSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SPHI:%.*]] = phi i32 [ [[IDX_INC_EXT:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ]
3803eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[PTR:%.*]] = getelementptr inbounds i32, i32* [[A]], i8 [[IDX]]
3804eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[SPHI]], i32* [[PTR]], align 4
3805eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IDX_INC]] = add i8 [[IDX]], 1
3806eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IDX_INC_EXT]] = zext i8 [[IDX_INC]] to i32
3807eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IDX_B_INC]] = add nuw nsw i32 [[IDX_B]], 1
3808eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C:%.*]] = icmp ult i32 [[IDX_B]], [[LEN]]
3809eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[C]], label [[LOOP]], label [[EXIT_LOOPEXIT]], !llvm.loop [[LOOP37:![0-9]+]]
3810eb052f6bSPhilip Reames; UNROLL-NO-IC:       exit.loopexit:
3811eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[EXIT]]
3812eb052f6bSPhilip Reames; UNROLL-NO-IC:       exit:
3813eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
3814eb052f6bSPhilip Reames;
3815eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @wrappingindvars1(
3816eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
3817eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[EXT:%.*]] = zext i8 [[T:%.*]] to i32
3818eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[ECMP:%.*]] = icmp ult i8 [[T]], 42
3819eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[ECMP]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
3820eb052f6bSPhilip Reames; INTERLEAVE:       loop.preheader:
3821eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = add i32 [[LEN:%.*]], 1
3822eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 8
3823eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
3824eb052f6bSPhilip Reames; INTERLEAVE:       vector.scevcheck:
3825eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = trunc i32 [[LEN]] to i8
3826eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = xor i8 [[T]], -1
3827eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = icmp ult i8 [[TMP2]], [[TMP1]]
3828356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP4:%.*]] = trunc i32 [[LEN]] to i8
3829356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP5:%.*]] = add i8 [[TMP4]], [[T]]
3830356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP6:%.*]] = icmp slt i8 [[TMP5]], [[T]]
3831356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP7:%.*]] = icmp ugt i32 [[LEN]], 255
3832356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP8:%.*]] = or i1 [[TMP6]], [[TMP7]]
3833356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP9:%.*]] = or i1 [[TMP3]], [[TMP8]]
3834356d47ccSNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP9]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
3835eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
3836eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i32 [[TMP0]], -8
38370c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
38380c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[IND_END:%.*]] = add i8 [[CAST_VTC]], [[T]]
3839be25f52fSPhilip Reames; INTERLEAVE-NEXT:    [[IND_END2:%.*]] = add i32 [[N_VEC]], [[EXT]]
38400c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[EXT]], i64 0
38410c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <4 x i32> [[DOTSPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
38420c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[INDUCTION:%.*]] = add nuw nsw <4 x i32> [[DOTSPLAT]], <i32 0, i32 1, i32 2, i32 3>
3843eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
3844eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
3845eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
38460c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND:%.*]] = phi <4 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
38470c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[STEP_ADD:%.*]] = add <4 x i32> [[VEC_IND]], <i32 4, i32 4, i32 4, i32 4>
3848356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP10:%.*]] = trunc i32 [[INDEX]] to i8
3849356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[OFFSET_IDX:%.*]] = add i8 [[TMP10]], [[T]]
3850356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP11:%.*]] = sext i8 [[OFFSET_IDX]] to i64
3851356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP12:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP11]]
3852356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP13:%.*]] = bitcast i32* [[TMP12]] to <4 x i32>*
3853356d47ccSNikita Popov; INTERLEAVE-NEXT:    store <4 x i32> [[VEC_IND]], <4 x i32>* [[TMP13]], align 4
3854356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP14:%.*]] = getelementptr inbounds i32, i32* [[TMP12]], i64 4
3855eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP15:%.*]] = bitcast i32* [[TMP14]] to <4 x i32>*
3856356d47ccSNikita Popov; INTERLEAVE-NEXT:    store <4 x i32> [[STEP_ADD]], <4 x i32>* [[TMP15]], align 4
3857eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8
38580c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND_NEXT]] = add <4 x i32> [[VEC_IND]], <i32 8, i32 8, i32 8, i32 8>
3859356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP16:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
3860356d47ccSNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP16]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP36:![0-9]+]]
3861eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
3862eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
3863eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[EXIT_LOOPEXIT:%.*]], label [[SCALAR_PH]]
3864eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
3865eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[T]], [[LOOP_PREHEADER]] ], [ [[T]], [[VECTOR_SCEVCHECK]] ]
3866eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_PREHEADER]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
3867be25f52fSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL3:%.*]] = phi i32 [ [[IND_END2]], [[MIDDLE_BLOCK]] ], [ [[EXT]], [[LOOP_PREHEADER]] ], [ [[EXT]], [[VECTOR_SCEVCHECK]] ]
3868eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[LOOP:%.*]]
3869eb052f6bSPhilip Reames; INTERLEAVE:       loop:
3870eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IDX:%.*]] = phi i8 [ [[IDX_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
3871eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IDX_B:%.*]] = phi i32 [ [[IDX_B_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
3872be25f52fSPhilip Reames; INTERLEAVE-NEXT:    [[SPHI:%.*]] = phi i32 [ [[IDX_INC_EXT:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ]
3873356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP17:%.*]] = sext i8 [[IDX]] to i64
3874356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[PTR:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP17]]
3875eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[SPHI]], i32* [[PTR]], align 4
3876eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IDX_INC]] = add i8 [[IDX]], 1
3877eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IDX_INC_EXT]] = zext i8 [[IDX_INC]] to i32
3878eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IDX_B_INC]] = add nuw nsw i32 [[IDX_B]], 1
3879eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C:%.*]] = icmp ult i32 [[IDX_B]], [[LEN]]
3880eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[C]], label [[LOOP]], label [[EXIT_LOOPEXIT]], !llvm.loop [[LOOP37:![0-9]+]]
3881eb052f6bSPhilip Reames; INTERLEAVE:       exit.loopexit:
3882eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[EXIT]]
3883eb052f6bSPhilip Reames; INTERLEAVE:       exit:
3884eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
3885eb052f6bSPhilip Reames;
3886cee313d2SEric Christopher  entry:
3887cee313d2SEric Christopher  %st = zext i8 %t to i16
3888cee313d2SEric Christopher  %ext = zext i8 %t to i32
3889cee313d2SEric Christopher  %ecmp = icmp ult i16 %st, 42
3890cee313d2SEric Christopher  br i1 %ecmp, label %loop, label %exit
3891cee313d2SEric Christopher
3892cee313d2SEric Christopher  loop:
3893cee313d2SEric Christopher
3894cee313d2SEric Christopher  %idx = phi i8 [ %t, %entry ], [ %idx.inc, %loop ]
3895cee313d2SEric Christopher  %idx.b = phi i32 [ 0, %entry ], [ %idx.b.inc, %loop ]
3896cee313d2SEric Christopher  %sphi = phi i32 [ %ext, %entry ], [%idx.inc.ext, %loop]
3897cee313d2SEric Christopher
3898cee313d2SEric Christopher  %ptr = getelementptr inbounds i32, i32* %A, i8 %idx
3899cee313d2SEric Christopher  store i32 %sphi, i32* %ptr
3900cee313d2SEric Christopher
3901cee313d2SEric Christopher  %idx.inc = add i8 %idx, 1
3902cee313d2SEric Christopher  %idx.inc.ext = zext i8 %idx.inc to i32
3903cee313d2SEric Christopher  %idx.b.inc = add nuw nsw i32 %idx.b, 1
3904cee313d2SEric Christopher
3905cee313d2SEric Christopher  %c = icmp ult i32 %idx.b, %len
3906cee313d2SEric Christopher  br i1 %c, label %loop, label %exit
3907cee313d2SEric Christopher
3908cee313d2SEric Christopher  exit:
3909cee313d2SEric Christopher  ret void
3910cee313d2SEric Christopher}
3911cee313d2SEric Christopher
3912cee313d2SEric Christopher; The SCEV expression of %sphi is (4 * (zext i8 {%t,+,1}<%loop> to i32))
3913cee313d2SEric Christopher; In order to recognize %sphi as an induction PHI and vectorize this loop,
3914cee313d2SEric Christopher; we need to convert the SCEV expression into an AddRecExpr.
3915cee313d2SEric Christopher; The expression gets converted to ({4 * (zext %t to i32),+,4}).
3916cee313d2SEric Christopherdefine void @wrappingindvars2(i8 %t, i32 %len, i32 *%A) {
3917eb052f6bSPhilip Reames; CHECK-LABEL: @wrappingindvars2(
3918eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
3919eb052f6bSPhilip Reames; CHECK-NEXT:    [[ST:%.*]] = zext i8 [[T:%.*]] to i16
3920eb052f6bSPhilip Reames; CHECK-NEXT:    [[EXT:%.*]] = zext i8 [[T]] to i32
3921eb052f6bSPhilip Reames; CHECK-NEXT:    [[EXT_MUL:%.*]] = mul i32 [[EXT]], 4
3922eb052f6bSPhilip Reames; CHECK-NEXT:    [[ECMP:%.*]] = icmp ult i16 [[ST]], 42
3923eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[ECMP]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
3924eb052f6bSPhilip Reames; CHECK:       loop.preheader:
3925eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[LEN:%.*]], 1
3926eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 2
3927eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
3928eb052f6bSPhilip Reames; CHECK:       vector.scevcheck:
3929eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = trunc i32 [[LEN]] to i8
3930eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = add i8 [[T]], [[TMP1]]
39317c080e46SNikita Popov; CHECK-NEXT:    [[TMP3:%.*]] = icmp ult i8 [[TMP2]], [[T]]
39327c080e46SNikita Popov; CHECK-NEXT:    [[TMP4:%.*]] = icmp ugt i32 [[LEN]], 255
39337c080e46SNikita Popov; CHECK-NEXT:    [[TMP5:%.*]] = or i1 [[TMP3]], [[TMP4]]
39347c080e46SNikita Popov; CHECK-NEXT:    [[TMP6:%.*]] = trunc i32 [[LEN]] to i8
39357c080e46SNikita Popov; CHECK-NEXT:    [[TMP7:%.*]] = add i8 [[T]], [[TMP6]]
39367c080e46SNikita Popov; CHECK-NEXT:    [[TMP8:%.*]] = icmp slt i8 [[TMP7]], [[T]]
39377c080e46SNikita Popov; CHECK-NEXT:    [[TMP9:%.*]] = icmp ugt i32 [[LEN]], 255
39387c080e46SNikita Popov; CHECK-NEXT:    [[TMP10:%.*]] = or i1 [[TMP8]], [[TMP9]]
39397c080e46SNikita Popov; CHECK-NEXT:    [[TMP11:%.*]] = or i1 [[TMP5]], [[TMP10]]
39407c080e46SNikita Popov; CHECK-NEXT:    br i1 [[TMP11]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
3941eb052f6bSPhilip Reames; CHECK:       vector.ph:
3942eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[TMP0]], 2
3943eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i32 [[TMP0]], [[N_MOD_VF]]
39440c00dbb9SNikita Popov; CHECK-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
39450c00dbb9SNikita Popov; CHECK-NEXT:    [[IND_END:%.*]] = add i8 [[T]], [[CAST_VTC]]
39467c080e46SNikita Popov; CHECK-NEXT:    [[TMP12:%.*]] = mul i32 [[N_VEC]], 4
3947be25f52fSPhilip Reames; CHECK-NEXT:    [[IND_END1:%.*]] = add i32 [[EXT_MUL]], [[TMP12]]
39480c00dbb9SNikita Popov; CHECK-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[EXT_MUL]], i32 0
39490c00dbb9SNikita Popov; CHECK-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
39500c00dbb9SNikita Popov; CHECK-NEXT:    [[INDUCTION:%.*]] = add <2 x i32> [[DOTSPLAT]], <i32 0, i32 4>
3951eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
3952eb052f6bSPhilip Reames; CHECK:       vector.body:
3953eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
39540c00dbb9SNikita Popov; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
39557c080e46SNikita Popov; CHECK-NEXT:    [[TMP13:%.*]] = trunc i32 [[INDEX]] to i8
39567c080e46SNikita Popov; CHECK-NEXT:    [[OFFSET_IDX:%.*]] = add i8 [[T]], [[TMP13]]
39577c080e46SNikita Popov; CHECK-NEXT:    [[TMP14:%.*]] = add i8 [[OFFSET_IDX]], 0
39587c080e46SNikita Popov; CHECK-NEXT:    [[TMP15:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i8 [[TMP14]]
39597c080e46SNikita Popov; CHECK-NEXT:    [[TMP16:%.*]] = getelementptr inbounds i32, i32* [[TMP15]], i32 0
39607c080e46SNikita Popov; CHECK-NEXT:    [[TMP17:%.*]] = bitcast i32* [[TMP16]] to <2 x i32>*
39610c00dbb9SNikita Popov; CHECK-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP17]], align 4
3962eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
39630c00dbb9SNikita Popov; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 8, i32 8>
39647c080e46SNikita Popov; CHECK-NEXT:    [[TMP18:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
39657c080e46SNikita Popov; CHECK-NEXT:    br i1 [[TMP18]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP38:![0-9]+]]
3966eb052f6bSPhilip Reames; CHECK:       middle.block:
3967eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
3968eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[EXIT_LOOPEXIT:%.*]], label [[SCALAR_PH]]
3969eb052f6bSPhilip Reames; CHECK:       scalar.ph:
3970eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[T]], [[LOOP_PREHEADER]] ], [ [[T]], [[VECTOR_SCEVCHECK]] ]
3971be25f52fSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL2:%.*]] = phi i32 [ [[IND_END1]], [[MIDDLE_BLOCK]] ], [ [[EXT_MUL]], [[LOOP_PREHEADER]] ], [ [[EXT_MUL]], [[VECTOR_SCEVCHECK]] ]
3972eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL3:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_PREHEADER]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
3973eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[LOOP:%.*]]
3974eb052f6bSPhilip Reames; CHECK:       loop:
3975eb052f6bSPhilip Reames; CHECK-NEXT:    [[IDX:%.*]] = phi i8 [ [[IDX_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
3976be25f52fSPhilip Reames; CHECK-NEXT:    [[SPHI:%.*]] = phi i32 [ [[MUL:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL2]], [[SCALAR_PH]] ]
3977eb052f6bSPhilip Reames; CHECK-NEXT:    [[IDX_B:%.*]] = phi i32 [ [[IDX_B_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ]
3978eb052f6bSPhilip Reames; CHECK-NEXT:    [[PTR:%.*]] = getelementptr inbounds i32, i32* [[A]], i8 [[IDX]]
3979eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[SPHI]], i32* [[PTR]], align 4
3980eb052f6bSPhilip Reames; CHECK-NEXT:    [[IDX_INC]] = add i8 [[IDX]], 1
3981eb052f6bSPhilip Reames; CHECK-NEXT:    [[IDX_INC_EXT:%.*]] = zext i8 [[IDX_INC]] to i32
3982eb052f6bSPhilip Reames; CHECK-NEXT:    [[MUL]] = mul i32 [[IDX_INC_EXT]], 4
3983eb052f6bSPhilip Reames; CHECK-NEXT:    [[IDX_B_INC]] = add nuw nsw i32 [[IDX_B]], 1
3984eb052f6bSPhilip Reames; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[IDX_B]], [[LEN]]
3985eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[C]], label [[LOOP]], label [[EXIT_LOOPEXIT]], !llvm.loop [[LOOP39:![0-9]+]]
3986eb052f6bSPhilip Reames; CHECK:       exit.loopexit:
3987eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[EXIT]]
3988eb052f6bSPhilip Reames; CHECK:       exit:
3989eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
3990eb052f6bSPhilip Reames;
3991eb052f6bSPhilip Reames; IND-LABEL: @wrappingindvars2(
3992eb052f6bSPhilip Reames; IND-NEXT:  entry:
3993eb052f6bSPhilip Reames; IND-NEXT:    [[EXT:%.*]] = zext i8 [[T:%.*]] to i32
3994eb052f6bSPhilip Reames; IND-NEXT:    [[EXT_MUL:%.*]] = shl nuw nsw i32 [[EXT]], 2
3995eb052f6bSPhilip Reames; IND-NEXT:    [[ECMP:%.*]] = icmp ult i8 [[T]], 42
3996eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[ECMP]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
3997eb052f6bSPhilip Reames; IND:       loop.preheader:
3998eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = add i32 [[LEN:%.*]], 1
3999eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 2
4000eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
4001eb052f6bSPhilip Reames; IND:       vector.scevcheck:
4002eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = trunc i32 [[LEN]] to i8
4003eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = xor i8 [[T]], -1
4004eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = icmp ult i8 [[TMP2]], [[TMP1]]
4005356d47ccSNikita Popov; IND-NEXT:    [[TMP4:%.*]] = trunc i32 [[LEN]] to i8
4006356d47ccSNikita Popov; IND-NEXT:    [[TMP5:%.*]] = add i8 [[TMP4]], [[T]]
4007356d47ccSNikita Popov; IND-NEXT:    [[TMP6:%.*]] = icmp slt i8 [[TMP5]], [[T]]
4008356d47ccSNikita Popov; IND-NEXT:    [[TMP7:%.*]] = icmp ugt i32 [[LEN]], 255
4009356d47ccSNikita Popov; IND-NEXT:    [[TMP8:%.*]] = or i1 [[TMP6]], [[TMP7]]
4010356d47ccSNikita Popov; IND-NEXT:    [[TMP9:%.*]] = or i1 [[TMP3]], [[TMP8]]
4011356d47ccSNikita Popov; IND-NEXT:    br i1 [[TMP9]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
4012eb052f6bSPhilip Reames; IND:       vector.ph:
4013eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i32 [[TMP0]], -2
40140c00dbb9SNikita Popov; IND-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
40150c00dbb9SNikita Popov; IND-NEXT:    [[IND_END:%.*]] = add i8 [[CAST_VTC]], [[T]]
4016356d47ccSNikita Popov; IND-NEXT:    [[TMP10:%.*]] = add i32 [[N_VEC]], [[EXT]]
4017be25f52fSPhilip Reames; IND-NEXT:    [[IND_END1:%.*]] = shl i32 [[TMP10]], 2
40180c00dbb9SNikita Popov; IND-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[EXT_MUL]], i64 0
40190c00dbb9SNikita Popov; IND-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
40200c00dbb9SNikita Popov; IND-NEXT:    [[INDUCTION:%.*]] = add nuw nsw <2 x i32> [[DOTSPLAT]], <i32 0, i32 4>
4021eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
4022eb052f6bSPhilip Reames; IND:       vector.body:
4023eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
40240c00dbb9SNikita Popov; IND-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
4025356d47ccSNikita Popov; IND-NEXT:    [[TMP11:%.*]] = trunc i32 [[INDEX]] to i8
4026356d47ccSNikita Popov; IND-NEXT:    [[OFFSET_IDX:%.*]] = add i8 [[TMP11]], [[T]]
4027356d47ccSNikita Popov; IND-NEXT:    [[TMP12:%.*]] = sext i8 [[OFFSET_IDX]] to i64
4028356d47ccSNikita Popov; IND-NEXT:    [[TMP13:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP12]]
4029356d47ccSNikita Popov; IND-NEXT:    [[TMP14:%.*]] = bitcast i32* [[TMP13]] to <2 x i32>*
4030356d47ccSNikita Popov; IND-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP14]], align 4
4031eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
40320c00dbb9SNikita Popov; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 8, i32 8>
4033356d47ccSNikita Popov; IND-NEXT:    [[TMP15:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
4034356d47ccSNikita Popov; IND-NEXT:    br i1 [[TMP15]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP38:![0-9]+]]
4035eb052f6bSPhilip Reames; IND:       middle.block:
4036eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
4037eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[EXIT_LOOPEXIT:%.*]], label [[SCALAR_PH]]
4038eb052f6bSPhilip Reames; IND:       scalar.ph:
4039eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[T]], [[LOOP_PREHEADER]] ], [ [[T]], [[VECTOR_SCEVCHECK]] ]
4040be25f52fSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL2:%.*]] = phi i32 [ [[IND_END1]], [[MIDDLE_BLOCK]] ], [ [[EXT_MUL]], [[LOOP_PREHEADER]] ], [ [[EXT_MUL]], [[VECTOR_SCEVCHECK]] ]
4041eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL3:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_PREHEADER]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
4042eb052f6bSPhilip Reames; IND-NEXT:    br label [[LOOP:%.*]]
4043eb052f6bSPhilip Reames; IND:       loop:
4044eb052f6bSPhilip Reames; IND-NEXT:    [[IDX:%.*]] = phi i8 [ [[IDX_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4045be25f52fSPhilip Reames; IND-NEXT:    [[SPHI:%.*]] = phi i32 [ [[MUL:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL2]], [[SCALAR_PH]] ]
4046eb052f6bSPhilip Reames; IND-NEXT:    [[IDX_B:%.*]] = phi i32 [ [[IDX_B_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ]
4047356d47ccSNikita Popov; IND-NEXT:    [[TMP16:%.*]] = sext i8 [[IDX]] to i64
4048356d47ccSNikita Popov; IND-NEXT:    [[PTR:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP16]]
4049eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[SPHI]], i32* [[PTR]], align 4
4050eb052f6bSPhilip Reames; IND-NEXT:    [[IDX_INC]] = add i8 [[IDX]], 1
4051eb052f6bSPhilip Reames; IND-NEXT:    [[IDX_INC_EXT:%.*]] = zext i8 [[IDX_INC]] to i32
4052eb052f6bSPhilip Reames; IND-NEXT:    [[MUL]] = shl nuw nsw i32 [[IDX_INC_EXT]], 2
4053eb052f6bSPhilip Reames; IND-NEXT:    [[IDX_B_INC]] = add nuw nsw i32 [[IDX_B]], 1
4054eb052f6bSPhilip Reames; IND-NEXT:    [[C:%.*]] = icmp ult i32 [[IDX_B]], [[LEN]]
4055eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[C]], label [[LOOP]], label [[EXIT_LOOPEXIT]], !llvm.loop [[LOOP39:![0-9]+]]
4056eb052f6bSPhilip Reames; IND:       exit.loopexit:
4057eb052f6bSPhilip Reames; IND-NEXT:    br label [[EXIT]]
4058eb052f6bSPhilip Reames; IND:       exit:
4059eb052f6bSPhilip Reames; IND-NEXT:    ret void
4060eb052f6bSPhilip Reames;
4061eb052f6bSPhilip Reames; UNROLL-LABEL: @wrappingindvars2(
4062eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
4063eb052f6bSPhilip Reames; UNROLL-NEXT:    [[EXT:%.*]] = zext i8 [[T:%.*]] to i32
4064eb052f6bSPhilip Reames; UNROLL-NEXT:    [[EXT_MUL:%.*]] = shl nuw nsw i32 [[EXT]], 2
4065eb052f6bSPhilip Reames; UNROLL-NEXT:    [[ECMP:%.*]] = icmp ult i8 [[T]], 42
4066eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[ECMP]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
4067eb052f6bSPhilip Reames; UNROLL:       loop.preheader:
4068eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = add i32 [[LEN:%.*]], 1
4069eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 4
4070eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
4071eb052f6bSPhilip Reames; UNROLL:       vector.scevcheck:
4072eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = trunc i32 [[LEN]] to i8
4073eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = xor i8 [[T]], -1
4074eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = icmp ult i8 [[TMP2]], [[TMP1]]
4075356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP4:%.*]] = trunc i32 [[LEN]] to i8
4076356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP5:%.*]] = add i8 [[TMP4]], [[T]]
4077356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP6:%.*]] = icmp slt i8 [[TMP5]], [[T]]
4078356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP7:%.*]] = icmp ugt i32 [[LEN]], 255
4079356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP8:%.*]] = or i1 [[TMP6]], [[TMP7]]
4080356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP9:%.*]] = or i1 [[TMP3]], [[TMP8]]
4081356d47ccSNikita Popov; UNROLL-NEXT:    br i1 [[TMP9]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
4082eb052f6bSPhilip Reames; UNROLL:       vector.ph:
4083eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i32 [[TMP0]], -4
40840c00dbb9SNikita Popov; UNROLL-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
40850c00dbb9SNikita Popov; UNROLL-NEXT:    [[IND_END:%.*]] = add i8 [[CAST_VTC]], [[T]]
4086356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP10:%.*]] = add i32 [[N_VEC]], [[EXT]]
4087be25f52fSPhilip Reames; UNROLL-NEXT:    [[IND_END1:%.*]] = shl i32 [[TMP10]], 2
40880c00dbb9SNikita Popov; UNROLL-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[EXT_MUL]], i64 0
40890c00dbb9SNikita Popov; UNROLL-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
40900c00dbb9SNikita Popov; UNROLL-NEXT:    [[INDUCTION:%.*]] = add nuw nsw <2 x i32> [[DOTSPLAT]], <i32 0, i32 4>
4091eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
4092eb052f6bSPhilip Reames; UNROLL:       vector.body:
4093eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
40940c00dbb9SNikita Popov; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
40950c00dbb9SNikita Popov; UNROLL-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 8, i32 8>
4096356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP11:%.*]] = trunc i32 [[INDEX]] to i8
4097356d47ccSNikita Popov; UNROLL-NEXT:    [[OFFSET_IDX:%.*]] = add i8 [[TMP11]], [[T]]
4098356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP12:%.*]] = sext i8 [[OFFSET_IDX]] to i64
4099356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP13:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP12]]
4100356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP14:%.*]] = bitcast i32* [[TMP13]] to <2 x i32>*
4101356d47ccSNikita Popov; UNROLL-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP14]], align 4
4102356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP15:%.*]] = getelementptr inbounds i32, i32* [[TMP13]], i64 2
4103eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP16:%.*]] = bitcast i32* [[TMP15]] to <2 x i32>*
4104356d47ccSNikita Popov; UNROLL-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP16]], align 4
4105eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
41060c00dbb9SNikita Popov; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 16, i32 16>
4107356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP17:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
4108356d47ccSNikita Popov; UNROLL-NEXT:    br i1 [[TMP17]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP38:![0-9]+]]
4109eb052f6bSPhilip Reames; UNROLL:       middle.block:
4110eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
4111eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[EXIT_LOOPEXIT:%.*]], label [[SCALAR_PH]]
4112eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
4113eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[T]], [[LOOP_PREHEADER]] ], [ [[T]], [[VECTOR_SCEVCHECK]] ]
4114be25f52fSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL2:%.*]] = phi i32 [ [[IND_END1]], [[MIDDLE_BLOCK]] ], [ [[EXT_MUL]], [[LOOP_PREHEADER]] ], [ [[EXT_MUL]], [[VECTOR_SCEVCHECK]] ]
4115eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL3:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_PREHEADER]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
4116eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[LOOP:%.*]]
4117eb052f6bSPhilip Reames; UNROLL:       loop:
4118eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IDX:%.*]] = phi i8 [ [[IDX_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4119be25f52fSPhilip Reames; UNROLL-NEXT:    [[SPHI:%.*]] = phi i32 [ [[MUL:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL2]], [[SCALAR_PH]] ]
4120eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IDX_B:%.*]] = phi i32 [ [[IDX_B_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ]
4121356d47ccSNikita Popov; UNROLL-NEXT:    [[TMP18:%.*]] = sext i8 [[IDX]] to i64
4122356d47ccSNikita Popov; UNROLL-NEXT:    [[PTR:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP18]]
4123eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[SPHI]], i32* [[PTR]], align 4
4124eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IDX_INC]] = add i8 [[IDX]], 1
4125eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IDX_INC_EXT:%.*]] = zext i8 [[IDX_INC]] to i32
4126eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MUL]] = shl nuw nsw i32 [[IDX_INC_EXT]], 2
4127eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IDX_B_INC]] = add nuw nsw i32 [[IDX_B]], 1
4128eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C:%.*]] = icmp ult i32 [[IDX_B]], [[LEN]]
4129eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[C]], label [[LOOP]], label [[EXIT_LOOPEXIT]], !llvm.loop [[LOOP39:![0-9]+]]
4130eb052f6bSPhilip Reames; UNROLL:       exit.loopexit:
4131eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[EXIT]]
4132eb052f6bSPhilip Reames; UNROLL:       exit:
4133eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
4134eb052f6bSPhilip Reames;
4135eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @wrappingindvars2(
4136eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
4137eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[ST:%.*]] = zext i8 [[T:%.*]] to i16
4138eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[EXT:%.*]] = zext i8 [[T]] to i32
4139eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[EXT_MUL:%.*]] = mul i32 [[EXT]], 4
4140eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[ECMP:%.*]] = icmp ult i16 [[ST]], 42
4141eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[ECMP]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
4142eb052f6bSPhilip Reames; UNROLL-NO-IC:       loop.preheader:
4143eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i32 [[LEN:%.*]], 1
4144eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 4
4145eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
4146eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.scevcheck:
4147eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = trunc i32 [[LEN]] to i8
4148eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = add i8 [[T]], [[TMP1]]
41497c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = icmp ult i8 [[TMP2]], [[T]]
41507c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = icmp ugt i32 [[LEN]], 255
41517c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = or i1 [[TMP3]], [[TMP4]]
41527c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = trunc i32 [[LEN]] to i8
41537c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = add i8 [[T]], [[TMP6]]
41547c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = icmp slt i8 [[TMP7]], [[T]]
41557c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = icmp ugt i32 [[LEN]], 255
41567c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = or i1 [[TMP8]], [[TMP9]]
41577c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = or i1 [[TMP5]], [[TMP10]]
41587c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP11]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
4159eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
4160eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[TMP0]], 4
4161eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i32 [[TMP0]], [[N_MOD_VF]]
41620c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
41630c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[IND_END:%.*]] = add i8 [[T]], [[CAST_VTC]]
41647c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = mul i32 [[N_VEC]], 4
4165be25f52fSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IND_END1:%.*]] = add i32 [[EXT_MUL]], [[TMP12]]
41660c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[EXT_MUL]], i32 0
41670c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
41680c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[INDUCTION:%.*]] = add <2 x i32> [[DOTSPLAT]], <i32 0, i32 4>
4169eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
4170eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
4171eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
41720c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
41730c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 8, i32 8>
41747c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = trunc i32 [[INDEX]] to i8
41757c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[OFFSET_IDX:%.*]] = add i8 [[T]], [[TMP13]]
41767c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = add i8 [[OFFSET_IDX]], 0
41777c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = add i8 [[OFFSET_IDX]], 2
41787c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP16:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i8 [[TMP14]]
41797c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP17:%.*]] = getelementptr inbounds i32, i32* [[A]], i8 [[TMP15]]
41807c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP18:%.*]] = getelementptr inbounds i32, i32* [[TMP16]], i32 0
41817c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP19:%.*]] = bitcast i32* [[TMP18]] to <2 x i32>*
41820c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP19]], align 4
41837c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP20:%.*]] = getelementptr inbounds i32, i32* [[TMP16]], i32 2
41847c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP21:%.*]] = bitcast i32* [[TMP20]] to <2 x i32>*
41850c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP21]], align 4
4186eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
41870c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[STEP_ADD]], <i32 8, i32 8>
41887c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP22:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
41897c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP22]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP38:![0-9]+]]
4190eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
4191eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
4192eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[EXIT_LOOPEXIT:%.*]], label [[SCALAR_PH]]
4193eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
4194eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[T]], [[LOOP_PREHEADER]] ], [ [[T]], [[VECTOR_SCEVCHECK]] ]
4195be25f52fSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL2:%.*]] = phi i32 [ [[IND_END1]], [[MIDDLE_BLOCK]] ], [ [[EXT_MUL]], [[LOOP_PREHEADER]] ], [ [[EXT_MUL]], [[VECTOR_SCEVCHECK]] ]
4196eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL3:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_PREHEADER]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
4197eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[LOOP:%.*]]
4198eb052f6bSPhilip Reames; UNROLL-NO-IC:       loop:
4199eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IDX:%.*]] = phi i8 [ [[IDX_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4200be25f52fSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SPHI:%.*]] = phi i32 [ [[MUL:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL2]], [[SCALAR_PH]] ]
4201eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IDX_B:%.*]] = phi i32 [ [[IDX_B_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ]
4202eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[PTR:%.*]] = getelementptr inbounds i32, i32* [[A]], i8 [[IDX]]
4203eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[SPHI]], i32* [[PTR]], align 4
4204eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IDX_INC]] = add i8 [[IDX]], 1
4205eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IDX_INC_EXT:%.*]] = zext i8 [[IDX_INC]] to i32
4206eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MUL]] = mul i32 [[IDX_INC_EXT]], 4
4207eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IDX_B_INC]] = add nuw nsw i32 [[IDX_B]], 1
4208eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C:%.*]] = icmp ult i32 [[IDX_B]], [[LEN]]
4209eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[C]], label [[LOOP]], label [[EXIT_LOOPEXIT]], !llvm.loop [[LOOP39:![0-9]+]]
4210eb052f6bSPhilip Reames; UNROLL-NO-IC:       exit.loopexit:
4211eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[EXIT]]
4212eb052f6bSPhilip Reames; UNROLL-NO-IC:       exit:
4213eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
4214eb052f6bSPhilip Reames;
4215eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @wrappingindvars2(
4216eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
4217eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[EXT:%.*]] = zext i8 [[T:%.*]] to i32
4218eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[EXT_MUL:%.*]] = shl nuw nsw i32 [[EXT]], 2
4219eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[ECMP:%.*]] = icmp ult i8 [[T]], 42
4220eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[ECMP]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
4221eb052f6bSPhilip Reames; INTERLEAVE:       loop.preheader:
4222eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = add i32 [[LEN:%.*]], 1
4223eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 8
4224eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
4225eb052f6bSPhilip Reames; INTERLEAVE:       vector.scevcheck:
4226eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = trunc i32 [[LEN]] to i8
4227eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = xor i8 [[T]], -1
4228eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = icmp ult i8 [[TMP2]], [[TMP1]]
4229356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP4:%.*]] = trunc i32 [[LEN]] to i8
4230356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP5:%.*]] = add i8 [[TMP4]], [[T]]
4231356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP6:%.*]] = icmp slt i8 [[TMP5]], [[T]]
4232356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP7:%.*]] = icmp ugt i32 [[LEN]], 255
4233356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP8:%.*]] = or i1 [[TMP6]], [[TMP7]]
4234356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP9:%.*]] = or i1 [[TMP3]], [[TMP8]]
4235356d47ccSNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP9]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
4236eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
4237eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i32 [[TMP0]], -8
42380c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[CAST_VTC:%.*]] = trunc i32 [[N_VEC]] to i8
42390c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[IND_END:%.*]] = add i8 [[CAST_VTC]], [[T]]
4240356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP10:%.*]] = add i32 [[N_VEC]], [[EXT]]
4241be25f52fSPhilip Reames; INTERLEAVE-NEXT:    [[IND_END1:%.*]] = shl i32 [[TMP10]], 2
42420c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[EXT_MUL]], i64 0
42430c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <4 x i32> [[DOTSPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
42440c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[INDUCTION:%.*]] = add nuw nsw <4 x i32> [[DOTSPLAT]], <i32 0, i32 4, i32 8, i32 12>
4245eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
4246eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
4247eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
42480c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND:%.*]] = phi <4 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
42490c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[STEP_ADD:%.*]] = add <4 x i32> [[VEC_IND]], <i32 16, i32 16, i32 16, i32 16>
4250356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP11:%.*]] = trunc i32 [[INDEX]] to i8
4251356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[OFFSET_IDX:%.*]] = add i8 [[TMP11]], [[T]]
4252356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP12:%.*]] = sext i8 [[OFFSET_IDX]] to i64
4253356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP13:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP12]]
4254356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP14:%.*]] = bitcast i32* [[TMP13]] to <4 x i32>*
4255356d47ccSNikita Popov; INTERLEAVE-NEXT:    store <4 x i32> [[VEC_IND]], <4 x i32>* [[TMP14]], align 4
4256356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP15:%.*]] = getelementptr inbounds i32, i32* [[TMP13]], i64 4
4257eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP16:%.*]] = bitcast i32* [[TMP15]] to <4 x i32>*
4258356d47ccSNikita Popov; INTERLEAVE-NEXT:    store <4 x i32> [[STEP_ADD]], <4 x i32>* [[TMP16]], align 4
4259eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8
42600c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND_NEXT]] = add <4 x i32> [[VEC_IND]], <i32 32, i32 32, i32 32, i32 32>
4261356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP17:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
4262356d47ccSNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP17]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP38:![0-9]+]]
4263eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
4264eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
4265eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[EXIT_LOOPEXIT:%.*]], label [[SCALAR_PH]]
4266eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
4267eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[T]], [[LOOP_PREHEADER]] ], [ [[T]], [[VECTOR_SCEVCHECK]] ]
4268be25f52fSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL2:%.*]] = phi i32 [ [[IND_END1]], [[MIDDLE_BLOCK]] ], [ [[EXT_MUL]], [[LOOP_PREHEADER]] ], [ [[EXT_MUL]], [[VECTOR_SCEVCHECK]] ]
4269eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL3:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_PREHEADER]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
4270eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[LOOP:%.*]]
4271eb052f6bSPhilip Reames; INTERLEAVE:       loop:
4272eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IDX:%.*]] = phi i8 [ [[IDX_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4273be25f52fSPhilip Reames; INTERLEAVE-NEXT:    [[SPHI:%.*]] = phi i32 [ [[MUL:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL2]], [[SCALAR_PH]] ]
4274eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IDX_B:%.*]] = phi i32 [ [[IDX_B_INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ]
4275356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[TMP18:%.*]] = sext i8 [[IDX]] to i64
4276356d47ccSNikita Popov; INTERLEAVE-NEXT:    [[PTR:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP18]]
4277eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[SPHI]], i32* [[PTR]], align 4
4278eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IDX_INC]] = add i8 [[IDX]], 1
4279eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IDX_INC_EXT:%.*]] = zext i8 [[IDX_INC]] to i32
4280eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MUL]] = shl nuw nsw i32 [[IDX_INC_EXT]], 2
4281eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IDX_B_INC]] = add nuw nsw i32 [[IDX_B]], 1
4282eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C:%.*]] = icmp ult i32 [[IDX_B]], [[LEN]]
4283eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[C]], label [[LOOP]], label [[EXIT_LOOPEXIT]], !llvm.loop [[LOOP39:![0-9]+]]
4284eb052f6bSPhilip Reames; INTERLEAVE:       exit.loopexit:
4285eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[EXIT]]
4286eb052f6bSPhilip Reames; INTERLEAVE:       exit:
4287eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
4288eb052f6bSPhilip Reames;
4289cee313d2SEric Christopherentry:
4290cee313d2SEric Christopher  %st = zext i8 %t to i16
4291cee313d2SEric Christopher  %ext = zext i8 %t to i32
4292cee313d2SEric Christopher  %ext.mul = mul i32 %ext, 4
4293cee313d2SEric Christopher
4294cee313d2SEric Christopher  %ecmp = icmp ult i16 %st, 42
4295cee313d2SEric Christopher  br i1 %ecmp, label %loop, label %exit
4296cee313d2SEric Christopher
4297cee313d2SEric Christopher  loop:
4298cee313d2SEric Christopher
4299cee313d2SEric Christopher  %idx = phi i8 [ %t, %entry ], [ %idx.inc, %loop ]
4300cee313d2SEric Christopher  %sphi = phi i32 [ %ext.mul, %entry ], [%mul, %loop]
4301cee313d2SEric Christopher  %idx.b = phi i32 [ 0, %entry ], [ %idx.b.inc, %loop ]
4302cee313d2SEric Christopher
4303cee313d2SEric Christopher  %ptr = getelementptr inbounds i32, i32* %A, i8 %idx
4304cee313d2SEric Christopher  store i32 %sphi, i32* %ptr
4305cee313d2SEric Christopher
4306cee313d2SEric Christopher  %idx.inc = add i8 %idx, 1
4307cee313d2SEric Christopher  %idx.inc.ext = zext i8 %idx.inc to i32
4308cee313d2SEric Christopher  %mul = mul i32 %idx.inc.ext, 4
4309cee313d2SEric Christopher  %idx.b.inc = add nuw nsw i32 %idx.b, 1
4310cee313d2SEric Christopher
4311cee313d2SEric Christopher  %c = icmp ult i32 %idx.b, %len
4312cee313d2SEric Christopher  br i1 %c, label %loop, label %exit
4313cee313d2SEric Christopher
4314cee313d2SEric Christopher  exit:
4315cee313d2SEric Christopher  ret void
4316cee313d2SEric Christopher}
4317cee313d2SEric Christopher
4318cee313d2SEric Christopher; Check that we generate vectorized IVs in the pre-header
4319cee313d2SEric Christopher; instead of widening the scalar IV inside the loop, when
4320cee313d2SEric Christopher; we know how to do that.
4321bbba8676SPhilip Reamesdefine void @veciv(i32* nocapture %a, i32 %start, i32 %k) {
4322eb052f6bSPhilip Reames; CHECK-LABEL: @veciv(
4323eb052f6bSPhilip Reames; CHECK-NEXT:  for.body.preheader:
4324eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[K:%.*]], 2
4325eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
4326eb052f6bSPhilip Reames; CHECK:       vector.ph:
4327eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[K]], 2
4328eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i32 [[K]], [[N_MOD_VF]]
4329eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
4330eb052f6bSPhilip Reames; CHECK:       vector.body:
4331eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
4332eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
4333eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[INDEX]], 0
43340c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i32 [[TMP0]]
43350c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[TMP1]], i32 0
43360c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <2 x i32>*
43370c00dbb9SNikita Popov; CHECK-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP3]], align 4
4338eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
4339eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
43400c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP4:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
43410c00dbb9SNikita Popov; CHECK-NEXT:    br i1 [[TMP4]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP40:![0-9]+]]
4342eb052f6bSPhilip Reames; CHECK:       middle.block:
4343eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[K]], [[N_VEC]]
4344eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4345eb052f6bSPhilip Reames; CHECK:       scalar.ph:
4346eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER:%.*]] ]
4347eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
4348eb052f6bSPhilip Reames; CHECK:       for.body:
4349eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4350eb052f6bSPhilip Reames; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[INDVARS_IV]]
4351eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[INDVARS_IV]], i32* [[ARRAYIDX]], align 4
4352eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
4353eb052f6bSPhilip Reames; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[INDVARS_IV_NEXT]], [[K]]
4354eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP41:![0-9]+]]
4355eb052f6bSPhilip Reames; CHECK:       exit:
4356eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
4357eb052f6bSPhilip Reames;
4358eb052f6bSPhilip Reames; IND-LABEL: @veciv(
4359eb052f6bSPhilip Reames; IND-NEXT:  for.body.preheader:
4360eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[K:%.*]], 2
4361eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
4362eb052f6bSPhilip Reames; IND:       vector.ph:
4363eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i32 [[K]], -2
4364eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
4365eb052f6bSPhilip Reames; IND:       vector.body:
4366eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
4367eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
4368eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = sext i32 [[INDEX]] to i64
4369eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP0]]
4370eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = bitcast i32* [[TMP1]] to <2 x i32>*
4371eb052f6bSPhilip Reames; IND-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP2]], align 4
4372eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
4373eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
4374eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
4375eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP3]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP40:![0-9]+]]
4376eb052f6bSPhilip Reames; IND:       middle.block:
4377eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[N_VEC]], [[K]]
4378eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4379eb052f6bSPhilip Reames; IND:       scalar.ph:
4380eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER:%.*]] ]
4381eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
4382eb052f6bSPhilip Reames; IND:       for.body:
4383eb052f6bSPhilip Reames; IND-NEXT:    [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4384eb052f6bSPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = sext i32 [[INDVARS_IV]] to i64
4385eb052f6bSPhilip Reames; IND-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP4]]
4386eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[INDVARS_IV]], i32* [[ARRAYIDX]], align 4
4387eb052f6bSPhilip Reames; IND-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
4388eb052f6bSPhilip Reames; IND-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[INDVARS_IV_NEXT]], [[K]]
4389eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP41:![0-9]+]]
4390eb052f6bSPhilip Reames; IND:       exit:
4391eb052f6bSPhilip Reames; IND-NEXT:    ret void
4392eb052f6bSPhilip Reames;
4393eb052f6bSPhilip Reames; UNROLL-LABEL: @veciv(
4394eb052f6bSPhilip Reames; UNROLL-NEXT:  for.body.preheader:
4395eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[K:%.*]], 4
4396eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
4397eb052f6bSPhilip Reames; UNROLL:       vector.ph:
4398eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i32 [[K]], -4
4399eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
4400eb052f6bSPhilip Reames; UNROLL:       vector.body:
4401eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
4402eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
4403eb052f6bSPhilip Reames; UNROLL-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
4404eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = sext i32 [[INDEX]] to i64
4405eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP0]]
4406eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = bitcast i32* [[TMP1]] to <2 x i32>*
4407eb052f6bSPhilip Reames; UNROLL-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP2]], align 4
4408eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i32, i32* [[TMP1]], i64 2
4409eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = bitcast i32* [[TMP3]] to <2 x i32>*
4410eb052f6bSPhilip Reames; UNROLL-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP4]], align 4
4411eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
4412eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 4, i32 4>
4413eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
4414eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP40:![0-9]+]]
4415eb052f6bSPhilip Reames; UNROLL:       middle.block:
4416eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[N_VEC]], [[K]]
4417eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4418eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
4419eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER:%.*]] ]
4420eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
4421eb052f6bSPhilip Reames; UNROLL:       for.body:
4422eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4423eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP6:%.*]] = sext i32 [[INDVARS_IV]] to i64
4424eb052f6bSPhilip Reames; UNROLL-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP6]]
4425eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[INDVARS_IV]], i32* [[ARRAYIDX]], align 4
4426eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
4427eb052f6bSPhilip Reames; UNROLL-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[INDVARS_IV_NEXT]], [[K]]
4428eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP41:![0-9]+]]
4429eb052f6bSPhilip Reames; UNROLL:       exit:
4430eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
4431eb052f6bSPhilip Reames;
4432eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @veciv(
4433eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  for.body.preheader:
4434eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[K:%.*]], 4
4435eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
4436eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
4437eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[K]], 4
4438eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i32 [[K]], [[N_MOD_VF]]
4439eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
4440eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
4441eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
4442eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
4443eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
4444eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i32 [[INDEX]], 0
44450c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = add i32 [[INDEX]], 2
44460c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i32 [[TMP0]]
44470c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[TMP1]]
44480c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i32 0
44490c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP4]] to <2 x i32>*
44500c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP5]], align 4
44510c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i32 2
4452eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = bitcast i32* [[TMP6]] to <2 x i32>*
44530c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP7]], align 4
4454eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
4455eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[STEP_ADD]], <i32 2, i32 2>
44560c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
44570c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP40:![0-9]+]]
4458eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
4459eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[K]], [[N_VEC]]
4460eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4461eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
4462eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER:%.*]] ]
4463eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
4464eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
4465eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4466eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[INDVARS_IV]]
4467eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[INDVARS_IV]], i32* [[ARRAYIDX]], align 4
4468eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
4469eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[INDVARS_IV_NEXT]], [[K]]
4470eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP41:![0-9]+]]
4471eb052f6bSPhilip Reames; UNROLL-NO-IC:       exit:
4472eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
4473eb052f6bSPhilip Reames;
4474eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @veciv(
4475eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  for.body.preheader:
4476eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[K:%.*]], 8
4477eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
4478eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
4479eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i32 [[K]], -8
4480eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
4481eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
4482eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
4483eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
4484eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[STEP_ADD:%.*]] = add <4 x i32> [[VEC_IND]], <i32 4, i32 4, i32 4, i32 4>
4485eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = sext i32 [[INDEX]] to i64
4486eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP0]]
4487eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = bitcast i32* [[TMP1]] to <4 x i32>*
4488eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store <4 x i32> [[VEC_IND]], <4 x i32>* [[TMP2]], align 4
4489eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i32, i32* [[TMP1]], i64 4
4490eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = bitcast i32* [[TMP3]] to <4 x i32>*
4491eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store <4 x i32> [[STEP_ADD]], <4 x i32>* [[TMP4]], align 4
4492eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8
4493eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_IND_NEXT]] = add <4 x i32> [[VEC_IND]], <i32 8, i32 8, i32 8, i32 8>
4494eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
4495eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP40:![0-9]+]]
4496eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
4497eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[N_VEC]], [[K]]
4498eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4499eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
4500eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER:%.*]] ]
4501eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
4502eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
4503eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4504eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = sext i32 [[INDVARS_IV]] to i64
4505eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP6]]
4506eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[INDVARS_IV]], i32* [[ARRAYIDX]], align 4
4507eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
4508eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[INDVARS_IV_NEXT]], [[K]]
4509eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP41:![0-9]+]]
4510eb052f6bSPhilip Reames; INTERLEAVE:       exit:
4511eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
4512eb052f6bSPhilip Reames;
4513cee313d2SEric Christopherfor.body.preheader:
4514cee313d2SEric Christopher  br label %for.body
4515cee313d2SEric Christopher
4516cee313d2SEric Christopherfor.body:
4517cee313d2SEric Christopher  %indvars.iv = phi i32 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
4518cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %a, i32 %indvars.iv
4519cee313d2SEric Christopher  store i32 %indvars.iv, i32* %arrayidx, align 4
4520cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
4521cee313d2SEric Christopher  %exitcond = icmp eq i32 %indvars.iv.next, %k
4522cee313d2SEric Christopher  br i1 %exitcond, label %exit, label %for.body
4523cee313d2SEric Christopher
4524cee313d2SEric Christopherexit:
4525cee313d2SEric Christopher  ret void
4526cee313d2SEric Christopher}
4527cee313d2SEric Christopher
4528bbba8676SPhilip Reamesdefine void @trunciv(i32* nocapture %a, i32 %start, i64 %k) {
4529eb052f6bSPhilip Reames; CHECK-LABEL: @trunciv(
4530eb052f6bSPhilip Reames; CHECK-NEXT:  for.body.preheader:
4531eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[K:%.*]], 2
4532eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
4533eb052f6bSPhilip Reames; CHECK:       vector.scevcheck:
4534eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i64 [[K]], -1
4535eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = trunc i64 [[TMP0]] to i32
45367c080e46SNikita Popov; CHECK-NEXT:    [[TMP2:%.*]] = icmp slt i32 [[TMP1]], 0
45377c080e46SNikita Popov; CHECK-NEXT:    [[TMP3:%.*]] = icmp ugt i64 [[TMP0]], 4294967295
45387c080e46SNikita Popov; CHECK-NEXT:    [[TMP4:%.*]] = or i1 [[TMP2]], [[TMP3]]
45397c080e46SNikita Popov; CHECK-NEXT:    br i1 [[TMP4]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
4540eb052f6bSPhilip Reames; CHECK:       vector.ph:
4541eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[K]], 2
4542eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[K]], [[N_MOD_VF]]
4543eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
4544eb052f6bSPhilip Reames; CHECK:       vector.body:
4545eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
45467c080e46SNikita Popov; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
45477c080e46SNikita Popov; CHECK-NEXT:    [[TMP5:%.*]] = trunc i64 [[INDEX]] to i32
45487c080e46SNikita Popov; CHECK-NEXT:    [[TMP6:%.*]] = add i32 [[TMP5]], 0
45490c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i32 [[TMP6]]
45500c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i32, i32* [[TMP7]], i32 0
45510c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP9:%.*]] = bitcast i32* [[TMP8]] to <2 x i32>*
45520c00dbb9SNikita Popov; CHECK-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP9]], align 4
4553eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
45547c080e46SNikita Popov; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
45550c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
45560c00dbb9SNikita Popov; CHECK-NEXT:    br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP42:![0-9]+]]
4557eb052f6bSPhilip Reames; CHECK:       middle.block:
4558eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[K]], [[N_VEC]]
4559eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4560eb052f6bSPhilip Reames; CHECK:       scalar.ph:
4561eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER:%.*]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
4562eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
4563eb052f6bSPhilip Reames; CHECK:       for.body:
4564eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4565eb052f6bSPhilip Reames; CHECK-NEXT:    [[TRUNC_IV:%.*]] = trunc i64 [[INDVARS_IV]] to i32
4566eb052f6bSPhilip Reames; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[TRUNC_IV]]
4567eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[TRUNC_IV]], i32* [[ARRAYIDX]], align 4
4568eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
4569eb052f6bSPhilip Reames; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[K]]
4570eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP43:![0-9]+]]
4571eb052f6bSPhilip Reames; CHECK:       exit:
4572eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
4573eb052f6bSPhilip Reames;
4574eb052f6bSPhilip Reames; IND-LABEL: @trunciv(
4575eb052f6bSPhilip Reames; IND-NEXT:  for.body.preheader:
4576eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[K:%.*]], 2
4577eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
4578eb052f6bSPhilip Reames; IND:       vector.scevcheck:
457986d113a8SFlorian Hahn; IND-NEXT:    [[TMP0:%.*]] = add i64 [[K]], -1
45807c080e46SNikita Popov; IND-NEXT:    [[DOTNOT:%.*]] = icmp ult i64 [[TMP0]], 2147483648
45817c080e46SNikita Popov; IND-NEXT:    br i1 [[DOTNOT]], label [[VECTOR_PH:%.*]], label [[SCALAR_PH]]
4582eb052f6bSPhilip Reames; IND:       vector.ph:
4583eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i64 [[K]], -2
4584eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
4585eb052f6bSPhilip Reames; IND:       vector.body:
4586eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
45877c080e46SNikita Popov; IND-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
4588eb052f6bSPhilip Reames; IND-NEXT:    [[SEXT:%.*]] = shl i64 [[INDEX]], 32
45897c080e46SNikita Popov; IND-NEXT:    [[TMP1:%.*]] = ashr exact i64 [[SEXT]], 32
45907c080e46SNikita Popov; IND-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP1]]
45917c080e46SNikita Popov; IND-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <2 x i32>*
45927c080e46SNikita Popov; IND-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP3]], align 4
4593eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
45947c080e46SNikita Popov; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
45957c080e46SNikita Popov; IND-NEXT:    [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
45967c080e46SNikita Popov; IND-NEXT:    br i1 [[TMP4]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP42:![0-9]+]]
4597eb052f6bSPhilip Reames; IND:       middle.block:
4598eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[K]]
4599eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4600eb052f6bSPhilip Reames; IND:       scalar.ph:
4601eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER:%.*]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
4602eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
4603eb052f6bSPhilip Reames; IND:       for.body:
4604eb052f6bSPhilip Reames; IND-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4605eb052f6bSPhilip Reames; IND-NEXT:    [[TRUNC_IV:%.*]] = trunc i64 [[INDVARS_IV]] to i32
46067c080e46SNikita Popov; IND-NEXT:    [[SEXT1:%.*]] = shl i64 [[INDVARS_IV]], 32
46077c080e46SNikita Popov; IND-NEXT:    [[TMP5:%.*]] = ashr exact i64 [[SEXT1]], 32
46087c080e46SNikita Popov; IND-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP5]]
4609eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[TRUNC_IV]], i32* [[ARRAYIDX]], align 4
4610eb052f6bSPhilip Reames; IND-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
4611eb052f6bSPhilip Reames; IND-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[K]]
4612eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP43:![0-9]+]]
4613eb052f6bSPhilip Reames; IND:       exit:
4614eb052f6bSPhilip Reames; IND-NEXT:    ret void
4615eb052f6bSPhilip Reames;
4616eb052f6bSPhilip Reames; UNROLL-LABEL: @trunciv(
4617eb052f6bSPhilip Reames; UNROLL-NEXT:  for.body.preheader:
4618eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[K:%.*]], 4
4619eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
4620eb052f6bSPhilip Reames; UNROLL:       vector.scevcheck:
462186d113a8SFlorian Hahn; UNROLL-NEXT:    [[TMP0:%.*]] = add i64 [[K]], -1
46227c080e46SNikita Popov; UNROLL-NEXT:    [[DOTNOT:%.*]] = icmp ult i64 [[TMP0]], 2147483648
46237c080e46SNikita Popov; UNROLL-NEXT:    br i1 [[DOTNOT]], label [[VECTOR_PH:%.*]], label [[SCALAR_PH]]
4624eb052f6bSPhilip Reames; UNROLL:       vector.ph:
4625eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i64 [[K]], -4
4626eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
4627eb052f6bSPhilip Reames; UNROLL:       vector.body:
4628eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
46297c080e46SNikita Popov; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
46307c080e46SNikita Popov; UNROLL-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
4631eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SEXT:%.*]] = shl i64 [[INDEX]], 32
46327c080e46SNikita Popov; UNROLL-NEXT:    [[TMP1:%.*]] = ashr exact i64 [[SEXT]], 32
46337c080e46SNikita Popov; UNROLL-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP1]]
46347c080e46SNikita Popov; UNROLL-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <2 x i32>*
46357c080e46SNikita Popov; UNROLL-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP3]], align 4
46367c080e46SNikita Popov; UNROLL-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i64 2
46377c080e46SNikita Popov; UNROLL-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP4]] to <2 x i32>*
46387c080e46SNikita Popov; UNROLL-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP5]], align 4
4639eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
46407c080e46SNikita Popov; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 4, i32 4>
46417c080e46SNikita Popov; UNROLL-NEXT:    [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
46427c080e46SNikita Popov; UNROLL-NEXT:    br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP42:![0-9]+]]
4643eb052f6bSPhilip Reames; UNROLL:       middle.block:
4644eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[K]]
4645eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4646eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
4647eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER:%.*]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
4648eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
4649eb052f6bSPhilip Reames; UNROLL:       for.body:
4650eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4651eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TRUNC_IV:%.*]] = trunc i64 [[INDVARS_IV]] to i32
46527c080e46SNikita Popov; UNROLL-NEXT:    [[SEXT2:%.*]] = shl i64 [[INDVARS_IV]], 32
46537c080e46SNikita Popov; UNROLL-NEXT:    [[TMP7:%.*]] = ashr exact i64 [[SEXT2]], 32
46547c080e46SNikita Popov; UNROLL-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP7]]
4655eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[TRUNC_IV]], i32* [[ARRAYIDX]], align 4
4656eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
4657eb052f6bSPhilip Reames; UNROLL-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[K]]
4658eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP43:![0-9]+]]
4659eb052f6bSPhilip Reames; UNROLL:       exit:
4660eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
4661eb052f6bSPhilip Reames;
4662eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @trunciv(
4663eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  for.body.preheader:
4664eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[K:%.*]], 4
4665eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
4666eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.scevcheck:
4667eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i64 [[K]], -1
4668eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = trunc i64 [[TMP0]] to i32
46697c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = icmp slt i32 [[TMP1]], 0
46707c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = icmp ugt i64 [[TMP0]], 4294967295
46717c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = or i1 [[TMP2]], [[TMP3]]
46727c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP4]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
4673eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
4674eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[K]], 4
4675eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i64 [[K]], [[N_MOD_VF]]
4676eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
4677eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
4678eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
46797c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
46807c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
46817c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = trunc i64 [[INDEX]] to i32
46827c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = add i32 [[TMP5]], 0
46830c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = add i32 [[TMP5]], 2
46840c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i32 [[TMP6]]
46850c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[TMP7]]
46860c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = getelementptr inbounds i32, i32* [[TMP8]], i32 0
46870c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = bitcast i32* [[TMP10]] to <2 x i32>*
46880c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP11]], align 4
46890c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = getelementptr inbounds i32, i32* [[TMP8]], i32 2
46907c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = bitcast i32* [[TMP12]] to <2 x i32>*
46910c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP13]], align 4
4692eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
46937c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[STEP_ADD]], <i32 2, i32 2>
46940c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
46950c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP14]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP42:![0-9]+]]
4696eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
4697eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[K]], [[N_VEC]]
4698eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4699eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
4700eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER:%.*]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
4701eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
4702eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
4703eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4704eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TRUNC_IV:%.*]] = trunc i64 [[INDVARS_IV]] to i32
4705eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[TRUNC_IV]]
4706eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[TRUNC_IV]], i32* [[ARRAYIDX]], align 4
4707eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
4708eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[K]]
4709eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP43:![0-9]+]]
4710eb052f6bSPhilip Reames; UNROLL-NO-IC:       exit:
4711eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
4712eb052f6bSPhilip Reames;
4713eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @trunciv(
4714eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  for.body.preheader:
4715eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[K:%.*]], 8
4716eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
4717eb052f6bSPhilip Reames; INTERLEAVE:       vector.scevcheck:
471886d113a8SFlorian Hahn; INTERLEAVE-NEXT:    [[TMP0:%.*]] = add i64 [[K]], -1
47197c080e46SNikita Popov; INTERLEAVE-NEXT:    [[DOTNOT:%.*]] = icmp ult i64 [[TMP0]], 2147483648
47207c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 [[DOTNOT]], label [[VECTOR_PH:%.*]], label [[SCALAR_PH]]
4721eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
4722eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i64 [[K]], -8
4723eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
4724eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
4725eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
47267c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
47277c080e46SNikita Popov; INTERLEAVE-NEXT:    [[STEP_ADD:%.*]] = add <4 x i32> [[VEC_IND]], <i32 4, i32 4, i32 4, i32 4>
4728eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SEXT:%.*]] = shl i64 [[INDEX]], 32
47297c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP1:%.*]] = ashr exact i64 [[SEXT]], 32
47307c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP1]]
47317c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <4 x i32>*
47327c080e46SNikita Popov; INTERLEAVE-NEXT:    store <4 x i32> [[VEC_IND]], <4 x i32>* [[TMP3]], align 4
47337c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i64 4
47347c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP4]] to <4 x i32>*
47357c080e46SNikita Popov; INTERLEAVE-NEXT:    store <4 x i32> [[STEP_ADD]], <4 x i32>* [[TMP5]], align 4
4736eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
47377c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND_NEXT]] = add <4 x i32> [[VEC_IND]], <i32 8, i32 8, i32 8, i32 8>
47387c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
47397c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP42:![0-9]+]]
4740eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
4741eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[K]]
4742eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4743eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
4744eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER:%.*]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
4745eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
4746eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
4747eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4748eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TRUNC_IV:%.*]] = trunc i64 [[INDVARS_IV]] to i32
47497c080e46SNikita Popov; INTERLEAVE-NEXT:    [[SEXT2:%.*]] = shl i64 [[INDVARS_IV]], 32
47507c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP7:%.*]] = ashr exact i64 [[SEXT2]], 32
47517c080e46SNikita Popov; INTERLEAVE-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP7]]
4752eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[TRUNC_IV]], i32* [[ARRAYIDX]], align 4
4753eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
4754eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[K]]
4755eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP43:![0-9]+]]
4756eb052f6bSPhilip Reames; INTERLEAVE:       exit:
4757eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
4758eb052f6bSPhilip Reames;
4759cee313d2SEric Christopherfor.body.preheader:
4760cee313d2SEric Christopher  br label %for.body
4761cee313d2SEric Christopher
4762cee313d2SEric Christopherfor.body:
4763cee313d2SEric Christopher  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
4764cee313d2SEric Christopher  %trunc.iv = trunc i64 %indvars.iv to i32
4765cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %a, i32 %trunc.iv
4766cee313d2SEric Christopher  store i32 %trunc.iv, i32* %arrayidx, align 4
4767cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
4768cee313d2SEric Christopher  %exitcond = icmp eq i64 %indvars.iv.next, %k
4769cee313d2SEric Christopher  br i1 %exitcond, label %exit, label %for.body
4770cee313d2SEric Christopher
4771cee313d2SEric Christopherexit:
4772cee313d2SEric Christopher  ret void
4773cee313d2SEric Christopher}
4774cee313d2SEric Christopher
4775eb052f6bSPhilip Reames;
4776eb052f6bSPhilip Reames;
4777eb052f6bSPhilip Reamesdefine void @nonprimary(i32* nocapture %a, i32 %start, i32 %i, i32 %k) {
4778cee313d2SEric Christopher; CHECK-LABEL: @nonprimary(
4779eb052f6bSPhilip Reames; CHECK-NEXT:  for.body.preheader:
4780eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = sub i32 [[K:%.*]], [[I:%.*]]
4781eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 2
4782eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
4783cee313d2SEric Christopher; CHECK:       vector.ph:
4784eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[TMP0]], 2
4785eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i32 [[TMP0]], [[N_MOD_VF]]
4786eb052f6bSPhilip Reames; CHECK-NEXT:    [[IND_END:%.*]] = add i32 [[I]], [[N_VEC]]
4787eb052f6bSPhilip Reames; CHECK-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[I]], i32 0
4788eb052f6bSPhilip Reames; CHECK-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
4789eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDUCTION:%.*]] = add <2 x i32> [[DOTSPLAT]], <i32 0, i32 1>
4790eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
4791cee313d2SEric Christopher; CHECK:       vector.body:
4792eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
4793eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
4794eb052f6bSPhilip Reames; CHECK-NEXT:    [[OFFSET_IDX:%.*]] = add i32 [[I]], [[INDEX]]
4795eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = add i32 [[OFFSET_IDX]], 0
47960c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i32 [[TMP1]]
47970c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i32 0
47980c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP4:%.*]] = bitcast i32* [[TMP3]] to <2 x i32>*
47990c00dbb9SNikita Popov; CHECK-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP4]], align 4
4800eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
4801eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
48020c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
48030c00dbb9SNikita Popov; CHECK-NEXT:    br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP44:![0-9]+]]
4804eb052f6bSPhilip Reames; CHECK:       middle.block:
4805eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
4806eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4807eb052f6bSPhilip Reames; CHECK:       scalar.ph:
4808eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[I]], [[FOR_BODY_PREHEADER:%.*]] ]
4809eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
4810eb052f6bSPhilip Reames; CHECK:       for.body:
4811eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4812eb052f6bSPhilip Reames; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[INDVARS_IV]]
4813eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[INDVARS_IV]], i32* [[ARRAYIDX]], align 4
4814eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
4815eb052f6bSPhilip Reames; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[INDVARS_IV_NEXT]], [[K]]
4816eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP45:![0-9]+]]
4817eb052f6bSPhilip Reames; CHECK:       exit:
4818eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
4819cee313d2SEric Christopher;
4820cee313d2SEric Christopher; IND-LABEL: @nonprimary(
4821eb052f6bSPhilip Reames; IND-NEXT:  for.body.preheader:
4822eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = sub i32 [[K:%.*]], [[I:%.*]]
4823eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 2
4824eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
4825cee313d2SEric Christopher; IND:       vector.ph:
4826eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i32 [[TMP0]], -2
4827eb052f6bSPhilip Reames; IND-NEXT:    [[IND_END:%.*]] = add i32 [[N_VEC]], [[I]]
4828e6ad9ef4SPhilip Reames; IND-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[I]], i64 0
4829eb052f6bSPhilip Reames; IND-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
4830eb052f6bSPhilip Reames; IND-NEXT:    [[INDUCTION:%.*]] = add <2 x i32> [[DOTSPLAT]], <i32 0, i32 1>
4831eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
4832cee313d2SEric Christopher; IND:       vector.body:
4833eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
4834eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
4835eb052f6bSPhilip Reames; IND-NEXT:    [[OFFSET_IDX:%.*]] = add i32 [[INDEX]], [[I]]
4836eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = sext i32 [[OFFSET_IDX]] to i64
4837eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP1]]
4838eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <2 x i32>*
4839eb052f6bSPhilip Reames; IND-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP3]], align 4
4840eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
4841eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
4842eb052f6bSPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
4843eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP4]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP44:![0-9]+]]
4844eb052f6bSPhilip Reames; IND:       middle.block:
4845eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
4846eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4847eb052f6bSPhilip Reames; IND:       scalar.ph:
4848eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[I]], [[FOR_BODY_PREHEADER:%.*]] ]
4849eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
4850eb052f6bSPhilip Reames; IND:       for.body:
4851eb052f6bSPhilip Reames; IND-NEXT:    [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4852eb052f6bSPhilip Reames; IND-NEXT:    [[TMP5:%.*]] = sext i32 [[INDVARS_IV]] to i64
4853eb052f6bSPhilip Reames; IND-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP5]]
4854eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[INDVARS_IV]], i32* [[ARRAYIDX]], align 4
4855eb052f6bSPhilip Reames; IND-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
4856eb052f6bSPhilip Reames; IND-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[INDVARS_IV_NEXT]], [[K]]
4857eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP45:![0-9]+]]
4858eb052f6bSPhilip Reames; IND:       exit:
4859eb052f6bSPhilip Reames; IND-NEXT:    ret void
4860cee313d2SEric Christopher;
4861cee313d2SEric Christopher; UNROLL-LABEL: @nonprimary(
4862eb052f6bSPhilip Reames; UNROLL-NEXT:  for.body.preheader:
4863eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = sub i32 [[K:%.*]], [[I:%.*]]
4864eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 4
4865eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
4866cee313d2SEric Christopher; UNROLL:       vector.ph:
4867eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i32 [[TMP0]], -4
4868eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IND_END:%.*]] = add i32 [[N_VEC]], [[I]]
4869e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[I]], i64 0
4870eb052f6bSPhilip Reames; UNROLL-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
4871eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDUCTION:%.*]] = add <2 x i32> [[DOTSPLAT]], <i32 0, i32 1>
4872eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
4873cee313d2SEric Christopher; UNROLL:       vector.body:
4874eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
4875eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
4876eb052f6bSPhilip Reames; UNROLL-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
4877eb052f6bSPhilip Reames; UNROLL-NEXT:    [[OFFSET_IDX:%.*]] = add i32 [[INDEX]], [[I]]
4878eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = sext i32 [[OFFSET_IDX]] to i64
4879eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP1]]
4880eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <2 x i32>*
4881eb052f6bSPhilip Reames; UNROLL-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP3]], align 4
4882eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i64 2
4883eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP4]] to <2 x i32>*
4884eb052f6bSPhilip Reames; UNROLL-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP5]], align 4
4885eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
4886eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 4, i32 4>
4887eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP6:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
4888eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP44:![0-9]+]]
4889eb052f6bSPhilip Reames; UNROLL:       middle.block:
4890eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
4891eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4892eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
4893eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[I]], [[FOR_BODY_PREHEADER:%.*]] ]
4894eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
4895eb052f6bSPhilip Reames; UNROLL:       for.body:
4896eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4897eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP7:%.*]] = sext i32 [[INDVARS_IV]] to i64
4898eb052f6bSPhilip Reames; UNROLL-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP7]]
4899eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[INDVARS_IV]], i32* [[ARRAYIDX]], align 4
4900eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
4901eb052f6bSPhilip Reames; UNROLL-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[INDVARS_IV_NEXT]], [[K]]
4902eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP45:![0-9]+]]
4903eb052f6bSPhilip Reames; UNROLL:       exit:
4904eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
4905eb052f6bSPhilip Reames;
4906eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @nonprimary(
4907eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  for.body.preheader:
4908eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = sub i32 [[K:%.*]], [[I:%.*]]
4909eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 4
4910eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
4911eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
4912eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[TMP0]], 4
4913eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i32 [[TMP0]], [[N_MOD_VF]]
4914eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IND_END:%.*]] = add i32 [[I]], [[N_VEC]]
4915eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[I]], i32 0
4916eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
4917eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDUCTION:%.*]] = add <2 x i32> [[DOTSPLAT]], <i32 0, i32 1>
4918eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
4919eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
4920eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
4921eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
4922eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
4923eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[OFFSET_IDX:%.*]] = add i32 [[I]], [[INDEX]]
4924eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = add i32 [[OFFSET_IDX]], 0
49250c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = add i32 [[OFFSET_IDX]], 2
49260c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i32 [[TMP1]]
49270c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[TMP2]]
49280c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = getelementptr inbounds i32, i32* [[TMP3]], i32 0
49290c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = bitcast i32* [[TMP5]] to <2 x i32>*
49300c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP6]], align 4
49310c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = getelementptr inbounds i32, i32* [[TMP3]], i32 2
4932eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = bitcast i32* [[TMP7]] to <2 x i32>*
49330c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP8]], align 4
4934eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
4935eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[STEP_ADD]], <i32 2, i32 2>
49360c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
49370c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP44:![0-9]+]]
4938eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
4939eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
4940eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4941eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
4942eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[I]], [[FOR_BODY_PREHEADER:%.*]] ]
4943eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
4944eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
4945eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4946eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[INDVARS_IV]]
4947eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[INDVARS_IV]], i32* [[ARRAYIDX]], align 4
4948eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
4949eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[INDVARS_IV_NEXT]], [[K]]
4950eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP45:![0-9]+]]
4951eb052f6bSPhilip Reames; UNROLL-NO-IC:       exit:
4952eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
4953eb052f6bSPhilip Reames;
4954eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @nonprimary(
4955eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  for.body.preheader:
4956eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = sub i32 [[K:%.*]], [[I:%.*]]
4957eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 8
4958eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
4959eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
4960eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i32 [[TMP0]], -8
4961eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IND_END:%.*]] = add i32 [[N_VEC]], [[I]]
4962e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[I]], i64 0
4963eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <4 x i32> [[DOTSPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
4964eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDUCTION:%.*]] = add <4 x i32> [[DOTSPLAT]], <i32 0, i32 1, i32 2, i32 3>
4965eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
4966eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
4967eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
4968eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_IND:%.*]] = phi <4 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
4969eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[STEP_ADD:%.*]] = add <4 x i32> [[VEC_IND]], <i32 4, i32 4, i32 4, i32 4>
4970eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[OFFSET_IDX:%.*]] = add i32 [[INDEX]], [[I]]
4971eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = sext i32 [[OFFSET_IDX]] to i64
4972eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP1]]
4973eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <4 x i32>*
4974eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store <4 x i32> [[VEC_IND]], <4 x i32>* [[TMP3]], align 4
4975eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i64 4
4976eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP4]] to <4 x i32>*
4977eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store <4 x i32> [[STEP_ADD]], <4 x i32>* [[TMP5]], align 4
4978eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8
4979eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_IND_NEXT]] = add <4 x i32> [[VEC_IND]], <i32 8, i32 8, i32 8, i32 8>
4980eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
4981eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP44:![0-9]+]]
4982eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
4983eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
4984eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
4985eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
4986eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[I]], [[FOR_BODY_PREHEADER:%.*]] ]
4987eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
4988eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
4989eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDVARS_IV:%.*]] = phi i32 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
4990eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP7:%.*]] = sext i32 [[INDVARS_IV]] to i64
4991eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP7]]
4992eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[INDVARS_IV]], i32* [[ARRAYIDX]], align 4
4993eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i32 [[INDVARS_IV]], 1
4994eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[INDVARS_IV_NEXT]], [[K]]
4995eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP45:![0-9]+]]
4996eb052f6bSPhilip Reames; INTERLEAVE:       exit:
4997eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
4998eb052f6bSPhilip Reames;
4999cee313d2SEric Christopherfor.body.preheader:
5000cee313d2SEric Christopher  br label %for.body
5001cee313d2SEric Christopher
5002cee313d2SEric Christopherfor.body:
5003cee313d2SEric Christopher  %indvars.iv = phi i32 [ %indvars.iv.next, %for.body ], [ %i, %for.body.preheader ]
5004cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %a, i32 %indvars.iv
5005cee313d2SEric Christopher  store i32 %indvars.iv, i32* %arrayidx, align 4
5006cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
5007cee313d2SEric Christopher  %exitcond = icmp eq i32 %indvars.iv.next, %k
5008cee313d2SEric Christopher  br i1 %exitcond, label %exit, label %for.body
5009cee313d2SEric Christopher
5010cee313d2SEric Christopherexit:
5011cee313d2SEric Christopher  ret void
5012cee313d2SEric Christopher}
5013cee313d2SEric Christopher
5014bbba8676SPhilip Reamesdefine void @non_primary_iv_trunc(i32* %a, i64 %n) {
5015eb052f6bSPhilip Reames; CHECK-LABEL: @non_primary_iv_trunc(
5016eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
5017eb052f6bSPhilip Reames; CHECK-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
5018eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 2
5019eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5020eb052f6bSPhilip Reames; CHECK:       vector.ph:
5021eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[SMAX]], 2
5022eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[SMAX]], [[N_MOD_VF]]
5023eb052f6bSPhilip Reames; CHECK-NEXT:    [[IND_END:%.*]] = mul i64 [[N_VEC]], 2
5024eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
5025eb052f6bSPhilip Reames; CHECK:       vector.body:
5026eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
50277c080e46SNikita Popov; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
5028eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
5029eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP0]]
5030eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[TMP1]], i32 0
5031eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <2 x i32>*
50327c080e46SNikita Popov; CHECK-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP3]], align 4
5033eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
50347c080e46SNikita Popov; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 4, i32 4>
5035eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
5036eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP4]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP46:![0-9]+]]
5037eb052f6bSPhilip Reames; CHECK:       middle.block:
5038eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
5039eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
5040eb052f6bSPhilip Reames; CHECK:       scalar.ph:
5041eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
5042eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
5043eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
5044eb052f6bSPhilip Reames; CHECK:       for.body:
5045eb052f6bSPhilip Reames; CHECK-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
5046eb052f6bSPhilip Reames; CHECK-NEXT:    [[J:%.*]] = phi i64 [ [[J_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
5047eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR0:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[I]]
5048eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR1:%.*]] = trunc i64 [[J]] to i32
5049eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[VAR1]], i32* [[VAR0]], align 4
5050eb052f6bSPhilip Reames; CHECK-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
5051eb052f6bSPhilip Reames; CHECK-NEXT:    [[J_NEXT]] = add nuw nsw i64 [[J]], 2
5052eb052f6bSPhilip Reames; CHECK-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
5053eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP47:![0-9]+]]
5054eb052f6bSPhilip Reames; CHECK:       for.end:
5055eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
5056eb052f6bSPhilip Reames;
5057eb052f6bSPhilip Reames; IND-LABEL: @non_primary_iv_trunc(
5058eb052f6bSPhilip Reames; IND-NEXT:  entry:
5059eb052f6bSPhilip Reames; IND-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
5060eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 2
5061eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5062eb052f6bSPhilip Reames; IND:       vector.ph:
5063eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i64 [[SMAX]], 9223372036854775806
5064eb052f6bSPhilip Reames; IND-NEXT:    [[IND_END:%.*]] = shl nuw i64 [[N_VEC]], 1
5065eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
5066eb052f6bSPhilip Reames; IND:       vector.body:
5067eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
50687c080e46SNikita Popov; IND-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
5069eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[INDEX]]
5070eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = bitcast i32* [[TMP0]] to <2 x i32>*
50717c080e46SNikita Popov; IND-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP1]], align 4
5072eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
50737c080e46SNikita Popov; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 4, i32 4>
5074eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
5075eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP2]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP46:![0-9]+]]
5076eb052f6bSPhilip Reames; IND:       middle.block:
5077eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
5078eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
5079eb052f6bSPhilip Reames; IND:       scalar.ph:
5080eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
5081eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
5082eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
5083eb052f6bSPhilip Reames; IND:       for.body:
5084eb052f6bSPhilip Reames; IND-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
5085eb052f6bSPhilip Reames; IND-NEXT:    [[J:%.*]] = phi i64 [ [[J_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
5086eb052f6bSPhilip Reames; IND-NEXT:    [[VAR0:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[I]]
5087eb052f6bSPhilip Reames; IND-NEXT:    [[VAR1:%.*]] = trunc i64 [[J]] to i32
5088eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[VAR1]], i32* [[VAR0]], align 4
5089eb052f6bSPhilip Reames; IND-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
5090eb052f6bSPhilip Reames; IND-NEXT:    [[J_NEXT]] = add nuw nsw i64 [[J]], 2
5091eb052f6bSPhilip Reames; IND-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
5092eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP47:![0-9]+]]
5093eb052f6bSPhilip Reames; IND:       for.end:
5094eb052f6bSPhilip Reames; IND-NEXT:    ret void
5095eb052f6bSPhilip Reames;
5096eb052f6bSPhilip Reames; UNROLL-LABEL: @non_primary_iv_trunc(
5097eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
5098eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
5099eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 4
5100eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5101eb052f6bSPhilip Reames; UNROLL:       vector.ph:
5102eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i64 [[SMAX]], 9223372036854775804
5103eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IND_END:%.*]] = shl nuw i64 [[N_VEC]], 1
5104eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
5105eb052f6bSPhilip Reames; UNROLL:       vector.body:
5106eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
51077c080e46SNikita Popov; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
51087c080e46SNikita Popov; UNROLL-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 4, i32 4>
5109eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[INDEX]]
5110eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = bitcast i32* [[TMP0]] to <2 x i32>*
51117c080e46SNikita Popov; UNROLL-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP1]], align 4
5112eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[TMP0]], i64 2
5113eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <2 x i32>*
51147c080e46SNikita Popov; UNROLL-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP3]], align 4
5115eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
51167c080e46SNikita Popov; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 8, i32 8>
5117eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
5118eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP4]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP46:![0-9]+]]
5119eb052f6bSPhilip Reames; UNROLL:       middle.block:
5120eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
5121eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
5122eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
5123eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
5124eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
5125eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
5126eb052f6bSPhilip Reames; UNROLL:       for.body:
5127eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
5128eb052f6bSPhilip Reames; UNROLL-NEXT:    [[J:%.*]] = phi i64 [ [[J_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
5129eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VAR0:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[I]]
5130eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VAR1:%.*]] = trunc i64 [[J]] to i32
5131eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[VAR1]], i32* [[VAR0]], align 4
5132eb052f6bSPhilip Reames; UNROLL-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
5133eb052f6bSPhilip Reames; UNROLL-NEXT:    [[J_NEXT]] = add nuw nsw i64 [[J]], 2
5134eb052f6bSPhilip Reames; UNROLL-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
5135eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP47:![0-9]+]]
5136eb052f6bSPhilip Reames; UNROLL:       for.end:
5137eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
5138eb052f6bSPhilip Reames;
5139eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @non_primary_iv_trunc(
5140eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
5141eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
5142eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 4
5143eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5144eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
5145eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[SMAX]], 4
5146eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i64 [[SMAX]], [[N_MOD_VF]]
5147eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IND_END:%.*]] = mul i64 [[N_VEC]], 2
5148eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
5149eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
5150eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
51517c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
51527c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 4, i32 4>
5153eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
5154eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = add i64 [[INDEX]], 2
5155eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP0]]
5156eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP1]]
5157eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i32 0
5158eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = bitcast i32* [[TMP4]] to <2 x i32>*
51597c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP5]], align 4
5160eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i32 2
5161eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = bitcast i32* [[TMP6]] to <2 x i32>*
51627c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[STEP_ADD]], <2 x i32>* [[TMP7]], align 4
5163eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
51647c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[STEP_ADD]], <i32 4, i32 4>
5165eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
5166eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP46:![0-9]+]]
5167eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
5168eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
5169eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
5170eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
5171eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
5172eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
5173eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
5174eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
5175eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
5176eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[J:%.*]] = phi i64 [ [[J_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
5177eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR0:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[I]]
5178eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR1:%.*]] = trunc i64 [[J]] to i32
5179eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[VAR1]], i32* [[VAR0]], align 4
5180eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
5181eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[J_NEXT]] = add nuw nsw i64 [[J]], 2
5182eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
5183eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP47:![0-9]+]]
5184eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.end:
5185eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
5186eb052f6bSPhilip Reames;
5187eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @non_primary_iv_trunc(
5188eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
5189eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SMAX:%.*]] = call i64 @llvm.smax.i64(i64 [[N:%.*]], i64 1)
5190eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SMAX]], 8
5191eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5192eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
5193eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i64 [[SMAX]], 9223372036854775800
5194eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IND_END:%.*]] = shl nuw i64 [[N_VEC]], 1
5195eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
5196eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
5197eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
51987c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 2, i32 4, i32 6>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
51997c080e46SNikita Popov; INTERLEAVE-NEXT:    [[STEP_ADD:%.*]] = add <4 x i32> [[VEC_IND]], <i32 8, i32 8, i32 8, i32 8>
5200eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[INDEX]]
5201eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = bitcast i32* [[TMP0]] to <4 x i32>*
52027c080e46SNikita Popov; INTERLEAVE-NEXT:    store <4 x i32> [[VEC_IND]], <4 x i32>* [[TMP1]], align 4
5203eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[TMP0]], i64 4
5204eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP2]] to <4 x i32>*
52057c080e46SNikita Popov; INTERLEAVE-NEXT:    store <4 x i32> [[STEP_ADD]], <4 x i32>* [[TMP3]], align 4
5206eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
52077c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND_NEXT]] = add <4 x i32> [[VEC_IND]], <i32 16, i32 16, i32 16, i32 16>
5208eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
5209eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP4]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP46:![0-9]+]]
5210eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
5211eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[SMAX]], [[N_VEC]]
5212eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
5213eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
5214eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
5215eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
5216eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
5217eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
5218eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
5219eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[J:%.*]] = phi i64 [ [[J_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
5220eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR0:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[I]]
5221eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR1:%.*]] = trunc i64 [[J]] to i32
5222eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[VAR1]], i32* [[VAR0]], align 4
5223eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I_NEXT]] = add nuw nsw i64 [[I]], 1
5224eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[J_NEXT]] = add nuw nsw i64 [[J]], 2
5225eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[COND:%.*]] = icmp slt i64 [[I_NEXT]], [[N]]
5226eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[COND]], label [[FOR_BODY]], label [[FOR_END]], !llvm.loop [[LOOP47:![0-9]+]]
5227eb052f6bSPhilip Reames; INTERLEAVE:       for.end:
5228eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
5229eb052f6bSPhilip Reames;
5230cee313d2SEric Christopherentry:
5231cee313d2SEric Christopher  br label %for.body
5232cee313d2SEric Christopher
5233cee313d2SEric Christopherfor.body:
5234cee313d2SEric Christopher  %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
5235cee313d2SEric Christopher  %j = phi i64 [ %j.next, %for.body ], [ 0, %entry ]
5236eb052f6bSPhilip Reames  %var0 = getelementptr inbounds i32, i32* %a, i64 %i
5237eb052f6bSPhilip Reames  %var1 = trunc i64 %j to i32
5238eb052f6bSPhilip Reames  store i32 %var1, i32* %var0, align 4
5239cee313d2SEric Christopher  %i.next = add nuw nsw i64 %i, 1
5240cee313d2SEric Christopher  %j.next = add nuw nsw i64 %j, 2
5241cee313d2SEric Christopher  %cond = icmp slt i64 %i.next, %n
5242cee313d2SEric Christopher  br i1 %cond, label %for.body, label %for.end
5243cee313d2SEric Christopher
5244cee313d2SEric Christopherfor.end:
5245cee313d2SEric Christopher  ret void
5246cee313d2SEric Christopher}
5247cee313d2SEric Christopher
5248cee313d2SEric Christopher; PR32419. Ensure we transform truncated non-primary induction variables. In
5249eb052f6bSPhilip Reames; the test case below we replace %var1 with a new induction variable. Because
5250cee313d2SEric Christopher; the truncated value is non-primary, we must compute an offset from the
5251cee313d2SEric Christopher; primary induction variable.
5252cee313d2SEric Christopher;
5253cee313d2SEric Christopher;
5254cee313d2SEric Christopherdefine i32 @PR32419(i32 %a, i16 %b) {
5255eb052f6bSPhilip Reames; CHECK-LABEL: @PR32419(
5256eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
5257eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5258eb052f6bSPhilip Reames; CHECK:       vector.ph:
5259eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = insertelement <2 x i32> zeroinitializer, i32 [[A:%.*]], i32 0
5260eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
5261eb052f6bSPhilip Reames; CHECK:       vector.body:
52627c080e46SNikita Popov; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_UREM_CONTINUE2:%.*]] ]
52637c080e46SNikita Popov; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ [[TMP0]], [[VECTOR_PH]] ], [ [[TMP15:%.*]], [[PRED_UREM_CONTINUE2]] ]
52647c080e46SNikita Popov; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <2 x i16> [ <i16 -20, i16 -19>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[PRED_UREM_CONTINUE2]] ]
5265eb052f6bSPhilip Reames; CHECK-NEXT:    [[OFFSET_IDX:%.*]] = add i32 -20, [[INDEX]]
5266eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = trunc i32 [[OFFSET_IDX]] to i16
52677c080e46SNikita Popov; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq <2 x i16> [[VEC_IND]], zeroinitializer
5268eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = xor <2 x i1> [[TMP2]], <i1 true, i1 true>
5269eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = extractelement <2 x i1> [[TMP3]], i32 0
5270eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP4]], label [[PRED_UREM_IF:%.*]], label [[PRED_UREM_CONTINUE:%.*]]
5271eb052f6bSPhilip Reames; CHECK:       pred.urem.if:
5272eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP5:%.*]] = add i16 [[TMP1]], 0
5273eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP6:%.*]] = urem i16 [[B:%.*]], [[TMP5]]
5274eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP7:%.*]] = insertelement <2 x i16> poison, i16 [[TMP6]], i32 0
5275eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[PRED_UREM_CONTINUE]]
5276eb052f6bSPhilip Reames; CHECK:       pred.urem.continue:
5277eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP8:%.*]] = phi <2 x i16> [ poison, [[VECTOR_BODY]] ], [ [[TMP7]], [[PRED_UREM_IF]] ]
5278eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP9:%.*]] = extractelement <2 x i1> [[TMP3]], i32 1
52797c080e46SNikita Popov; CHECK-NEXT:    br i1 [[TMP9]], label [[PRED_UREM_IF1:%.*]], label [[PRED_UREM_CONTINUE2]]
5280da740492SFlorian Hahn; CHECK:       pred.urem.if1:
5281eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP10:%.*]] = add i16 [[TMP1]], 1
5282eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP11:%.*]] = urem i16 [[B]], [[TMP10]]
5283eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP12:%.*]] = insertelement <2 x i16> [[TMP8]], i16 [[TMP11]], i32 1
52847c080e46SNikita Popov; CHECK-NEXT:    br label [[PRED_UREM_CONTINUE2]]
5285da740492SFlorian Hahn; CHECK:       pred.urem.continue2:
52867c080e46SNikita Popov; CHECK-NEXT:    [[TMP13:%.*]] = phi <2 x i16> [ [[TMP8]], [[PRED_UREM_CONTINUE]] ], [ [[TMP12]], [[PRED_UREM_IF1]] ]
5287eb052f6bSPhilip Reames; CHECK-NEXT:    [[PREDPHI:%.*]] = select <2 x i1> [[TMP2]], <2 x i16> zeroinitializer, <2 x i16> [[TMP13]]
5288eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP14:%.*]] = sext <2 x i16> [[PREDPHI]] to <2 x i32>
5289eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP15]] = or <2 x i32> [[VEC_PHI]], [[TMP14]]
5290eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
52917c080e46SNikita Popov; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i16> [[VEC_IND]], <i16 2, i16 2>
5292eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP16:%.*]] = icmp eq i32 [[INDEX_NEXT]], 20
5293eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP16]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP48:![0-9]+]]
5294eb052f6bSPhilip Reames; CHECK:       middle.block:
5295eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP17:%.*]] = call i32 @llvm.vector.reduce.or.v2i32(<2 x i32> [[TMP15]])
5296eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i32 20, 20
5297eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
5298eb052f6bSPhilip Reames; CHECK:       scalar.ph:
5299eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ 0, [[MIDDLE_BLOCK]] ], [ -20, [[ENTRY:%.*]] ]
5300eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ [[A]], [[ENTRY]] ], [ [[TMP17]], [[MIDDLE_BLOCK]] ]
5301eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
5302eb052f6bSPhilip Reames; CHECK:       for.body:
5303eb052f6bSPhilip Reames; CHECK-NEXT:    [[I:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[FOR_INC:%.*]] ]
5304eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR0:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[VAR6:%.*]], [[FOR_INC]] ]
5305eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR1:%.*]] = trunc i32 [[I]] to i16
5306eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR2:%.*]] = icmp eq i16 [[VAR1]], 0
5307eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[VAR2]], label [[FOR_INC]], label [[FOR_COND:%.*]]
5308eb052f6bSPhilip Reames; CHECK:       for.cond:
5309eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR3:%.*]] = urem i16 [[B]], [[VAR1]]
5310eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[FOR_INC]]
5311eb052f6bSPhilip Reames; CHECK:       for.inc:
5312eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR4:%.*]] = phi i16 [ [[VAR3]], [[FOR_COND]] ], [ 0, [[FOR_BODY]] ]
5313eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR5:%.*]] = sext i16 [[VAR4]] to i32
5314eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR6]] = or i32 [[VAR0]], [[VAR5]]
5315eb052f6bSPhilip Reames; CHECK-NEXT:    [[I_NEXT]] = add nsw i32 [[I]], 1
5316eb052f6bSPhilip Reames; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 [[I_NEXT]], 0
5317eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[COND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP49:![0-9]+]]
5318eb052f6bSPhilip Reames; CHECK:       for.end:
5319eb052f6bSPhilip Reames; CHECK-NEXT:    [[VAR7:%.*]] = phi i32 [ [[VAR6]], [[FOR_INC]] ], [ [[TMP17]], [[MIDDLE_BLOCK]] ]
5320eb052f6bSPhilip Reames; CHECK-NEXT:    ret i32 [[VAR7]]
5321eb052f6bSPhilip Reames;
5322eb052f6bSPhilip Reames; IND-LABEL: @PR32419(
5323eb052f6bSPhilip Reames; IND-NEXT:  entry:
5324eb052f6bSPhilip Reames; IND-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5325eb052f6bSPhilip Reames; IND:       vector.ph:
5326e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = insertelement <2 x i32> <i32 poison, i32 0>, i32 [[A:%.*]], i64 0
5327eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
5328eb052f6bSPhilip Reames; IND:       vector.body:
53297c080e46SNikita Popov; IND-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_UREM_CONTINUE2:%.*]] ]
53307c080e46SNikita Popov; IND-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ [[TMP0]], [[VECTOR_PH]] ], [ [[TMP15:%.*]], [[PRED_UREM_CONTINUE2]] ]
53317c080e46SNikita Popov; IND-NEXT:    [[VEC_IND:%.*]] = phi <2 x i16> [ <i16 -20, i16 -19>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[PRED_UREM_CONTINUE2]] ]
5332eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = trunc i32 [[INDEX]] to i16
53337c080e46SNikita Popov; IND-NEXT:    [[TMP2:%.*]] = icmp eq <2 x i16> [[VEC_IND]], zeroinitializer
5334eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = xor <2 x i1> [[TMP2]], <i1 true, i1 true>
5335e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = extractelement <2 x i1> [[TMP3]], i64 0
5336eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP4]], label [[PRED_UREM_IF:%.*]], label [[PRED_UREM_CONTINUE:%.*]]
5337eb052f6bSPhilip Reames; IND:       pred.urem.if:
5338eb052f6bSPhilip Reames; IND-NEXT:    [[TMP5:%.*]] = add i16 [[TMP1]], -20
5339eb052f6bSPhilip Reames; IND-NEXT:    [[TMP6:%.*]] = urem i16 [[B:%.*]], [[TMP5]]
5340e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP7:%.*]] = insertelement <2 x i16> poison, i16 [[TMP6]], i64 0
5341eb052f6bSPhilip Reames; IND-NEXT:    br label [[PRED_UREM_CONTINUE]]
5342eb052f6bSPhilip Reames; IND:       pred.urem.continue:
5343eb052f6bSPhilip Reames; IND-NEXT:    [[TMP8:%.*]] = phi <2 x i16> [ poison, [[VECTOR_BODY]] ], [ [[TMP7]], [[PRED_UREM_IF]] ]
5344e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP9:%.*]] = extractelement <2 x i1> [[TMP3]], i64 1
53457c080e46SNikita Popov; IND-NEXT:    br i1 [[TMP9]], label [[PRED_UREM_IF1:%.*]], label [[PRED_UREM_CONTINUE2]]
5346da740492SFlorian Hahn; IND:       pred.urem.if1:
5347eb052f6bSPhilip Reames; IND-NEXT:    [[TMP10:%.*]] = add i16 [[TMP1]], -19
5348eb052f6bSPhilip Reames; IND-NEXT:    [[TMP11:%.*]] = urem i16 [[B]], [[TMP10]]
5349e6ad9ef4SPhilip Reames; IND-NEXT:    [[TMP12:%.*]] = insertelement <2 x i16> [[TMP8]], i16 [[TMP11]], i64 1
53507c080e46SNikita Popov; IND-NEXT:    br label [[PRED_UREM_CONTINUE2]]
5351da740492SFlorian Hahn; IND:       pred.urem.continue2:
53527c080e46SNikita Popov; IND-NEXT:    [[TMP13:%.*]] = phi <2 x i16> [ [[TMP8]], [[PRED_UREM_CONTINUE]] ], [ [[TMP12]], [[PRED_UREM_IF1]] ]
5353eb052f6bSPhilip Reames; IND-NEXT:    [[PREDPHI:%.*]] = select <2 x i1> [[TMP2]], <2 x i16> zeroinitializer, <2 x i16> [[TMP13]]
5354eb052f6bSPhilip Reames; IND-NEXT:    [[TMP14:%.*]] = sext <2 x i16> [[PREDPHI]] to <2 x i32>
5355eb052f6bSPhilip Reames; IND-NEXT:    [[TMP15]] = or <2 x i32> [[VEC_PHI]], [[TMP14]]
5356eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
53577c080e46SNikita Popov; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i16> [[VEC_IND]], <i16 2, i16 2>
5358eb052f6bSPhilip Reames; IND-NEXT:    [[TMP16:%.*]] = icmp eq i32 [[INDEX_NEXT]], 20
5359eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP16]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP48:![0-9]+]]
5360eb052f6bSPhilip Reames; IND:       middle.block:
5361eb052f6bSPhilip Reames; IND-NEXT:    [[TMP17:%.*]] = call i32 @llvm.vector.reduce.or.v2i32(<2 x i32> [[TMP15]])
5362eb052f6bSPhilip Reames; IND-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
5363eb052f6bSPhilip Reames; IND:       scalar.ph:
5364eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_BODY:%.*]]
5365eb052f6bSPhilip Reames; IND:       for.body:
5366*9df0b254SNuno Lopes; IND-NEXT:    br i1 poison, label [[FOR_INC:%.*]], label [[FOR_COND:%.*]]
5367eb052f6bSPhilip Reames; IND:       for.cond:
5368eb052f6bSPhilip Reames; IND-NEXT:    br label [[FOR_INC]]
5369eb052f6bSPhilip Reames; IND:       for.inc:
5370*9df0b254SNuno Lopes; IND-NEXT:    br i1 poison, label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP49:![0-9]+]]
5371eb052f6bSPhilip Reames; IND:       for.end:
5372*9df0b254SNuno Lopes; IND-NEXT:    [[VAR7:%.*]] = phi i32 [ poison, [[FOR_INC]] ], [ [[TMP17]], [[MIDDLE_BLOCK]] ]
5373eb052f6bSPhilip Reames; IND-NEXT:    ret i32 [[VAR7]]
5374eb052f6bSPhilip Reames;
5375eb052f6bSPhilip Reames; UNROLL-LABEL: @PR32419(
5376eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
5377eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5378eb052f6bSPhilip Reames; UNROLL:       vector.ph:
5379e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = insertelement <2 x i32> <i32 poison, i32 0>, i32 [[A:%.*]], i64 0
5380eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
5381eb052f6bSPhilip Reames; UNROLL:       vector.body:
53827c080e46SNikita Popov; UNROLL-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_UREM_CONTINUE8:%.*]] ]
53837c080e46SNikita Popov; UNROLL-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ [[TMP0]], [[VECTOR_PH]] ], [ [[TMP28:%.*]], [[PRED_UREM_CONTINUE8]] ]
53847c080e46SNikita Popov; UNROLL-NEXT:    [[VEC_PHI1:%.*]] = phi <2 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP29:%.*]], [[PRED_UREM_CONTINUE8]] ]
53857c080e46SNikita Popov; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i16> [ <i16 -20, i16 -19>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[PRED_UREM_CONTINUE8]] ]
5386eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = trunc i32 [[INDEX]] to i16
53877c080e46SNikita Popov; UNROLL-NEXT:    [[TMP2:%.*]] = icmp eq <2 x i16> [[VEC_IND]], zeroinitializer
53887c080e46SNikita Popov; UNROLL-NEXT:    [[TMP3:%.*]] = icmp eq <2 x i16> [[VEC_IND]], <i16 -2, i16 -2>
5389eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = xor <2 x i1> [[TMP2]], <i1 true, i1 true>
5390eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = xor <2 x i1> [[TMP3]], <i1 true, i1 true>
5391e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP6:%.*]] = extractelement <2 x i1> [[TMP4]], i64 0
5392eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP6]], label [[PRED_UREM_IF:%.*]], label [[PRED_UREM_CONTINUE:%.*]]
5393eb052f6bSPhilip Reames; UNROLL:       pred.urem.if:
5394eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP7:%.*]] = add i16 [[TMP1]], -20
5395eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP8:%.*]] = urem i16 [[B:%.*]], [[TMP7]]
5396e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP9:%.*]] = insertelement <2 x i16> poison, i16 [[TMP8]], i64 0
5397eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[PRED_UREM_CONTINUE]]
5398eb052f6bSPhilip Reames; UNROLL:       pred.urem.continue:
5399eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP10:%.*]] = phi <2 x i16> [ poison, [[VECTOR_BODY]] ], [ [[TMP9]], [[PRED_UREM_IF]] ]
5400e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP11:%.*]] = extractelement <2 x i1> [[TMP4]], i64 1
54017c080e46SNikita Popov; UNROLL-NEXT:    br i1 [[TMP11]], label [[PRED_UREM_IF3:%.*]], label [[PRED_UREM_CONTINUE4:%.*]]
5402da740492SFlorian Hahn; UNROLL:       pred.urem.if3:
5403eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP12:%.*]] = add i16 [[TMP1]], -19
5404eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP13:%.*]] = urem i16 [[B]], [[TMP12]]
5405e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP14:%.*]] = insertelement <2 x i16> [[TMP10]], i16 [[TMP13]], i64 1
54067c080e46SNikita Popov; UNROLL-NEXT:    br label [[PRED_UREM_CONTINUE4]]
5407da740492SFlorian Hahn; UNROLL:       pred.urem.continue4:
54087c080e46SNikita Popov; UNROLL-NEXT:    [[TMP15:%.*]] = phi <2 x i16> [ [[TMP10]], [[PRED_UREM_CONTINUE]] ], [ [[TMP14]], [[PRED_UREM_IF3]] ]
5409e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP16:%.*]] = extractelement <2 x i1> [[TMP5]], i64 0
54107c080e46SNikita Popov; UNROLL-NEXT:    br i1 [[TMP16]], label [[PRED_UREM_IF5:%.*]], label [[PRED_UREM_CONTINUE6:%.*]]
5411da740492SFlorian Hahn; UNROLL:       pred.urem.if5:
5412eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP17:%.*]] = add i16 [[TMP1]], -18
5413eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP18:%.*]] = urem i16 [[B]], [[TMP17]]
5414e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP19:%.*]] = insertelement <2 x i16> poison, i16 [[TMP18]], i64 0
54157c080e46SNikita Popov; UNROLL-NEXT:    br label [[PRED_UREM_CONTINUE6]]
5416da740492SFlorian Hahn; UNROLL:       pred.urem.continue6:
54177c080e46SNikita Popov; UNROLL-NEXT:    [[TMP20:%.*]] = phi <2 x i16> [ poison, [[PRED_UREM_CONTINUE4]] ], [ [[TMP19]], [[PRED_UREM_IF5]] ]
5418e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP21:%.*]] = extractelement <2 x i1> [[TMP5]], i64 1
54197c080e46SNikita Popov; UNROLL-NEXT:    br i1 [[TMP21]], label [[PRED_UREM_IF7:%.*]], label [[PRED_UREM_CONTINUE8]]
5420da740492SFlorian Hahn; UNROLL:       pred.urem.if7:
5421eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP22:%.*]] = add i16 [[TMP1]], -17
5422eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP23:%.*]] = urem i16 [[B]], [[TMP22]]
5423e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[TMP24:%.*]] = insertelement <2 x i16> [[TMP20]], i16 [[TMP23]], i64 1
54247c080e46SNikita Popov; UNROLL-NEXT:    br label [[PRED_UREM_CONTINUE8]]
5425da740492SFlorian Hahn; UNROLL:       pred.urem.continue8:
54267c080e46SNikita Popov; UNROLL-NEXT:    [[TMP25:%.*]] = phi <2 x i16> [ [[TMP20]], [[PRED_UREM_CONTINUE6]] ], [ [[TMP24]], [[PRED_UREM_IF7]] ]
5427eb052f6bSPhilip Reames; UNROLL-NEXT:    [[PREDPHI:%.*]] = select <2 x i1> [[TMP2]], <2 x i16> zeroinitializer, <2 x i16> [[TMP15]]
54287c080e46SNikita Popov; UNROLL-NEXT:    [[PREDPHI9:%.*]] = select <2 x i1> [[TMP3]], <2 x i16> zeroinitializer, <2 x i16> [[TMP25]]
5429eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP26:%.*]] = sext <2 x i16> [[PREDPHI]] to <2 x i32>
54307c080e46SNikita Popov; UNROLL-NEXT:    [[TMP27:%.*]] = sext <2 x i16> [[PREDPHI9]] to <2 x i32>
5431eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP28]] = or <2 x i32> [[VEC_PHI]], [[TMP26]]
54327c080e46SNikita Popov; UNROLL-NEXT:    [[TMP29]] = or <2 x i32> [[VEC_PHI1]], [[TMP27]]
5433eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
54347c080e46SNikita Popov; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i16> [[VEC_IND]], <i16 4, i16 4>
5435eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP30:%.*]] = icmp eq i32 [[INDEX_NEXT]], 20
5436eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP30]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP48:![0-9]+]]
5437eb052f6bSPhilip Reames; UNROLL:       middle.block:
5438eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BIN_RDX:%.*]] = or <2 x i32> [[TMP29]], [[TMP28]]
5439eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP31:%.*]] = call i32 @llvm.vector.reduce.or.v2i32(<2 x i32> [[BIN_RDX]])
5440eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
5441eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
5442eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_BODY:%.*]]
5443eb052f6bSPhilip Reames; UNROLL:       for.body:
5444*9df0b254SNuno Lopes; UNROLL-NEXT:    br i1 poison, label [[FOR_INC:%.*]], label [[FOR_COND:%.*]]
5445eb052f6bSPhilip Reames; UNROLL:       for.cond:
5446eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[FOR_INC]]
5447eb052f6bSPhilip Reames; UNROLL:       for.inc:
5448*9df0b254SNuno Lopes; UNROLL-NEXT:    br i1 poison, label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP49:![0-9]+]]
5449eb052f6bSPhilip Reames; UNROLL:       for.end:
5450*9df0b254SNuno Lopes; UNROLL-NEXT:    [[VAR7:%.*]] = phi i32 [ poison, [[FOR_INC]] ], [ [[TMP31]], [[MIDDLE_BLOCK]] ]
5451eb052f6bSPhilip Reames; UNROLL-NEXT:    ret i32 [[VAR7]]
5452eb052f6bSPhilip Reames;
5453eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @PR32419(
5454eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
5455eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5456eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
5457eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = insertelement <2 x i32> zeroinitializer, i32 [[A:%.*]], i32 0
5458eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
5459eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
54607c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_UREM_CONTINUE8:%.*]] ]
54617c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i32> [ [[TMP0]], [[VECTOR_PH]] ], [ [[TMP28:%.*]], [[PRED_UREM_CONTINUE8]] ]
54627c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_PHI1:%.*]] = phi <2 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP29:%.*]], [[PRED_UREM_CONTINUE8]] ]
54637c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i16> [ <i16 -20, i16 -19>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[PRED_UREM_CONTINUE8]] ]
54647c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[STEP_ADD:%.*]] = add <2 x i16> [[VEC_IND]], <i16 2, i16 2>
5465eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[OFFSET_IDX:%.*]] = add i32 -20, [[INDEX]]
5466eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = trunc i32 [[OFFSET_IDX]] to i16
54677c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = icmp eq <2 x i16> [[VEC_IND]], zeroinitializer
54687c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = icmp eq <2 x i16> [[STEP_ADD]], zeroinitializer
5469eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = xor <2 x i1> [[TMP2]], <i1 true, i1 true>
5470eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = xor <2 x i1> [[TMP3]], <i1 true, i1 true>
5471eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = extractelement <2 x i1> [[TMP4]], i32 0
5472eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP6]], label [[PRED_UREM_IF:%.*]], label [[PRED_UREM_CONTINUE:%.*]]
5473eb052f6bSPhilip Reames; UNROLL-NO-IC:       pred.urem.if:
5474eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = add i16 [[TMP1]], 0
5475eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = urem i16 [[B:%.*]], [[TMP7]]
5476eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = insertelement <2 x i16> poison, i16 [[TMP8]], i32 0
5477eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[PRED_UREM_CONTINUE]]
5478eb052f6bSPhilip Reames; UNROLL-NO-IC:       pred.urem.continue:
5479eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = phi <2 x i16> [ poison, [[VECTOR_BODY]] ], [ [[TMP9]], [[PRED_UREM_IF]] ]
5480eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = extractelement <2 x i1> [[TMP4]], i32 1
54817c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP11]], label [[PRED_UREM_IF3:%.*]], label [[PRED_UREM_CONTINUE4:%.*]]
5482da740492SFlorian Hahn; UNROLL-NO-IC:       pred.urem.if3:
5483eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = add i16 [[TMP1]], 1
5484eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = urem i16 [[B]], [[TMP12]]
5485eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = insertelement <2 x i16> [[TMP10]], i16 [[TMP13]], i32 1
54867c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br label [[PRED_UREM_CONTINUE4]]
5487da740492SFlorian Hahn; UNROLL-NO-IC:       pred.urem.continue4:
54887c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = phi <2 x i16> [ [[TMP10]], [[PRED_UREM_CONTINUE]] ], [ [[TMP14]], [[PRED_UREM_IF3]] ]
5489eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP16:%.*]] = extractelement <2 x i1> [[TMP5]], i32 0
54907c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP16]], label [[PRED_UREM_IF5:%.*]], label [[PRED_UREM_CONTINUE6:%.*]]
5491da740492SFlorian Hahn; UNROLL-NO-IC:       pred.urem.if5:
5492eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP17:%.*]] = add i16 [[TMP1]], 2
5493eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP18:%.*]] = urem i16 [[B]], [[TMP17]]
5494eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP19:%.*]] = insertelement <2 x i16> poison, i16 [[TMP18]], i32 0
54957c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br label [[PRED_UREM_CONTINUE6]]
5496da740492SFlorian Hahn; UNROLL-NO-IC:       pred.urem.continue6:
54977c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP20:%.*]] = phi <2 x i16> [ poison, [[PRED_UREM_CONTINUE4]] ], [ [[TMP19]], [[PRED_UREM_IF5]] ]
5498eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP21:%.*]] = extractelement <2 x i1> [[TMP5]], i32 1
54997c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP21]], label [[PRED_UREM_IF7:%.*]], label [[PRED_UREM_CONTINUE8]]
5500da740492SFlorian Hahn; UNROLL-NO-IC:       pred.urem.if7:
5501eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP22:%.*]] = add i16 [[TMP1]], 3
5502eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP23:%.*]] = urem i16 [[B]], [[TMP22]]
5503eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP24:%.*]] = insertelement <2 x i16> [[TMP20]], i16 [[TMP23]], i32 1
55047c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br label [[PRED_UREM_CONTINUE8]]
5505da740492SFlorian Hahn; UNROLL-NO-IC:       pred.urem.continue8:
55067c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP25:%.*]] = phi <2 x i16> [ [[TMP20]], [[PRED_UREM_CONTINUE6]] ], [ [[TMP24]], [[PRED_UREM_IF7]] ]
5507eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[PREDPHI:%.*]] = select <2 x i1> [[TMP2]], <2 x i16> zeroinitializer, <2 x i16> [[TMP15]]
55087c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[PREDPHI9:%.*]] = select <2 x i1> [[TMP3]], <2 x i16> zeroinitializer, <2 x i16> [[TMP25]]
5509eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP26:%.*]] = sext <2 x i16> [[PREDPHI]] to <2 x i32>
55107c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP27:%.*]] = sext <2 x i16> [[PREDPHI9]] to <2 x i32>
5511eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP28]] = or <2 x i32> [[VEC_PHI]], [[TMP26]]
55127c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP29]] = or <2 x i32> [[VEC_PHI1]], [[TMP27]]
5513eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
55147c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i16> [[STEP_ADD]], <i16 2, i16 2>
5515eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP30:%.*]] = icmp eq i32 [[INDEX_NEXT]], 20
5516eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP30]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP48:![0-9]+]]
5517eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
5518eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BIN_RDX:%.*]] = or <2 x i32> [[TMP29]], [[TMP28]]
5519eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP31:%.*]] = call i32 @llvm.vector.reduce.or.v2i32(<2 x i32> [[BIN_RDX]])
5520eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i32 20, 20
5521eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
5522eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
5523eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ 0, [[MIDDLE_BLOCK]] ], [ -20, [[ENTRY:%.*]] ]
5524eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ [[A]], [[ENTRY]] ], [ [[TMP31]], [[MIDDLE_BLOCK]] ]
5525eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_BODY:%.*]]
5526eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.body:
5527eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[FOR_INC:%.*]] ]
5528eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR0:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[VAR6:%.*]], [[FOR_INC]] ]
5529eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR1:%.*]] = trunc i32 [[I]] to i16
5530eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR2:%.*]] = icmp eq i16 [[VAR1]], 0
5531eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[VAR2]], label [[FOR_INC]], label [[FOR_COND:%.*]]
5532eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.cond:
5533eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR3:%.*]] = urem i16 [[B]], [[VAR1]]
5534eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[FOR_INC]]
5535eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.inc:
5536eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR4:%.*]] = phi i16 [ [[VAR3]], [[FOR_COND]] ], [ 0, [[FOR_BODY]] ]
5537eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR5:%.*]] = sext i16 [[VAR4]] to i32
5538eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR6]] = or i32 [[VAR0]], [[VAR5]]
5539eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[I_NEXT]] = add nsw i32 [[I]], 1
5540eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[COND:%.*]] = icmp eq i32 [[I_NEXT]], 0
5541eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[COND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP49:![0-9]+]]
5542eb052f6bSPhilip Reames; UNROLL-NO-IC:       for.end:
5543eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VAR7:%.*]] = phi i32 [ [[VAR6]], [[FOR_INC]] ], [ [[TMP31]], [[MIDDLE_BLOCK]] ]
5544eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret i32 [[VAR7]]
5545eb052f6bSPhilip Reames;
5546eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @PR32419(
5547eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
5548eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5549eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
5550e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 [[A:%.*]], i64 0
5551eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
5552eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
55537c080e46SNikita Popov; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_UREM_CONTINUE16:%.*]] ]
55547c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VEC_PHI:%.*]] = phi <4 x i32> [ [[TMP0]], [[VECTOR_PH]] ], [ [[TMP48:%.*]], [[PRED_UREM_CONTINUE16]] ]
55557c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VEC_PHI1:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP49:%.*]], [[PRED_UREM_CONTINUE16]] ]
55567c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND:%.*]] = phi <4 x i16> [ <i16 -20, i16 -19, i16 -18, i16 -17>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[PRED_UREM_CONTINUE16]] ]
5557eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = trunc i32 [[INDEX]] to i16
55587c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP2:%.*]] = icmp eq <4 x i16> [[VEC_IND]], zeroinitializer
55597c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP3:%.*]] = icmp eq <4 x i16> [[VEC_IND]], <i16 -4, i16 -4, i16 -4, i16 -4>
5560eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = xor <4 x i1> [[TMP2]], <i1 true, i1 true, i1 true, i1 true>
5561eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = xor <4 x i1> [[TMP3]], <i1 true, i1 true, i1 true, i1 true>
5562e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = extractelement <4 x i1> [[TMP4]], i64 0
5563eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP6]], label [[PRED_UREM_IF:%.*]], label [[PRED_UREM_CONTINUE:%.*]]
5564eb052f6bSPhilip Reames; INTERLEAVE:       pred.urem.if:
5565eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP7:%.*]] = add i16 [[TMP1]], -20
5566eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP8:%.*]] = urem i16 [[B:%.*]], [[TMP7]]
5567e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP9:%.*]] = insertelement <4 x i16> poison, i16 [[TMP8]], i64 0
5568eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[PRED_UREM_CONTINUE]]
5569eb052f6bSPhilip Reames; INTERLEAVE:       pred.urem.continue:
5570eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP10:%.*]] = phi <4 x i16> [ poison, [[VECTOR_BODY]] ], [ [[TMP9]], [[PRED_UREM_IF]] ]
5571e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP11:%.*]] = extractelement <4 x i1> [[TMP4]], i64 1
55727c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP11]], label [[PRED_UREM_IF3:%.*]], label [[PRED_UREM_CONTINUE4:%.*]]
5573da740492SFlorian Hahn; INTERLEAVE:       pred.urem.if3:
5574eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP12:%.*]] = add i16 [[TMP1]], -19
5575eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP13:%.*]] = urem i16 [[B]], [[TMP12]]
5576e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP14:%.*]] = insertelement <4 x i16> [[TMP10]], i16 [[TMP13]], i64 1
55777c080e46SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UREM_CONTINUE4]]
5578da740492SFlorian Hahn; INTERLEAVE:       pred.urem.continue4:
55797c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP15:%.*]] = phi <4 x i16> [ [[TMP10]], [[PRED_UREM_CONTINUE]] ], [ [[TMP14]], [[PRED_UREM_IF3]] ]
5580e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP16:%.*]] = extractelement <4 x i1> [[TMP4]], i64 2
55817c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP16]], label [[PRED_UREM_IF5:%.*]], label [[PRED_UREM_CONTINUE6:%.*]]
5582da740492SFlorian Hahn; INTERLEAVE:       pred.urem.if5:
5583eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP17:%.*]] = add i16 [[TMP1]], -18
5584eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP18:%.*]] = urem i16 [[B]], [[TMP17]]
5585e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP19:%.*]] = insertelement <4 x i16> [[TMP15]], i16 [[TMP18]], i64 2
55867c080e46SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UREM_CONTINUE6]]
5587da740492SFlorian Hahn; INTERLEAVE:       pred.urem.continue6:
55887c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP20:%.*]] = phi <4 x i16> [ [[TMP15]], [[PRED_UREM_CONTINUE4]] ], [ [[TMP19]], [[PRED_UREM_IF5]] ]
5589e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP21:%.*]] = extractelement <4 x i1> [[TMP4]], i64 3
55907c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP21]], label [[PRED_UREM_IF7:%.*]], label [[PRED_UREM_CONTINUE8:%.*]]
5591da740492SFlorian Hahn; INTERLEAVE:       pred.urem.if7:
5592eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP22:%.*]] = add i16 [[TMP1]], -17
5593eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP23:%.*]] = urem i16 [[B]], [[TMP22]]
5594e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP24:%.*]] = insertelement <4 x i16> [[TMP20]], i16 [[TMP23]], i64 3
55957c080e46SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UREM_CONTINUE8]]
5596da740492SFlorian Hahn; INTERLEAVE:       pred.urem.continue8:
55977c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP25:%.*]] = phi <4 x i16> [ [[TMP20]], [[PRED_UREM_CONTINUE6]] ], [ [[TMP24]], [[PRED_UREM_IF7]] ]
5598e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP26:%.*]] = extractelement <4 x i1> [[TMP5]], i64 0
55997c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP26]], label [[PRED_UREM_IF9:%.*]], label [[PRED_UREM_CONTINUE10:%.*]]
5600da740492SFlorian Hahn; INTERLEAVE:       pred.urem.if9:
5601eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP27:%.*]] = add i16 [[TMP1]], -16
5602eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP28:%.*]] = urem i16 [[B]], [[TMP27]]
5603e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP29:%.*]] = insertelement <4 x i16> poison, i16 [[TMP28]], i64 0
56047c080e46SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UREM_CONTINUE10]]
5605da740492SFlorian Hahn; INTERLEAVE:       pred.urem.continue10:
56067c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP30:%.*]] = phi <4 x i16> [ poison, [[PRED_UREM_CONTINUE8]] ], [ [[TMP29]], [[PRED_UREM_IF9]] ]
5607e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP31:%.*]] = extractelement <4 x i1> [[TMP5]], i64 1
56087c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP31]], label [[PRED_UREM_IF11:%.*]], label [[PRED_UREM_CONTINUE12:%.*]]
5609da740492SFlorian Hahn; INTERLEAVE:       pred.urem.if11:
5610eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP32:%.*]] = add i16 [[TMP1]], -15
5611eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP33:%.*]] = urem i16 [[B]], [[TMP32]]
5612e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP34:%.*]] = insertelement <4 x i16> [[TMP30]], i16 [[TMP33]], i64 1
56137c080e46SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UREM_CONTINUE12]]
5614da740492SFlorian Hahn; INTERLEAVE:       pred.urem.continue12:
56157c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP35:%.*]] = phi <4 x i16> [ [[TMP30]], [[PRED_UREM_CONTINUE10]] ], [ [[TMP34]], [[PRED_UREM_IF11]] ]
5616e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP36:%.*]] = extractelement <4 x i1> [[TMP5]], i64 2
56177c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP36]], label [[PRED_UREM_IF13:%.*]], label [[PRED_UREM_CONTINUE14:%.*]]
5618da740492SFlorian Hahn; INTERLEAVE:       pred.urem.if13:
5619eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP37:%.*]] = add i16 [[TMP1]], -14
5620eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP38:%.*]] = urem i16 [[B]], [[TMP37]]
5621e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP39:%.*]] = insertelement <4 x i16> [[TMP35]], i16 [[TMP38]], i64 2
56227c080e46SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UREM_CONTINUE14]]
5623da740492SFlorian Hahn; INTERLEAVE:       pred.urem.continue14:
56247c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP40:%.*]] = phi <4 x i16> [ [[TMP35]], [[PRED_UREM_CONTINUE12]] ], [ [[TMP39]], [[PRED_UREM_IF13]] ]
5625e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP41:%.*]] = extractelement <4 x i1> [[TMP5]], i64 3
56267c080e46SNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP41]], label [[PRED_UREM_IF15:%.*]], label [[PRED_UREM_CONTINUE16]]
5627da740492SFlorian Hahn; INTERLEAVE:       pred.urem.if15:
5628eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP42:%.*]] = add i16 [[TMP1]], -13
5629eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP43:%.*]] = urem i16 [[B]], [[TMP42]]
5630e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[TMP44:%.*]] = insertelement <4 x i16> [[TMP40]], i16 [[TMP43]], i64 3
56317c080e46SNikita Popov; INTERLEAVE-NEXT:    br label [[PRED_UREM_CONTINUE16]]
5632da740492SFlorian Hahn; INTERLEAVE:       pred.urem.continue16:
56337c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP45:%.*]] = phi <4 x i16> [ [[TMP40]], [[PRED_UREM_CONTINUE14]] ], [ [[TMP44]], [[PRED_UREM_IF15]] ]
5634eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[PREDPHI:%.*]] = select <4 x i1> [[TMP2]], <4 x i16> zeroinitializer, <4 x i16> [[TMP25]]
56357c080e46SNikita Popov; INTERLEAVE-NEXT:    [[PREDPHI17:%.*]] = select <4 x i1> [[TMP3]], <4 x i16> zeroinitializer, <4 x i16> [[TMP45]]
5636eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP46:%.*]] = sext <4 x i16> [[PREDPHI]] to <4 x i32>
56377c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP47:%.*]] = sext <4 x i16> [[PREDPHI17]] to <4 x i32>
5638eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP48]] = or <4 x i32> [[VEC_PHI]], [[TMP46]]
56397c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP49]] = or <4 x i32> [[VEC_PHI1]], [[TMP47]]
5640eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8
56417c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND_NEXT]] = add <4 x i16> [[VEC_IND]], <i16 8, i16 8, i16 8, i16 8>
5642eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP50:%.*]] = icmp eq i32 [[INDEX_NEXT]], 16
5643eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP50]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP48:![0-9]+]]
5644eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
5645eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BIN_RDX:%.*]] = or <4 x i32> [[TMP49]], [[TMP48]]
5646eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP51:%.*]] = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> [[BIN_RDX]])
5647eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 false, label [[FOR_END:%.*]], label [[SCALAR_PH]]
5648eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
5649eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ -4, [[MIDDLE_BLOCK]] ], [ -20, [[ENTRY:%.*]] ]
5650eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP51]], [[MIDDLE_BLOCK]] ], [ [[A]], [[ENTRY]] ]
5651eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_BODY:%.*]]
5652eb052f6bSPhilip Reames; INTERLEAVE:       for.body:
5653eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[FOR_INC:%.*]] ]
5654eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR0:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[VAR6:%.*]], [[FOR_INC]] ]
5655eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR1:%.*]] = trunc i32 [[I]] to i16
5656eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR2:%.*]] = icmp eq i16 [[VAR1]], 0
5657eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[VAR2]], label [[FOR_INC]], label [[FOR_COND:%.*]]
5658eb052f6bSPhilip Reames; INTERLEAVE:       for.cond:
5659eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR3:%.*]] = urem i16 [[B]], [[VAR1]]
5660eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[FOR_INC]]
5661eb052f6bSPhilip Reames; INTERLEAVE:       for.inc:
5662eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR4:%.*]] = phi i16 [ [[VAR3]], [[FOR_COND]] ], [ 0, [[FOR_BODY]] ]
5663eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR5:%.*]] = sext i16 [[VAR4]] to i32
5664eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR6]] = or i32 [[VAR0]], [[VAR5]]
5665eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[I_NEXT]] = add nsw i32 [[I]], 1
5666eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[COND:%.*]] = icmp eq i32 [[I_NEXT]], 0
5667eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[COND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP49:![0-9]+]]
5668eb052f6bSPhilip Reames; INTERLEAVE:       for.end:
5669eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VAR7:%.*]] = phi i32 [ [[VAR6]], [[FOR_INC]] ], [ [[TMP51]], [[MIDDLE_BLOCK]] ]
5670eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret i32 [[VAR7]]
5671eb052f6bSPhilip Reames;
5672cee313d2SEric Christopherentry:
5673cee313d2SEric Christopher  br label %for.body
5674cee313d2SEric Christopher
5675cee313d2SEric Christopherfor.body:
5676cee313d2SEric Christopher  %i = phi i32 [ -20, %entry ], [ %i.next, %for.inc ]
5677eb052f6bSPhilip Reames  %var0 = phi i32 [ %a, %entry ], [ %var6, %for.inc ]
5678eb052f6bSPhilip Reames  %var1 = trunc i32 %i to i16
5679eb052f6bSPhilip Reames  %var2 = icmp eq i16 %var1, 0
5680eb052f6bSPhilip Reames  br i1 %var2, label %for.inc, label %for.cond
5681cee313d2SEric Christopher
5682cee313d2SEric Christopherfor.cond:
5683eb052f6bSPhilip Reames  %var3 = urem i16 %b, %var1
5684cee313d2SEric Christopher  br label %for.inc
5685cee313d2SEric Christopher
5686cee313d2SEric Christopherfor.inc:
5687eb052f6bSPhilip Reames  %var4 = phi i16 [ %var3, %for.cond ], [ 0, %for.body ]
5688eb052f6bSPhilip Reames  %var5 = sext i16 %var4 to i32
5689eb052f6bSPhilip Reames  %var6 = or i32 %var0, %var5
5690cee313d2SEric Christopher  %i.next = add nsw i32 %i, 1
5691cee313d2SEric Christopher  %cond = icmp eq i32 %i.next, 0
5692cee313d2SEric Christopher  br i1 %cond, label %for.end, label %for.body
5693cee313d2SEric Christopher
5694cee313d2SEric Christopherfor.end:
5695eb052f6bSPhilip Reames  %var7 = phi i32 [ %var6, %for.inc ]
5696eb052f6bSPhilip Reames  ret i32 %var7
5697cee313d2SEric Christopher}
5698cee313d2SEric Christopher
5699cee313d2SEric Christopher; Ensure that the shuffle vector for first order recurrence is inserted
5700cee313d2SEric Christopher; correctly after all the phis. These new phis correspond to new IVs
5701e3bfb6a1SFlorian Hahn; that are generated by optimizing non-free truncs of IVs to IVs themselves.
5702e3bfb6a1SFlorian Hahn; This also ensures the first-order recurrence splice recipe is placed
5703e3bfb6a1SFlorian Hahn; correctly if it is fed by an induction.
5704cee313d2SEric Christopherdefine i64 @trunc_with_first_order_recurrence() {
5705eb052f6bSPhilip Reames; CHECK-LABEL: @trunc_with_first_order_recurrence(
5706eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
5707eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5708eb052f6bSPhilip Reames; CHECK:       vector.ph:
5709eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
5710eb052f6bSPhilip Reames; CHECK:       vector.body:
5711eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
5712eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP10:%.*]], [[VECTOR_BODY]] ]
57137c080e46SNikita Popov; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 1, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
57147c080e46SNikita Popov; CHECK-NEXT:    [[VECTOR_RECUR:%.*]] = phi <2 x i32> [ <i32 poison, i32 42>, [[VECTOR_PH]] ], [ [[VEC_IND2:%.*]], [[VECTOR_BODY]] ]
57157c080e46SNikita Popov; CHECK-NEXT:    [[VEC_IND2]] = phi <2 x i32> [ <i32 1, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT3:%.*]], [[VECTOR_BODY]] ]
57167c080e46SNikita Popov; CHECK-NEXT:    [[VEC_IND4:%.*]] = phi <2 x i32> [ <i32 1, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT5:%.*]], [[VECTOR_BODY]] ]
57177c080e46SNikita Popov; CHECK-NEXT:    [[TMP0:%.*]] = shufflevector <2 x i32> [[VECTOR_RECUR]], <2 x i32> [[VEC_IND2]], <2 x i32> <i32 1, i32 2>
57187c080e46SNikita Popov; CHECK-NEXT:    [[TMP1:%.*]] = mul <2 x i32> [[VEC_IND]], [[VEC_IND2]]
5719eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = add <2 x i32> [[TMP1]], <i32 42, i32 42>
57207c080e46SNikita Popov; CHECK-NEXT:    [[TMP3:%.*]] = add <2 x i32> [[TMP0]], [[VEC_IND2]]
5721eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = add <2 x i32> [[TMP3]], [[TMP2]]
5722eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP5:%.*]] = sext <2 x i32> [[TMP4]] to <2 x i64>
5723eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP6:%.*]] = add <2 x i64> [[VEC_PHI]], [[TMP5]]
57247c080e46SNikita Popov; CHECK-NEXT:    [[TMP7:%.*]] = shl <2 x i32> [[VEC_IND4]], <i32 1, i32 1>
5725eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP8:%.*]] = add <2 x i32> [[TMP2]], [[TMP7]]
5726eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP9:%.*]] = sext <2 x i32> [[TMP8]] to <2 x i64>
5727eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP10]] = add <2 x i64> [[TMP6]], [[TMP9]]
5728eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
57297c080e46SNikita Popov; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
5730eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_IND_NEXT3]] = add <2 x i32> [[VEC_IND2]], <i32 2, i32 2>
5731eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_IND_NEXT5]] = add <2 x i32> [[VEC_IND4]], <i32 2, i32 2>
5732eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], 112
5733eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[TMP11]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP50:![0-9]+]]
5734eb052f6bSPhilip Reames; CHECK:       middle.block:
5735eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP12:%.*]] = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> [[TMP10]])
5736eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 113, 112
57377c080e46SNikita Popov; CHECK-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <2 x i32> [[VEC_IND2]], i32 1
57387c080e46SNikita Popov; CHECK-NEXT:    [[VECTOR_RECUR_EXTRACT_FOR_PHI:%.*]] = extractelement <2 x i32> [[VEC_IND2]], i32 0
5739eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
5740eb052f6bSPhilip Reames; CHECK:       scalar.ph:
5741eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 42, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
5742eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 113, [[MIDDLE_BLOCK]] ], [ 1, [[ENTRY]] ]
5743eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ 113, [[MIDDLE_BLOCK]] ], [ 1, [[ENTRY]] ]
5744eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[TMP12]], [[MIDDLE_BLOCK]] ]
5745eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[LOOP:%.*]]
5746eb052f6bSPhilip Reames; CHECK:       exit:
5747eb052f6bSPhilip Reames; CHECK-NEXT:    [[DOTLCSSA:%.*]] = phi i64 [ [[C23:%.*]], [[LOOP]] ], [ [[TMP12]], [[MIDDLE_BLOCK]] ]
5748eb052f6bSPhilip Reames; CHECK-NEXT:    ret i64 [[DOTLCSSA]]
5749eb052f6bSPhilip Reames; CHECK:       loop:
5750eb052f6bSPhilip Reames; CHECK-NEXT:    [[C5:%.*]] = phi i64 [ [[C23]], [[LOOP]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
5751eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
5752eb052f6bSPhilip Reames; CHECK-NEXT:    [[X:%.*]] = phi i32 [ [[C24:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
5753eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[C6:%.*]], [[LOOP]] ], [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ]
5754eb052f6bSPhilip Reames; CHECK-NEXT:    [[C6]] = trunc i64 [[INDVARS_IV]] to i32
5755eb052f6bSPhilip Reames; CHECK-NEXT:    [[C8:%.*]] = mul i32 [[X]], [[C6]]
5756eb052f6bSPhilip Reames; CHECK-NEXT:    [[C9:%.*]] = add i32 [[C8]], 42
5757eb052f6bSPhilip Reames; CHECK-NEXT:    [[C10:%.*]] = add i32 [[SCALAR_RECUR]], [[C6]]
5758eb052f6bSPhilip Reames; CHECK-NEXT:    [[C11:%.*]] = add i32 [[C10]], [[C9]]
5759eb052f6bSPhilip Reames; CHECK-NEXT:    [[C12:%.*]] = sext i32 [[C11]] to i64
5760eb052f6bSPhilip Reames; CHECK-NEXT:    [[C13:%.*]] = add i64 [[C5]], [[C12]]
5761eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDVARS_IV_TR:%.*]] = trunc i64 [[INDVARS_IV]] to i32
5762eb052f6bSPhilip Reames; CHECK-NEXT:    [[C14:%.*]] = shl i32 [[INDVARS_IV_TR]], 1
5763eb052f6bSPhilip Reames; CHECK-NEXT:    [[C15:%.*]] = add i32 [[C9]], [[C14]]
5764eb052f6bSPhilip Reames; CHECK-NEXT:    [[C16:%.*]] = sext i32 [[C15]] to i64
5765eb052f6bSPhilip Reames; CHECK-NEXT:    [[C23]] = add i64 [[C13]], [[C16]]
5766eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
5767eb052f6bSPhilip Reames; CHECK-NEXT:    [[C24]] = add nuw nsw i32 [[X]], 1
5768eb052f6bSPhilip Reames; CHECK-NEXT:    [[EXITCOND_I:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 114
5769eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND_I]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP51:![0-9]+]]
5770eb052f6bSPhilip Reames;
5771eb052f6bSPhilip Reames; IND-LABEL: @trunc_with_first_order_recurrence(
5772eb052f6bSPhilip Reames; IND-NEXT:  entry:
5773eb052f6bSPhilip Reames; IND-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5774eb052f6bSPhilip Reames; IND:       vector.ph:
5775eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
5776eb052f6bSPhilip Reames; IND:       vector.body:
5777eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
5778eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP10:%.*]], [[VECTOR_BODY]] ]
57797c080e46SNikita Popov; IND-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 1, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
57807c080e46SNikita Popov; IND-NEXT:    [[VECTOR_RECUR:%.*]] = phi <2 x i32> [ <i32 poison, i32 42>, [[VECTOR_PH]] ], [ [[VEC_IND2:%.*]], [[VECTOR_BODY]] ]
57817c080e46SNikita Popov; IND-NEXT:    [[VEC_IND2]] = phi <2 x i32> [ <i32 1, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT3:%.*]], [[VECTOR_BODY]] ]
57827c080e46SNikita Popov; IND-NEXT:    [[VEC_IND4:%.*]] = phi <2 x i32> [ <i32 1, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT5:%.*]], [[VECTOR_BODY]] ]
57837c080e46SNikita Popov; IND-NEXT:    [[TMP0:%.*]] = shufflevector <2 x i32> [[VECTOR_RECUR]], <2 x i32> [[VEC_IND2]], <2 x i32> <i32 1, i32 2>
57847c080e46SNikita Popov; IND-NEXT:    [[TMP1:%.*]] = mul <2 x i32> [[VEC_IND]], [[VEC_IND2]]
5785eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = add <2 x i32> [[TMP1]], <i32 42, i32 42>
57867c080e46SNikita Popov; IND-NEXT:    [[TMP3:%.*]] = add <2 x i32> [[TMP0]], [[VEC_IND2]]
5787eb052f6bSPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = add <2 x i32> [[TMP3]], [[TMP2]]
5788eb052f6bSPhilip Reames; IND-NEXT:    [[TMP5:%.*]] = sext <2 x i32> [[TMP4]] to <2 x i64>
5789eb052f6bSPhilip Reames; IND-NEXT:    [[TMP6:%.*]] = add <2 x i64> [[VEC_PHI]], [[TMP5]]
57907c080e46SNikita Popov; IND-NEXT:    [[TMP7:%.*]] = shl <2 x i32> [[VEC_IND4]], <i32 1, i32 1>
5791eb052f6bSPhilip Reames; IND-NEXT:    [[TMP8:%.*]] = add <2 x i32> [[TMP2]], [[TMP7]]
5792eb052f6bSPhilip Reames; IND-NEXT:    [[TMP9:%.*]] = sext <2 x i32> [[TMP8]] to <2 x i64>
5793eb052f6bSPhilip Reames; IND-NEXT:    [[TMP10]] = add <2 x i64> [[TMP6]], [[TMP9]]
5794eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
57957c080e46SNikita Popov; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
5796eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_IND_NEXT3]] = add <2 x i32> [[VEC_IND2]], <i32 2, i32 2>
5797eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_IND_NEXT5]] = add <2 x i32> [[VEC_IND4]], <i32 2, i32 2>
5798eb052f6bSPhilip Reames; IND-NEXT:    [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], 112
5799eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP11]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP50:![0-9]+]]
5800eb052f6bSPhilip Reames; IND:       middle.block:
5801eb052f6bSPhilip Reames; IND-NEXT:    [[TMP12:%.*]] = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> [[TMP10]])
58027c080e46SNikita Popov; IND-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <2 x i32> [[VEC_IND2]], i64 1
5803eb052f6bSPhilip Reames; IND-NEXT:    br i1 false, label [[EXIT:%.*]], label [[SCALAR_PH]]
5804eb052f6bSPhilip Reames; IND:       scalar.ph:
5805eb052f6bSPhilip Reames; IND-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 42, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
5806eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 1, [[ENTRY]] ], [ 113, [[MIDDLE_BLOCK]] ]
5807eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ 113, [[MIDDLE_BLOCK]] ]
5808eb052f6bSPhilip Reames; IND-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[TMP12]], [[MIDDLE_BLOCK]] ]
5809eb052f6bSPhilip Reames; IND-NEXT:    br label [[LOOP:%.*]]
5810eb052f6bSPhilip Reames; IND:       exit:
5811eb052f6bSPhilip Reames; IND-NEXT:    [[DOTLCSSA:%.*]] = phi i64 [ [[C23:%.*]], [[LOOP]] ], [ [[TMP12]], [[MIDDLE_BLOCK]] ]
5812eb052f6bSPhilip Reames; IND-NEXT:    ret i64 [[DOTLCSSA]]
5813eb052f6bSPhilip Reames; IND:       loop:
5814eb052f6bSPhilip Reames; IND-NEXT:    [[C5:%.*]] = phi i64 [ [[C23]], [[LOOP]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
5815eb052f6bSPhilip Reames; IND-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
5816eb052f6bSPhilip Reames; IND-NEXT:    [[X:%.*]] = phi i32 [ [[C24:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
5817eb052f6bSPhilip Reames; IND-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[C6:%.*]], [[LOOP]] ], [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ]
5818eb052f6bSPhilip Reames; IND-NEXT:    [[C6]] = trunc i64 [[INDVARS_IV]] to i32
5819eb052f6bSPhilip Reames; IND-NEXT:    [[C8:%.*]] = mul i32 [[X]], [[C6]]
5820eb052f6bSPhilip Reames; IND-NEXT:    [[C9:%.*]] = add i32 [[C8]], 42
5821eb052f6bSPhilip Reames; IND-NEXT:    [[C10:%.*]] = add i32 [[SCALAR_RECUR]], [[C6]]
5822eb052f6bSPhilip Reames; IND-NEXT:    [[C11:%.*]] = add i32 [[C10]], [[C9]]
5823eb052f6bSPhilip Reames; IND-NEXT:    [[C12:%.*]] = sext i32 [[C11]] to i64
5824eb052f6bSPhilip Reames; IND-NEXT:    [[C13:%.*]] = add i64 [[C5]], [[C12]]
5825eb052f6bSPhilip Reames; IND-NEXT:    [[INDVARS_IV_TR:%.*]] = trunc i64 [[INDVARS_IV]] to i32
5826eb052f6bSPhilip Reames; IND-NEXT:    [[C14:%.*]] = shl i32 [[INDVARS_IV_TR]], 1
5827eb052f6bSPhilip Reames; IND-NEXT:    [[C15:%.*]] = add i32 [[C9]], [[C14]]
5828eb052f6bSPhilip Reames; IND-NEXT:    [[C16:%.*]] = sext i32 [[C15]] to i64
5829eb052f6bSPhilip Reames; IND-NEXT:    [[C23]] = add i64 [[C13]], [[C16]]
5830eb052f6bSPhilip Reames; IND-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
5831eb052f6bSPhilip Reames; IND-NEXT:    [[C24]] = add nuw nsw i32 [[X]], 1
5832eb052f6bSPhilip Reames; IND-NEXT:    [[EXITCOND_I:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 114
5833eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[EXITCOND_I]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP51:![0-9]+]]
5834eb052f6bSPhilip Reames;
5835eb052f6bSPhilip Reames; UNROLL-LABEL: @trunc_with_first_order_recurrence(
5836eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
5837eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5838eb052f6bSPhilip Reames; UNROLL:       vector.ph:
5839eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
5840eb052f6bSPhilip Reames; UNROLL:       vector.body:
5841eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
5842eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP20:%.*]], [[VECTOR_BODY]] ]
5843eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_PHI2:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP21:%.*]], [[VECTOR_BODY]] ]
58447c080e46SNikita Popov; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 1, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
58457c080e46SNikita Popov; UNROLL-NEXT:    [[VECTOR_RECUR:%.*]] = phi <2 x i32> [ <i32 poison, i32 42>, [[VECTOR_PH]] ], [ [[STEP_ADD5:%.*]], [[VECTOR_BODY]] ]
5846eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND4:%.*]] = phi <2 x i32> [ <i32 1, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT7:%.*]], [[VECTOR_BODY]] ]
5847eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND8:%.*]] = phi <2 x i32> [ <i32 1, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT11:%.*]], [[VECTOR_BODY]] ]
58487c080e46SNikita Popov; UNROLL-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
58497c080e46SNikita Popov; UNROLL-NEXT:    [[STEP_ADD5]] = add <2 x i32> [[VEC_IND4]], <i32 2, i32 2>
58507c080e46SNikita Popov; UNROLL-NEXT:    [[TMP0:%.*]] = shufflevector <2 x i32> [[VECTOR_RECUR]], <2 x i32> [[VEC_IND4]], <2 x i32> <i32 1, i32 2>
58517c080e46SNikita Popov; UNROLL-NEXT:    [[TMP1:%.*]] = shufflevector <2 x i32> [[VEC_IND4]], <2 x i32> [[STEP_ADD5]], <2 x i32> <i32 1, i32 2>
58527c080e46SNikita Popov; UNROLL-NEXT:    [[TMP2:%.*]] = mul <2 x i32> [[VEC_IND]], [[VEC_IND4]]
58537c080e46SNikita Popov; UNROLL-NEXT:    [[TMP3:%.*]] = mul <2 x i32> [[STEP_ADD]], [[STEP_ADD5]]
5854eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP4:%.*]] = add <2 x i32> [[TMP2]], <i32 42, i32 42>
5855eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = add <2 x i32> [[TMP3]], <i32 42, i32 42>
58567c080e46SNikita Popov; UNROLL-NEXT:    [[TMP6:%.*]] = add <2 x i32> [[TMP0]], [[VEC_IND4]]
58577c080e46SNikita Popov; UNROLL-NEXT:    [[TMP7:%.*]] = add <2 x i32> [[TMP1]], [[STEP_ADD5]]
5858eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP8:%.*]] = add <2 x i32> [[TMP6]], [[TMP4]]
5859eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP9:%.*]] = add <2 x i32> [[TMP7]], [[TMP5]]
5860eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP10:%.*]] = sext <2 x i32> [[TMP8]] to <2 x i64>
5861eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP11:%.*]] = sext <2 x i32> [[TMP9]] to <2 x i64>
5862eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP12:%.*]] = add <2 x i64> [[VEC_PHI]], [[TMP10]]
5863eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP13:%.*]] = add <2 x i64> [[VEC_PHI2]], [[TMP11]]
58647c080e46SNikita Popov; UNROLL-NEXT:    [[TMP14:%.*]] = shl <2 x i32> [[VEC_IND8]], <i32 1, i32 1>
58657c080e46SNikita Popov; UNROLL-NEXT:    [[STEP_ADD9:%.*]] = shl <2 x i32> [[VEC_IND8]], <i32 1, i32 1>
58667c080e46SNikita Popov; UNROLL-NEXT:    [[TMP15:%.*]] = add <2 x i32> [[STEP_ADD9]], <i32 4, i32 4>
5867eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP16:%.*]] = add <2 x i32> [[TMP4]], [[TMP14]]
5868eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP17:%.*]] = add <2 x i32> [[TMP5]], [[TMP15]]
5869eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP18:%.*]] = sext <2 x i32> [[TMP16]] to <2 x i64>
5870eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP19:%.*]] = sext <2 x i32> [[TMP17]] to <2 x i64>
5871eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP20]] = add <2 x i64> [[TMP12]], [[TMP18]]
5872eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP21]] = add <2 x i64> [[TMP13]], [[TMP19]]
5873eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
58747c080e46SNikita Popov; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 4, i32 4>
5875eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND_NEXT7]] = add <2 x i32> [[VEC_IND4]], <i32 4, i32 4>
5876eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND_NEXT11]] = add <2 x i32> [[VEC_IND8]], <i32 4, i32 4>
5877eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP22:%.*]] = icmp eq i64 [[INDEX_NEXT]], 112
5878eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP22]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP50:![0-9]+]]
5879eb052f6bSPhilip Reames; UNROLL:       middle.block:
5880eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BIN_RDX:%.*]] = add <2 x i64> [[TMP21]], [[TMP20]]
5881eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP23:%.*]] = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> [[BIN_RDX]])
58827c080e46SNikita Popov; UNROLL-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <2 x i32> [[STEP_ADD5]], i64 1
5883eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 false, label [[EXIT:%.*]], label [[SCALAR_PH]]
5884eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
5885eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 42, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
5886eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 1, [[ENTRY]] ], [ 113, [[MIDDLE_BLOCK]] ]
5887eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ 113, [[MIDDLE_BLOCK]] ]
5888eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[TMP23]], [[MIDDLE_BLOCK]] ]
5889eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[LOOP:%.*]]
5890eb052f6bSPhilip Reames; UNROLL:       exit:
5891eb052f6bSPhilip Reames; UNROLL-NEXT:    [[DOTLCSSA:%.*]] = phi i64 [ [[C23:%.*]], [[LOOP]] ], [ [[TMP23]], [[MIDDLE_BLOCK]] ]
5892eb052f6bSPhilip Reames; UNROLL-NEXT:    ret i64 [[DOTLCSSA]]
5893eb052f6bSPhilip Reames; UNROLL:       loop:
5894eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C5:%.*]] = phi i64 [ [[C23]], [[LOOP]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
5895eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
5896eb052f6bSPhilip Reames; UNROLL-NEXT:    [[X:%.*]] = phi i32 [ [[C24:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
5897eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[C6:%.*]], [[LOOP]] ], [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ]
5898eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C6]] = trunc i64 [[INDVARS_IV]] to i32
5899eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C8:%.*]] = mul i32 [[X]], [[C6]]
5900eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C9:%.*]] = add i32 [[C8]], 42
5901eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C10:%.*]] = add i32 [[SCALAR_RECUR]], [[C6]]
5902eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C11:%.*]] = add i32 [[C10]], [[C9]]
5903eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C12:%.*]] = sext i32 [[C11]] to i64
5904eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C13:%.*]] = add i64 [[C5]], [[C12]]
5905eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDVARS_IV_TR:%.*]] = trunc i64 [[INDVARS_IV]] to i32
5906eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C14:%.*]] = shl i32 [[INDVARS_IV_TR]], 1
5907eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C15:%.*]] = add i32 [[C9]], [[C14]]
5908eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C16:%.*]] = sext i32 [[C15]] to i64
5909eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C23]] = add i64 [[C13]], [[C16]]
5910eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
5911eb052f6bSPhilip Reames; UNROLL-NEXT:    [[C24]] = add nuw nsw i32 [[X]], 1
5912eb052f6bSPhilip Reames; UNROLL-NEXT:    [[EXITCOND_I:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 114
5913eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[EXITCOND_I]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP51:![0-9]+]]
5914eb052f6bSPhilip Reames;
5915eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @trunc_with_first_order_recurrence(
5916eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
5917eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
5918eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
5919eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
5920eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
5921eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
5922eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_PHI:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP20:%.*]], [[VECTOR_BODY]] ]
5923eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_PHI2:%.*]] = phi <2 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP21:%.*]], [[VECTOR_BODY]] ]
59247c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 1, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
59257c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VECTOR_RECUR:%.*]] = phi <2 x i32> [ <i32 poison, i32 42>, [[VECTOR_PH]] ], [ [[STEP_ADD5:%.*]], [[VECTOR_BODY]] ]
5926eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND4:%.*]] = phi <2 x i32> [ <i32 1, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT7:%.*]], [[VECTOR_BODY]] ]
5927eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND8:%.*]] = phi <2 x i32> [ <i32 1, i32 2>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT11:%.*]], [[VECTOR_BODY]] ]
59287c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[STEP_ADD:%.*]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
59297c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[STEP_ADD5]] = add <2 x i32> [[VEC_IND4]], <i32 2, i32 2>
59307c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[STEP_ADD9:%.*]] = add <2 x i32> [[VEC_IND8]], <i32 2, i32 2>
59317c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = shufflevector <2 x i32> [[VECTOR_RECUR]], <2 x i32> [[VEC_IND4]], <2 x i32> <i32 1, i32 2>
59327c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = shufflevector <2 x i32> [[VEC_IND4]], <2 x i32> [[STEP_ADD5]], <2 x i32> <i32 1, i32 2>
59337c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = mul <2 x i32> [[VEC_IND]], [[VEC_IND4]]
59347c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = mul <2 x i32> [[STEP_ADD]], [[STEP_ADD5]]
5935eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = add <2 x i32> [[TMP2]], <i32 42, i32 42>
5936eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = add <2 x i32> [[TMP3]], <i32 42, i32 42>
59377c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = add <2 x i32> [[TMP0]], [[VEC_IND4]]
59387c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = add <2 x i32> [[TMP1]], [[STEP_ADD5]]
5939eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = add <2 x i32> [[TMP6]], [[TMP4]]
5940eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = add <2 x i32> [[TMP7]], [[TMP5]]
5941eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = sext <2 x i32> [[TMP8]] to <2 x i64>
5942eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = sext <2 x i32> [[TMP9]] to <2 x i64>
5943eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = add <2 x i64> [[VEC_PHI]], [[TMP10]]
5944eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = add <2 x i64> [[VEC_PHI2]], [[TMP11]]
59457c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = shl <2 x i32> [[VEC_IND8]], <i32 1, i32 1>
59467c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = shl <2 x i32> [[STEP_ADD9]], <i32 1, i32 1>
5947eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP16:%.*]] = add <2 x i32> [[TMP4]], [[TMP14]]
5948eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP17:%.*]] = add <2 x i32> [[TMP5]], [[TMP15]]
5949eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP18:%.*]] = sext <2 x i32> [[TMP16]] to <2 x i64>
5950eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP19:%.*]] = sext <2 x i32> [[TMP17]] to <2 x i64>
5951eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP20]] = add <2 x i64> [[TMP12]], [[TMP18]]
5952eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP21]] = add <2 x i64> [[TMP13]], [[TMP19]]
5953eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
59547c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[STEP_ADD]], <i32 2, i32 2>
5955eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT7]] = add <2 x i32> [[STEP_ADD5]], <i32 2, i32 2>
5956eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT11]] = add <2 x i32> [[STEP_ADD9]], <i32 2, i32 2>
5957eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP22:%.*]] = icmp eq i64 [[INDEX_NEXT]], 112
5958eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[TMP22]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP50:![0-9]+]]
5959eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
5960eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BIN_RDX:%.*]] = add <2 x i64> [[TMP21]], [[TMP20]]
5961eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP23:%.*]] = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> [[BIN_RDX]])
5962eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i64 113, 112
59637c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <2 x i32> [[STEP_ADD5]], i32 1
59647c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VECTOR_RECUR_EXTRACT_FOR_PHI:%.*]] = extractelement <2 x i32> [[STEP_ADD5]], i32 0
5965eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
5966eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
5967eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 42, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
5968eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 113, [[MIDDLE_BLOCK]] ], [ 1, [[ENTRY]] ]
5969eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ 113, [[MIDDLE_BLOCK]] ], [ 1, [[ENTRY]] ]
5970eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[TMP23]], [[MIDDLE_BLOCK]] ]
5971eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[LOOP:%.*]]
5972eb052f6bSPhilip Reames; UNROLL-NO-IC:       exit:
5973eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[DOTLCSSA:%.*]] = phi i64 [ [[C23:%.*]], [[LOOP]] ], [ [[TMP23]], [[MIDDLE_BLOCK]] ]
5974eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret i64 [[DOTLCSSA]]
5975eb052f6bSPhilip Reames; UNROLL-NO-IC:       loop:
5976eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C5:%.*]] = phi i64 [ [[C23]], [[LOOP]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
5977eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
5978eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[X:%.*]] = phi i32 [ [[C24:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
5979eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[C6:%.*]], [[LOOP]] ], [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ]
5980eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C6]] = trunc i64 [[INDVARS_IV]] to i32
5981eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C8:%.*]] = mul i32 [[X]], [[C6]]
5982eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C9:%.*]] = add i32 [[C8]], 42
5983eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C10:%.*]] = add i32 [[SCALAR_RECUR]], [[C6]]
5984eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C11:%.*]] = add i32 [[C10]], [[C9]]
5985eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C12:%.*]] = sext i32 [[C11]] to i64
5986eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C13:%.*]] = add i64 [[C5]], [[C12]]
5987eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDVARS_IV_TR:%.*]] = trunc i64 [[INDVARS_IV]] to i32
5988eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C14:%.*]] = shl i32 [[INDVARS_IV_TR]], 1
5989eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C15:%.*]] = add i32 [[C9]], [[C14]]
5990eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C16:%.*]] = sext i32 [[C15]] to i64
5991eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C23]] = add i64 [[C13]], [[C16]]
5992eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
5993eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[C24]] = add nuw nsw i32 [[X]], 1
5994eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[EXITCOND_I:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 114
5995eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[EXITCOND_I]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP51:![0-9]+]]
5996eb052f6bSPhilip Reames;
5997eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @trunc_with_first_order_recurrence(
5998eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
5999eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
6000eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
6001eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
6002eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
6003eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
6004eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_PHI:%.*]] = phi <4 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP20:%.*]], [[VECTOR_BODY]] ]
6005eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_PHI2:%.*]] = phi <4 x i64> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP21:%.*]], [[VECTOR_BODY]] ]
60067c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
60077c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VECTOR_RECUR:%.*]] = phi <4 x i32> [ <i32 poison, i32 poison, i32 poison, i32 42>, [[VECTOR_PH]] ], [ [[STEP_ADD5:%.*]], [[VECTOR_BODY]] ]
6008eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_IND4:%.*]] = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT7:%.*]], [[VECTOR_BODY]] ]
6009eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_IND8:%.*]] = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT11:%.*]], [[VECTOR_BODY]] ]
60107c080e46SNikita Popov; INTERLEAVE-NEXT:    [[STEP_ADD:%.*]] = add <4 x i32> [[VEC_IND]], <i32 4, i32 4, i32 4, i32 4>
60117c080e46SNikita Popov; INTERLEAVE-NEXT:    [[STEP_ADD5]] = add <4 x i32> [[VEC_IND4]], <i32 4, i32 4, i32 4, i32 4>
60127c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP0:%.*]] = shufflevector <4 x i32> [[VECTOR_RECUR]], <4 x i32> [[VEC_IND4]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
60137c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP1:%.*]] = shufflevector <4 x i32> [[VEC_IND4]], <4 x i32> [[STEP_ADD5]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
60147c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP2:%.*]] = mul <4 x i32> [[VEC_IND]], [[VEC_IND4]]
60157c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP3:%.*]] = mul <4 x i32> [[STEP_ADD]], [[STEP_ADD5]]
6016eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP4:%.*]] = add <4 x i32> [[TMP2]], <i32 42, i32 42, i32 42, i32 42>
6017eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = add <4 x i32> [[TMP3]], <i32 42, i32 42, i32 42, i32 42>
60187c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP6:%.*]] = add <4 x i32> [[TMP0]], [[VEC_IND4]]
60197c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP7:%.*]] = add <4 x i32> [[TMP1]], [[STEP_ADD5]]
6020eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP8:%.*]] = add <4 x i32> [[TMP6]], [[TMP4]]
6021eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP9:%.*]] = add <4 x i32> [[TMP7]], [[TMP5]]
6022eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP10:%.*]] = sext <4 x i32> [[TMP8]] to <4 x i64>
6023eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP11:%.*]] = sext <4 x i32> [[TMP9]] to <4 x i64>
6024eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP12:%.*]] = add <4 x i64> [[VEC_PHI]], [[TMP10]]
6025eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP13:%.*]] = add <4 x i64> [[VEC_PHI2]], [[TMP11]]
60267c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP14:%.*]] = shl <4 x i32> [[VEC_IND8]], <i32 1, i32 1, i32 1, i32 1>
60277c080e46SNikita Popov; INTERLEAVE-NEXT:    [[STEP_ADD9:%.*]] = shl <4 x i32> [[VEC_IND8]], <i32 1, i32 1, i32 1, i32 1>
60287c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP15:%.*]] = add <4 x i32> [[STEP_ADD9]], <i32 8, i32 8, i32 8, i32 8>
6029eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP16:%.*]] = add <4 x i32> [[TMP4]], [[TMP14]]
6030eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP17:%.*]] = add <4 x i32> [[TMP5]], [[TMP15]]
6031eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP18:%.*]] = sext <4 x i32> [[TMP16]] to <4 x i64>
6032eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP19:%.*]] = sext <4 x i32> [[TMP17]] to <4 x i64>
6033eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP20]] = add <4 x i64> [[TMP12]], [[TMP18]]
6034eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP21]] = add <4 x i64> [[TMP13]], [[TMP19]]
6035eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
60367c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND_NEXT]] = add <4 x i32> [[VEC_IND]], <i32 8, i32 8, i32 8, i32 8>
6037eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_IND_NEXT7]] = add <4 x i32> [[VEC_IND4]], <i32 8, i32 8, i32 8, i32 8>
6038eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_IND_NEXT11]] = add <4 x i32> [[VEC_IND8]], <i32 8, i32 8, i32 8, i32 8>
6039eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP22:%.*]] = icmp eq i64 [[INDEX_NEXT]], 112
6040eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP22]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP50:![0-9]+]]
6041eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
6042eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BIN_RDX:%.*]] = add <4 x i64> [[TMP21]], [[TMP20]]
6043eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP23:%.*]] = call i64 @llvm.vector.reduce.add.v4i64(<4 x i64> [[BIN_RDX]])
60447c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <4 x i32> [[STEP_ADD5]], i64 3
6045eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 false, label [[EXIT:%.*]], label [[SCALAR_PH]]
6046eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
6047eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 42, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
6048eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 1, [[ENTRY]] ], [ 113, [[MIDDLE_BLOCK]] ]
6049eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ 113, [[MIDDLE_BLOCK]] ]
6050eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_MERGE_RDX:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[TMP23]], [[MIDDLE_BLOCK]] ]
6051eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[LOOP:%.*]]
6052eb052f6bSPhilip Reames; INTERLEAVE:       exit:
6053eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[DOTLCSSA:%.*]] = phi i64 [ [[C23:%.*]], [[LOOP]] ], [ [[TMP23]], [[MIDDLE_BLOCK]] ]
6054eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret i64 [[DOTLCSSA]]
6055eb052f6bSPhilip Reames; INTERLEAVE:       loop:
6056eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C5:%.*]] = phi i64 [ [[C23]], [[LOOP]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
6057eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
6058eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[X:%.*]] = phi i32 [ [[C24:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
6059eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[C6:%.*]], [[LOOP]] ], [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ]
6060eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C6]] = trunc i64 [[INDVARS_IV]] to i32
6061eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C8:%.*]] = mul i32 [[X]], [[C6]]
6062eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C9:%.*]] = add i32 [[C8]], 42
6063eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C10:%.*]] = add i32 [[SCALAR_RECUR]], [[C6]]
6064eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C11:%.*]] = add i32 [[C10]], [[C9]]
6065eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C12:%.*]] = sext i32 [[C11]] to i64
6066eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C13:%.*]] = add i64 [[C5]], [[C12]]
6067eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDVARS_IV_TR:%.*]] = trunc i64 [[INDVARS_IV]] to i32
6068eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C14:%.*]] = shl i32 [[INDVARS_IV_TR]], 1
6069eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C15:%.*]] = add i32 [[C9]], [[C14]]
6070eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C16:%.*]] = sext i32 [[C15]] to i64
6071eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C23]] = add i64 [[C13]], [[C16]]
6072eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
6073eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[C24]] = add nuw nsw i32 [[X]], 1
6074eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[EXITCOND_I:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 114
6075eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[EXITCOND_I]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP51:![0-9]+]]
6076eb052f6bSPhilip Reames;
6077cee313d2SEric Christopherentry:
6078cee313d2SEric Christopher  br label %loop
6079cee313d2SEric Christopher
6080cee313d2SEric Christopherexit:                                        ; preds = %loop
6081cee313d2SEric Christopher  %.lcssa = phi i64 [ %c23, %loop ]
6082cee313d2SEric Christopher  ret i64 %.lcssa
6083cee313d2SEric Christopher
6084cee313d2SEric Christopherloop:                                         ; preds = %loop, %entry
6085cee313d2SEric Christopher  %c5 = phi i64 [ %c23, %loop ], [ 0, %entry ]
6086cee313d2SEric Christopher  %indvars.iv = phi i64 [ %indvars.iv.next, %loop ], [ 1, %entry ]
6087cee313d2SEric Christopher  %x = phi i32 [ %c24, %loop ], [ 1, %entry ]
6088cee313d2SEric Christopher  %y = phi i32 [ %c6, %loop ], [ 42, %entry ]
6089cee313d2SEric Christopher  %c6 = trunc i64 %indvars.iv to i32
6090cee313d2SEric Christopher  %c8 = mul i32 %x, %c6
6091cee313d2SEric Christopher  %c9 = add i32 %c8, 42
6092cee313d2SEric Christopher  %c10 = add i32 %y, %c6
6093cee313d2SEric Christopher  %c11 = add i32 %c10, %c9
6094cee313d2SEric Christopher  %c12 = sext i32 %c11 to i64
6095cee313d2SEric Christopher  %c13 = add i64 %c5, %c12
6096cee313d2SEric Christopher  %indvars.iv.tr = trunc i64 %indvars.iv to i32
6097cee313d2SEric Christopher  %c14 = shl i32 %indvars.iv.tr, 1
6098cee313d2SEric Christopher  %c15 = add i32 %c9, %c14
6099cee313d2SEric Christopher  %c16 = sext i32 %c15 to i64
6100cee313d2SEric Christopher  %c23 = add i64 %c13, %c16
6101cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
6102cee313d2SEric Christopher  %c24 = add nuw nsw i32 %x, 1
6103cee313d2SEric Christopher  %exitcond.i = icmp eq i64 %indvars.iv.next, 114
6104cee313d2SEric Christopher  br i1 %exitcond.i, label %exit, label %loop
6105cee313d2SEric Christopher
6106cee313d2SEric Christopher}
6107e7f1232cSFlorian Hahn
6108e7f1232cSFlorian Hahn; Test case for PR52460.
6109e7f1232cSFlorian Hahndefine void @pr52460_first_order_recurrence_truncated_iv(i32* noalias %src, i32* %dst) {
6110eb052f6bSPhilip Reames;
6111eb052f6bSPhilip Reames; CHECK-LABEL: @pr52460_first_order_recurrence_truncated_iv(
6112eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
6113eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
6114eb052f6bSPhilip Reames; CHECK:       vector.ph:
6115eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
6116eb052f6bSPhilip Reames; CHECK:       vector.body:
6117eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
61187c080e46SNikita Popov; CHECK-NEXT:    [[VECTOR_RECUR:%.*]] = phi <2 x i32> [ <i32 poison, i32 0>, [[VECTOR_PH]] ], [ [[VEC_IND:%.*]], [[VECTOR_BODY]] ]
61197c080e46SNikita Popov; CHECK-NEXT:    [[VEC_IND]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
61207c080e46SNikita Popov; CHECK-NEXT:    [[TMP0:%.*]] = trunc i64 [[INDEX]] to i32
61217c080e46SNikita Popov; CHECK-NEXT:    [[TMP1:%.*]] = add i32 [[TMP0]], 0
61220c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP2:%.*]] = shufflevector <2 x i32> [[VECTOR_RECUR]], <2 x i32> [[VEC_IND]], <2 x i32> <i32 1, i32 2>
61230c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP3:%.*]] = load i32, i32* [[SRC:%.*]], align 4
61240c00dbb9SNikita Popov; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[TMP3]], i32 0
6125eb052f6bSPhilip Reames; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
61260c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP4:%.*]] = mul nsw <2 x i32> [[BROADCAST_SPLAT]], [[TMP2]]
61270c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP5:%.*]] = getelementptr i32, i32* [[DST:%.*]], i32 [[TMP1]]
61280c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP6:%.*]] = add <2 x i32> [[VEC_IND]], [[TMP4]]
61290c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP7:%.*]] = getelementptr i32, i32* [[TMP5]], i32 0
61300c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP8:%.*]] = bitcast i32* [[TMP7]] to <2 x i32>*
61310c00dbb9SNikita Popov; CHECK-NEXT:    store <2 x i32> [[TMP6]], <2 x i32>* [[TMP8]], align 4
6132eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
61337c080e46SNikita Popov; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
61340c00dbb9SNikita Popov; CHECK-NEXT:    [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 100
61350c00dbb9SNikita Popov; CHECK-NEXT:    br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP52:![0-9]+]]
6136eb052f6bSPhilip Reames; CHECK:       middle.block:
6137eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 100, 100
61387c080e46SNikita Popov; CHECK-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <2 x i32> [[VEC_IND]], i32 1
61397c080e46SNikita Popov; CHECK-NEXT:    [[VECTOR_RECUR_EXTRACT_FOR_PHI:%.*]] = extractelement <2 x i32> [[VEC_IND]], i32 0
6140eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
6141eb052f6bSPhilip Reames; CHECK:       scalar.ph:
6142eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
6143eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 100, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
6144eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ 100, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
6145eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[LOOP:%.*]]
6146eb052f6bSPhilip Reames; CHECK:       loop:
6147eb052f6bSPhilip Reames; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
6148eb052f6bSPhilip Reames; CHECK-NEXT:    [[TRUNC_IV:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[TRUNC_IV_NEXT:%.*]], [[LOOP]] ]
6149eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ], [ [[IV_TRUNC:%.*]], [[LOOP]] ]
6150eb052f6bSPhilip Reames; CHECK-NEXT:    [[LV:%.*]] = load i32, i32* [[SRC]], align 4
6151eb052f6bSPhilip Reames; CHECK-NEXT:    [[MUL:%.*]] = mul nsw i32 [[LV]], [[SCALAR_RECUR]]
6152eb052f6bSPhilip Reames; CHECK-NEXT:    [[TRUNC_IV_NEXT]] = add i32 [[TRUNC_IV]], 1
6153eb052f6bSPhilip Reames; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
6154eb052f6bSPhilip Reames; CHECK-NEXT:    [[IV_TRUNC]] = trunc i64 [[IV]] to i32
6155eb052f6bSPhilip Reames; CHECK-NEXT:    [[DST_GEP:%.*]] = getelementptr i32, i32* [[DST]], i32 [[IV_TRUNC]]
6156eb052f6bSPhilip Reames; CHECK-NEXT:    [[ADD:%.*]] = add i32 [[IV_TRUNC]], [[MUL]]
6157eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[ADD]], i32* [[DST_GEP]], align 4
6158eb052f6bSPhilip Reames; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[TRUNC_IV_NEXT]], 100
6159eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP53:![0-9]+]]
6160eb052f6bSPhilip Reames; CHECK:       exit:
6161eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
6162eb052f6bSPhilip Reames;
6163eb052f6bSPhilip Reames; IND-LABEL: @pr52460_first_order_recurrence_truncated_iv(
6164eb052f6bSPhilip Reames; IND-NEXT:  entry:
6165eb052f6bSPhilip Reames; IND-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
6166eb052f6bSPhilip Reames; IND:       vector.ph:
6167eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
6168eb052f6bSPhilip Reames; IND:       vector.body:
6169eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
61707c080e46SNikita Popov; IND-NEXT:    [[VECTOR_RECUR:%.*]] = phi <2 x i32> [ <i32 poison, i32 0>, [[VECTOR_PH]] ], [ [[VEC_IND:%.*]], [[VECTOR_BODY]] ]
61717c080e46SNikita Popov; IND-NEXT:    [[VEC_IND]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
61727c080e46SNikita Popov; IND-NEXT:    [[TMP0:%.*]] = shufflevector <2 x i32> [[VECTOR_RECUR]], <2 x i32> [[VEC_IND]], <2 x i32> <i32 1, i32 2>
6173eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = load i32, i32* [[SRC:%.*]], align 4
6174e6ad9ef4SPhilip Reames; IND-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[TMP1]], i64 0
6175eb052f6bSPhilip Reames; IND-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
6176eb052f6bSPhilip Reames; IND-NEXT:    [[TMP2:%.*]] = mul nsw <2 x i32> [[BROADCAST_SPLAT]], [[TMP0]]
6177eb052f6bSPhilip Reames; IND-NEXT:    [[SEXT:%.*]] = shl i64 [[INDEX]], 32
6178eb052f6bSPhilip Reames; IND-NEXT:    [[TMP3:%.*]] = ashr exact i64 [[SEXT]], 32
6179eb052f6bSPhilip Reames; IND-NEXT:    [[TMP4:%.*]] = getelementptr i32, i32* [[DST:%.*]], i64 [[TMP3]]
61807c080e46SNikita Popov; IND-NEXT:    [[TMP5:%.*]] = add <2 x i32> [[VEC_IND]], [[TMP2]]
6181eb052f6bSPhilip Reames; IND-NEXT:    [[TMP6:%.*]] = bitcast i32* [[TMP4]] to <2 x i32>*
6182eb052f6bSPhilip Reames; IND-NEXT:    store <2 x i32> [[TMP5]], <2 x i32>* [[TMP6]], align 4
6183eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
61847c080e46SNikita Popov; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
6185eb052f6bSPhilip Reames; IND-NEXT:    [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], 100
6186eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[TMP7]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP52:![0-9]+]]
6187eb052f6bSPhilip Reames; IND:       middle.block:
6188eb052f6bSPhilip Reames; IND-NEXT:    br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]
6189eb052f6bSPhilip Reames; IND:       scalar.ph:
6190eb052f6bSPhilip Reames; IND-NEXT:    br label [[LOOP:%.*]]
6191eb052f6bSPhilip Reames; IND:       loop:
6192*9df0b254SNuno Lopes; IND-NEXT:    br i1 poison, label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP53:![0-9]+]]
6193eb052f6bSPhilip Reames; IND:       exit:
6194eb052f6bSPhilip Reames; IND-NEXT:    ret void
6195eb052f6bSPhilip Reames;
6196eb052f6bSPhilip Reames; UNROLL-LABEL: @pr52460_first_order_recurrence_truncated_iv(
6197eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
6198eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
6199eb052f6bSPhilip Reames; UNROLL:       vector.ph:
6200eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
6201eb052f6bSPhilip Reames; UNROLL:       vector.body:
6202eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
62037c080e46SNikita Popov; UNROLL-NEXT:    [[VECTOR_RECUR:%.*]] = phi <2 x i32> [ <i32 poison, i32 0>, [[VECTOR_PH]] ], [ [[STEP_ADD:%.*]], [[VECTOR_BODY]] ]
62047c080e46SNikita Popov; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
62057c080e46SNikita Popov; UNROLL-NEXT:    [[STEP_ADD]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
62067c080e46SNikita Popov; UNROLL-NEXT:    [[TMP0:%.*]] = shufflevector <2 x i32> [[VECTOR_RECUR]], <2 x i32> [[VEC_IND]], <2 x i32> <i32 1, i32 2>
62077c080e46SNikita Popov; UNROLL-NEXT:    [[TMP1:%.*]] = shufflevector <2 x i32> [[VEC_IND]], <2 x i32> [[STEP_ADD]], <2 x i32> <i32 1, i32 2>
6208eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP2:%.*]] = load i32, i32* [[SRC:%.*]], align 4
6209e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[TMP2]], i64 0
6210eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
62117c080e46SNikita Popov; UNROLL-NEXT:    [[BROADCAST_SPLATINSERT3:%.*]] = insertelement <2 x i32> poison, i32 [[TMP2]], i64 0
62127c080e46SNikita Popov; UNROLL-NEXT:    [[BROADCAST_SPLAT4:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT3]], <2 x i32> poison, <2 x i32> zeroinitializer
6213eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP3:%.*]] = mul nsw <2 x i32> [[BROADCAST_SPLAT]], [[TMP0]]
62147c080e46SNikita Popov; UNROLL-NEXT:    [[TMP4:%.*]] = mul nsw <2 x i32> [[BROADCAST_SPLAT4]], [[TMP1]]
6215eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SEXT:%.*]] = shl i64 [[INDEX]], 32
6216eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP5:%.*]] = ashr exact i64 [[SEXT]], 32
6217eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP6:%.*]] = getelementptr i32, i32* [[DST:%.*]], i64 [[TMP5]]
62187c080e46SNikita Popov; UNROLL-NEXT:    [[TMP7:%.*]] = add <2 x i32> [[VEC_IND]], [[TMP3]]
62197c080e46SNikita Popov; UNROLL-NEXT:    [[TMP8:%.*]] = add <2 x i32> [[STEP_ADD]], [[TMP4]]
6220eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP9:%.*]] = bitcast i32* [[TMP6]] to <2 x i32>*
6221eb052f6bSPhilip Reames; UNROLL-NEXT:    store <2 x i32> [[TMP7]], <2 x i32>* [[TMP9]], align 4
6222eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP10:%.*]] = getelementptr i32, i32* [[TMP6]], i64 2
6223eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP11:%.*]] = bitcast i32* [[TMP10]] to <2 x i32>*
6224eb052f6bSPhilip Reames; UNROLL-NEXT:    store <2 x i32> [[TMP8]], <2 x i32>* [[TMP11]], align 4
6225eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
62267c080e46SNikita Popov; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 4, i32 4>
6227eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], 100
6228eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP52:![0-9]+]]
6229eb052f6bSPhilip Reames; UNROLL:       middle.block:
6230eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]
6231eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
6232eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[LOOP:%.*]]
6233eb052f6bSPhilip Reames; UNROLL:       loop:
6234*9df0b254SNuno Lopes; UNROLL-NEXT:    br i1 poison, label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP53:![0-9]+]]
6235eb052f6bSPhilip Reames; UNROLL:       exit:
6236eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
6237eb052f6bSPhilip Reames;
6238eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @pr52460_first_order_recurrence_truncated_iv(
6239eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
6240eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
6241eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
6242eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
6243eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
6244eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
62457c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VECTOR_RECUR:%.*]] = phi <2 x i32> [ <i32 poison, i32 0>, [[VECTOR_PH]] ], [ [[STEP_ADD:%.*]], [[VECTOR_BODY]] ]
62467c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
62477c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[STEP_ADD]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
62487c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = trunc i64 [[INDEX]] to i32
62497c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = add i32 [[TMP0]], 0
62500c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = add i32 [[TMP0]], 2
62510c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = shufflevector <2 x i32> [[VECTOR_RECUR]], <2 x i32> [[VEC_IND]], <2 x i32> <i32 1, i32 2>
62520c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = shufflevector <2 x i32> [[VEC_IND]], <2 x i32> [[STEP_ADD]], <2 x i32> <i32 1, i32 2>
62530c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = load i32, i32* [[SRC:%.*]], align 4
62540c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[TMP5]], i32 0
6255eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
62560c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = load i32, i32* [[SRC]], align 4
62570c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLATINSERT3:%.*]] = insertelement <2 x i32> poison, i32 [[TMP6]], i32 0
62587c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[BROADCAST_SPLAT4:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT3]], <2 x i32> poison, <2 x i32> zeroinitializer
62590c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = mul nsw <2 x i32> [[BROADCAST_SPLAT]], [[TMP3]]
62600c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = mul nsw <2 x i32> [[BROADCAST_SPLAT4]], [[TMP4]]
62610c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = getelementptr i32, i32* [[DST:%.*]], i32 [[TMP1]]
62620c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = getelementptr i32, i32* [[DST]], i32 [[TMP2]]
62630c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = add <2 x i32> [[VEC_IND]], [[TMP7]]
62640c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = add <2 x i32> [[STEP_ADD]], [[TMP8]]
62650c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = getelementptr i32, i32* [[TMP9]], i32 0
62660c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = bitcast i32* [[TMP13]] to <2 x i32>*
62670c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[TMP11]], <2 x i32>* [[TMP14]], align 4
62680c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = getelementptr i32, i32* [[TMP9]], i32 2
62697c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP16:%.*]] = bitcast i32* [[TMP15]] to <2 x i32>*
62700c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[TMP12]], <2 x i32>* [[TMP16]], align 4
6271eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
62727c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[STEP_ADD]], <i32 2, i32 2>
62730c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP17:%.*]] = icmp eq i64 [[INDEX_NEXT]], 100
62740c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP17]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP52:![0-9]+]]
6275eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
6276eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i64 100, 100
62777c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <2 x i32> [[STEP_ADD]], i32 1
62787c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[VECTOR_RECUR_EXTRACT_FOR_PHI:%.*]] = extractelement <2 x i32> [[STEP_ADD]], i32 0
6279eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
6280eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
6281eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
6282eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 100, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
6283eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ 100, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
6284eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[LOOP:%.*]]
6285eb052f6bSPhilip Reames; UNROLL-NO-IC:       loop:
6286eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
6287eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TRUNC_IV:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[TRUNC_IV_NEXT:%.*]], [[LOOP]] ]
6288eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ], [ [[IV_TRUNC:%.*]], [[LOOP]] ]
6289eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[LV:%.*]] = load i32, i32* [[SRC]], align 4
6290eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MUL:%.*]] = mul nsw i32 [[LV]], [[SCALAR_RECUR]]
6291eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TRUNC_IV_NEXT]] = add i32 [[TRUNC_IV]], 1
6292eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
6293eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IV_TRUNC]] = trunc i64 [[IV]] to i32
6294eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[DST_GEP:%.*]] = getelementptr i32, i32* [[DST]], i32 [[IV_TRUNC]]
6295eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[ADD:%.*]] = add i32 [[IV_TRUNC]], [[MUL]]
6296eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[ADD]], i32* [[DST_GEP]], align 4
6297eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[TRUNC_IV_NEXT]], 100
6298eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP53:![0-9]+]]
6299eb052f6bSPhilip Reames; UNROLL-NO-IC:       exit:
6300eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
6301eb052f6bSPhilip Reames;
6302eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @pr52460_first_order_recurrence_truncated_iv(
6303eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
6304eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
6305eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
6306eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
6307eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
6308eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
63097c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VECTOR_RECUR:%.*]] = phi <4 x i32> [ <i32 poison, i32 poison, i32 poison, i32 0>, [[VECTOR_PH]] ], [ [[STEP_ADD:%.*]], [[VECTOR_BODY]] ]
63107c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
63117c080e46SNikita Popov; INTERLEAVE-NEXT:    [[STEP_ADD]] = add <4 x i32> [[VEC_IND]], <i32 4, i32 4, i32 4, i32 4>
63127c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP0:%.*]] = shufflevector <4 x i32> [[VECTOR_RECUR]], <4 x i32> [[VEC_IND]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
63137c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP1:%.*]] = shufflevector <4 x i32> [[VEC_IND]], <4 x i32> [[STEP_ADD]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
6314eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP2:%.*]] = load i32, i32* [[SRC:%.*]], align 4
6315e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[TMP2]], i64 0
6316eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
63177c080e46SNikita Popov; INTERLEAVE-NEXT:    [[BROADCAST_SPLATINSERT3:%.*]] = insertelement <4 x i32> poison, i32 [[TMP2]], i64 0
63187c080e46SNikita Popov; INTERLEAVE-NEXT:    [[BROADCAST_SPLAT4:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT3]], <4 x i32> poison, <4 x i32> zeroinitializer
6319eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP3:%.*]] = mul nsw <4 x i32> [[BROADCAST_SPLAT]], [[TMP0]]
63207c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP4:%.*]] = mul nsw <4 x i32> [[BROADCAST_SPLAT4]], [[TMP1]]
6321eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SEXT:%.*]] = shl i64 [[INDEX]], 32
6322eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP5:%.*]] = ashr exact i64 [[SEXT]], 32
6323eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP6:%.*]] = getelementptr i32, i32* [[DST:%.*]], i64 [[TMP5]]
63247c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP7:%.*]] = add <4 x i32> [[VEC_IND]], [[TMP3]]
63257c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP8:%.*]] = add <4 x i32> [[STEP_ADD]], [[TMP4]]
6326eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP9:%.*]] = bitcast i32* [[TMP6]] to <4 x i32>*
6327eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store <4 x i32> [[TMP7]], <4 x i32>* [[TMP9]], align 4
6328eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP10:%.*]] = getelementptr i32, i32* [[TMP6]], i64 4
6329eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP11:%.*]] = bitcast i32* [[TMP10]] to <4 x i32>*
6330eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store <4 x i32> [[TMP8]], <4 x i32>* [[TMP11]], align 4
6331eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
63327c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND_NEXT]] = add <4 x i32> [[VEC_IND]], <i32 8, i32 8, i32 8, i32 8>
6333eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], 96
6334eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP52:![0-9]+]]
6335eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
63367c080e46SNikita Popov; INTERLEAVE-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <4 x i32> [[STEP_ADD]], i64 3
6337eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 false, label [[EXIT:%.*]], label [[SCALAR_PH]]
6338eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
6339eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
6340eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ 96, [[MIDDLE_BLOCK]] ]
6341eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ 96, [[MIDDLE_BLOCK]] ]
6342eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[LOOP:%.*]]
6343eb052f6bSPhilip Reames; INTERLEAVE:       loop:
6344eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
6345eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TRUNC_IV:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[TRUNC_IV_NEXT:%.*]], [[LOOP]] ]
6346eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ], [ [[IV_TRUNC:%.*]], [[LOOP]] ]
6347eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[LV:%.*]] = load i32, i32* [[SRC]], align 4
6348eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MUL:%.*]] = mul nsw i32 [[LV]], [[SCALAR_RECUR]]
6349eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TRUNC_IV_NEXT]] = add i32 [[TRUNC_IV]], 1
6350eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
6351eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IV_TRUNC]] = trunc i64 [[IV]] to i32
63527c080e46SNikita Popov; INTERLEAVE-NEXT:    [[SEXT5:%.*]] = shl i64 [[IV]], 32
63537c080e46SNikita Popov; INTERLEAVE-NEXT:    [[TMP13:%.*]] = ashr exact i64 [[SEXT5]], 32
6354eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[DST_GEP:%.*]] = getelementptr i32, i32* [[DST]], i64 [[TMP13]]
6355eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[ADD:%.*]] = add i32 [[MUL]], [[IV_TRUNC]]
6356eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[ADD]], i32* [[DST_GEP]], align 4
6357eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[TRUNC_IV_NEXT]], 100
6358eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP53:![0-9]+]]
6359eb052f6bSPhilip Reames; INTERLEAVE:       exit:
6360eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
6361e7f1232cSFlorian Hahn;
6362e7f1232cSFlorian Hahnentry:
6363e7f1232cSFlorian Hahn  br label %loop
6364e7f1232cSFlorian Hahn
6365e7f1232cSFlorian Hahnloop:
6366e7f1232cSFlorian Hahn  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
6367e7f1232cSFlorian Hahn  %trunc.iv = phi i32 [ 0, %entry ], [ %trunc.iv.next, %loop ]
6368e7f1232cSFlorian Hahn  %recur = phi i32 [ 0, %entry ], [ %iv.trunc, %loop ]
6369e7f1232cSFlorian Hahn  %lv = load i32, i32* %src, align 4
6370e7f1232cSFlorian Hahn  %mul = mul nsw i32 %lv, %recur
6371e7f1232cSFlorian Hahn  %trunc.iv.next  = add i32 %trunc.iv, 1
6372e7f1232cSFlorian Hahn  %iv.next = add nuw nsw i64 %iv, 1
6373e7f1232cSFlorian Hahn  %iv.trunc = trunc i64 %iv to i32
6374e7f1232cSFlorian Hahn  %dst.gep = getelementptr i32, i32* %dst, i32 %iv.trunc
6375e7f1232cSFlorian Hahn  %add = add i32 %iv.trunc, %mul
6376e7f1232cSFlorian Hahn  store i32 %add, i32* %dst.gep
6377e7f1232cSFlorian Hahn  %exitcond = icmp eq i32 %trunc.iv.next, 100
6378e7f1232cSFlorian Hahn  br i1 %exitcond, label %exit, label %loop
6379e7f1232cSFlorian Hahn
6380e7f1232cSFlorian Hahnexit:
6381e7f1232cSFlorian Hahn  ret void
6382e7f1232cSFlorian Hahn}
6383505ad03cSFlorian Hahn
6384505ad03cSFlorian Hahn; Test case where %iv.2.ext and %iv.2.conv become redundant due to the SCEV
6385505ad03cSFlorian Hahn; predicates generated for the vector loop. They should be removed in the
6386505ad03cSFlorian Hahn; vector loop.
6387505ad03cSFlorian Hahndefine void @test_optimized_cast_induction_feeding_first_order_recurrence(i64 %n, i32 %step, i32* %ptr) {
6388eb052f6bSPhilip Reames;
6389505ad03cSFlorian Hahn; CHECK-LABEL: @test_optimized_cast_induction_feeding_first_order_recurrence(
6390eb052f6bSPhilip Reames; CHECK-NEXT:  entry:
6391eb052f6bSPhilip Reames; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N:%.*]], 2
6392eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
6393eb052f6bSPhilip Reames; CHECK:       vector.scevcheck:
6394eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = add i64 [[N]], -1
6395eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = trunc i32 [[STEP:%.*]] to i8
6396eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = sub i8 0, [[TMP1]]
6397eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = icmp slt i8 [[TMP1]], 0
6398eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = select i1 [[TMP3]], i8 [[TMP2]], i8 [[TMP1]]
6399eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP5:%.*]] = trunc i64 [[TMP0]] to i8
6400eb052f6bSPhilip Reames; CHECK-NEXT:    [[MUL:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[TMP4]], i8 [[TMP5]])
6401eb052f6bSPhilip Reames; CHECK-NEXT:    [[MUL_RESULT:%.*]] = extractvalue { i8, i1 } [[MUL]], 0
6402eb052f6bSPhilip Reames; CHECK-NEXT:    [[MUL_OVERFLOW:%.*]] = extractvalue { i8, i1 } [[MUL]], 1
64037c080e46SNikita Popov; CHECK-NEXT:    [[TMP6:%.*]] = sub i8 0, [[MUL_RESULT]]
64047c080e46SNikita Popov; CHECK-NEXT:    [[TMP7:%.*]] = icmp slt i8 [[MUL_RESULT]], 0
64057c080e46SNikita Popov; CHECK-NEXT:    [[TMP8:%.*]] = icmp sgt i8 [[TMP6]], 0
64067c080e46SNikita Popov; CHECK-NEXT:    [[TMP9:%.*]] = select i1 [[TMP3]], i1 [[TMP8]], i1 [[TMP7]]
64077c080e46SNikita Popov; CHECK-NEXT:    [[TMP10:%.*]] = or i1 [[TMP9]], [[MUL_OVERFLOW]]
6408eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP11:%.*]] = icmp ugt i64 [[TMP0]], 255
6409eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP12:%.*]] = icmp ne i8 [[TMP1]], 0
6410eb052f6bSPhilip Reames; CHECK-NEXT:    [[TMP13:%.*]] = and i1 [[TMP11]], [[TMP12]]
64117c080e46SNikita Popov; CHECK-NEXT:    [[TMP14:%.*]] = or i1 [[TMP10]], [[TMP13]]
64127c080e46SNikita Popov; CHECK-NEXT:    [[TMP15:%.*]] = sext i8 [[TMP1]] to i32
64137c080e46SNikita Popov; CHECK-NEXT:    [[IDENT_CHECK:%.*]] = icmp ne i32 [[STEP]], [[TMP15]]
64147c080e46SNikita Popov; CHECK-NEXT:    [[TMP16:%.*]] = or i1 [[TMP14]], [[IDENT_CHECK]]
64157c080e46SNikita Popov; CHECK-NEXT:    br i1 [[TMP16]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
6416eb052f6bSPhilip Reames; CHECK:       vector.ph:
6417eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[N]], 2
6418eb052f6bSPhilip Reames; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[N]], [[N_MOD_VF]]
64190c00dbb9SNikita Popov; CHECK-NEXT:    [[CAST_VTC:%.*]] = trunc i64 [[N_VEC]] to i32
64200c00dbb9SNikita Popov; CHECK-NEXT:    [[IND_END:%.*]] = mul i32 [[CAST_VTC]], [[STEP]]
6421eb052f6bSPhilip Reames; CHECK-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[STEP]], i32 0
6422eb052f6bSPhilip Reames; CHECK-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
64237c080e46SNikita Popov; CHECK-NEXT:    [[TMP17:%.*]] = mul <2 x i32> <i32 0, i32 1>, [[DOTSPLAT]]
64247c080e46SNikita Popov; CHECK-NEXT:    [[INDUCTION:%.*]] = add <2 x i32> zeroinitializer, [[TMP17]]
64257c080e46SNikita Popov; CHECK-NEXT:    [[TMP18:%.*]] = mul i32 [[STEP]], 2
64267c080e46SNikita Popov; CHECK-NEXT:    [[DOTSPLATINSERT2:%.*]] = insertelement <2 x i32> poison, i32 [[TMP18]], i32 0
6427eb052f6bSPhilip Reames; CHECK-NEXT:    [[DOTSPLAT3:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT2]], <2 x i32> poison, <2 x i32> zeroinitializer
6428eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
6429eb052f6bSPhilip Reames; CHECK:       vector.body:
6430eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
6431eb052f6bSPhilip Reames; CHECK-NEXT:    [[VECTOR_RECUR:%.*]] = phi <2 x i32> [ <i32 poison, i32 0>, [[VECTOR_PH]] ], [ [[VEC_IND:%.*]], [[VECTOR_BODY]] ]
6432eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_IND]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
64337c080e46SNikita Popov; CHECK-NEXT:    [[TMP19:%.*]] = add i64 [[INDEX]], 0
64347c080e46SNikita Popov; CHECK-NEXT:    [[TMP20:%.*]] = shufflevector <2 x i32> [[VECTOR_RECUR]], <2 x i32> [[VEC_IND]], <2 x i32> <i32 1, i32 2>
64357c080e46SNikita Popov; CHECK-NEXT:    [[TMP21:%.*]] = getelementptr inbounds i32, i32* [[PTR:%.*]], i64 [[TMP19]]
64367c080e46SNikita Popov; CHECK-NEXT:    [[TMP22:%.*]] = getelementptr inbounds i32, i32* [[TMP21]], i32 0
64377c080e46SNikita Popov; CHECK-NEXT:    [[TMP23:%.*]] = bitcast i32* [[TMP22]] to <2 x i32>*
64387c080e46SNikita Popov; CHECK-NEXT:    store <2 x i32> [[TMP20]], <2 x i32>* [[TMP23]], align 4
6439eb052f6bSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
6440eb052f6bSPhilip Reames; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], [[DOTSPLAT3]]
64417c080e46SNikita Popov; CHECK-NEXT:    [[TMP24:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
64427c080e46SNikita Popov; CHECK-NEXT:    br i1 [[TMP24]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP54:![0-9]+]]
6443eb052f6bSPhilip Reames; CHECK:       middle.block:
6444eb052f6bSPhilip Reames; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]]
6445eb052f6bSPhilip Reames; CHECK-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <2 x i32> [[VEC_IND]], i32 1
6446eb052f6bSPhilip Reames; CHECK-NEXT:    [[VECTOR_RECUR_EXTRACT_FOR_PHI:%.*]] = extractelement <2 x i32> [[VEC_IND]], i32 0
6447eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
6448eb052f6bSPhilip Reames; CHECK:       scalar.ph:
6449eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
6450eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
6451eb052f6bSPhilip Reames; CHECK-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
6452eb052f6bSPhilip Reames; CHECK-NEXT:    br label [[LOOP:%.*]]
6453eb052f6bSPhilip Reames; CHECK:       loop:
6454eb052f6bSPhilip Reames; CHECK-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ], [ [[IV_2_CONV:%.*]], [[LOOP]] ]
6455eb052f6bSPhilip Reames; CHECK-NEXT:    [[IV_1:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_1_NEXT:%.*]], [[LOOP]] ]
6456eb052f6bSPhilip Reames; CHECK-NEXT:    [[IV_2:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[IV_2_NEXT:%.*]], [[LOOP]] ]
6457eb052f6bSPhilip Reames; CHECK-NEXT:    [[IV_2_EXT:%.*]] = shl i32 [[IV_2]], 24
6458eb052f6bSPhilip Reames; CHECK-NEXT:    [[IV_2_CONV]] = ashr exact i32 [[IV_2_EXT]], 24
6459eb052f6bSPhilip Reames; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds i32, i32* [[PTR]], i64 [[IV_1]]
6460eb052f6bSPhilip Reames; CHECK-NEXT:    store i32 [[SCALAR_RECUR]], i32* [[GEP]], align 4
6461eb052f6bSPhilip Reames; CHECK-NEXT:    [[IV_2_NEXT]] = add nsw i32 [[IV_2_CONV]], [[STEP]]
6462eb052f6bSPhilip Reames; CHECK-NEXT:    [[IV_1_NEXT]] = add nuw nsw i64 [[IV_1]], 1
6463eb052f6bSPhilip Reames; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV_1_NEXT]], [[N]]
6464eb052f6bSPhilip Reames; CHECK-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP55:![0-9]+]]
6465eb052f6bSPhilip Reames; CHECK:       exit:
6466eb052f6bSPhilip Reames; CHECK-NEXT:    ret void
6467eb052f6bSPhilip Reames;
6468eb052f6bSPhilip Reames; IND-LABEL: @test_optimized_cast_induction_feeding_first_order_recurrence(
6469eb052f6bSPhilip Reames; IND-NEXT:  entry:
6470eb052f6bSPhilip Reames; IND-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N:%.*]], 2
6471eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
6472eb052f6bSPhilip Reames; IND:       vector.scevcheck:
6473eb052f6bSPhilip Reames; IND-NEXT:    [[TMP0:%.*]] = add i64 [[N]], -1
6474eb052f6bSPhilip Reames; IND-NEXT:    [[TMP1:%.*]] = trunc i32 [[STEP:%.*]] to i8
647526748bb1SNikita Popov; IND-NEXT:    [[TMP2:%.*]] = icmp slt i8 [[TMP1]], 0
647626748bb1SNikita Popov; IND-NEXT:    [[TMP3:%.*]] = call i8 @llvm.abs.i8(i8 [[TMP1]], i1 false)
647726748bb1SNikita Popov; IND-NEXT:    [[TMP4:%.*]] = trunc i64 [[TMP0]] to i8
647826748bb1SNikita Popov; IND-NEXT:    [[MUL:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[TMP3]], i8 [[TMP4]])
6479eb052f6bSPhilip Reames; IND-NEXT:    [[MUL_RESULT:%.*]] = extractvalue { i8, i1 } [[MUL]], 0
6480eb052f6bSPhilip Reames; IND-NEXT:    [[MUL_OVERFLOW:%.*]] = extractvalue { i8, i1 } [[MUL]], 1
648126748bb1SNikita Popov; IND-NEXT:    [[TMP5:%.*]] = icmp slt i8 [[MUL_RESULT]], 0
648226748bb1SNikita Popov; IND-NEXT:    [[TMP6:%.*]] = icmp ugt i8 [[MUL_RESULT]], -128
648326748bb1SNikita Popov; IND-NEXT:    [[TMP7:%.*]] = select i1 [[TMP2]], i1 [[TMP6]], i1 [[TMP5]]
648426748bb1SNikita Popov; IND-NEXT:    [[TMP8:%.*]] = or i1 [[TMP7]], [[MUL_OVERFLOW]]
648526748bb1SNikita Popov; IND-NEXT:    [[TMP9:%.*]] = icmp ugt i64 [[TMP0]], 255
648626748bb1SNikita Popov; IND-NEXT:    [[TMP10:%.*]] = icmp ne i8 [[TMP1]], 0
648726748bb1SNikita Popov; IND-NEXT:    [[TMP11:%.*]] = and i1 [[TMP9]], [[TMP10]]
648826748bb1SNikita Popov; IND-NEXT:    [[TMP12:%.*]] = or i1 [[TMP8]], [[TMP11]]
648926748bb1SNikita Popov; IND-NEXT:    [[TMP13:%.*]] = add i32 [[STEP]], -128
649026748bb1SNikita Popov; IND-NEXT:    [[TMP14:%.*]] = icmp ult i32 [[TMP13]], -256
649126748bb1SNikita Popov; IND-NEXT:    [[TMP15:%.*]] = or i1 [[TMP12]], [[TMP14]]
649226748bb1SNikita Popov; IND-NEXT:    br i1 [[TMP15]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
6493eb052f6bSPhilip Reames; IND:       vector.ph:
6494eb052f6bSPhilip Reames; IND-NEXT:    [[N_VEC:%.*]] = and i64 [[N]], -2
64950c00dbb9SNikita Popov; IND-NEXT:    [[CAST_VTC:%.*]] = trunc i64 [[N_VEC]] to i32
64960c00dbb9SNikita Popov; IND-NEXT:    [[IND_END:%.*]] = mul i32 [[CAST_VTC]], [[STEP]]
6497e6ad9ef4SPhilip Reames; IND-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[STEP]], i64 0
6498eb052f6bSPhilip Reames; IND-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
649926748bb1SNikita Popov; IND-NEXT:    [[TMP16:%.*]] = mul nuw <2 x i32> [[DOTSPLAT]], <i32 0, i32 1>
650026748bb1SNikita Popov; IND-NEXT:    [[TMP17:%.*]] = shl i32 [[STEP]], 1
650126748bb1SNikita Popov; IND-NEXT:    [[DOTSPLATINSERT2:%.*]] = insertelement <2 x i32> poison, i32 [[TMP17]], i64 0
6502eb052f6bSPhilip Reames; IND-NEXT:    [[DOTSPLAT3:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT2]], <2 x i32> poison, <2 x i32> zeroinitializer
6503eb052f6bSPhilip Reames; IND-NEXT:    br label [[VECTOR_BODY:%.*]]
6504eb052f6bSPhilip Reames; IND:       vector.body:
6505eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
6506eb052f6bSPhilip Reames; IND-NEXT:    [[VECTOR_RECUR:%.*]] = phi <2 x i32> [ <i32 poison, i32 0>, [[VECTOR_PH]] ], [ [[VEC_IND:%.*]], [[VECTOR_BODY]] ]
650726748bb1SNikita Popov; IND-NEXT:    [[VEC_IND]] = phi <2 x i32> [ [[TMP16]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
650826748bb1SNikita Popov; IND-NEXT:    [[TMP18:%.*]] = shufflevector <2 x i32> [[VECTOR_RECUR]], <2 x i32> [[VEC_IND]], <2 x i32> <i32 1, i32 2>
650926748bb1SNikita Popov; IND-NEXT:    [[TMP19:%.*]] = getelementptr inbounds i32, i32* [[PTR:%.*]], i64 [[INDEX]]
651026748bb1SNikita Popov; IND-NEXT:    [[TMP20:%.*]] = bitcast i32* [[TMP19]] to <2 x i32>*
651126748bb1SNikita Popov; IND-NEXT:    store <2 x i32> [[TMP18]], <2 x i32>* [[TMP20]], align 4
6512eb052f6bSPhilip Reames; IND-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
6513eb052f6bSPhilip Reames; IND-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], [[DOTSPLAT3]]
651426748bb1SNikita Popov; IND-NEXT:    [[TMP21:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
651526748bb1SNikita Popov; IND-NEXT:    br i1 [[TMP21]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP54:![0-9]+]]
6516eb052f6bSPhilip Reames; IND:       middle.block:
6517eb052f6bSPhilip Reames; IND-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[N]]
6518e6ad9ef4SPhilip Reames; IND-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <2 x i32> [[VEC_IND]], i64 1
6519eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
6520eb052f6bSPhilip Reames; IND:       scalar.ph:
6521eb052f6bSPhilip Reames; IND-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
6522eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[ENTRY]] ], [ [[N_VEC]], [[MIDDLE_BLOCK]] ]
6523eb052f6bSPhilip Reames; IND-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[ENTRY]] ], [ [[IND_END]], [[MIDDLE_BLOCK]] ]
6524eb052f6bSPhilip Reames; IND-NEXT:    br label [[LOOP:%.*]]
6525eb052f6bSPhilip Reames; IND:       loop:
6526eb052f6bSPhilip Reames; IND-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ], [ [[IV_2_CONV:%.*]], [[LOOP]] ]
6527eb052f6bSPhilip Reames; IND-NEXT:    [[IV_1:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_1_NEXT:%.*]], [[LOOP]] ]
6528eb052f6bSPhilip Reames; IND-NEXT:    [[IV_2:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[IV_2_NEXT:%.*]], [[LOOP]] ]
6529eb052f6bSPhilip Reames; IND-NEXT:    [[IV_2_EXT:%.*]] = shl i32 [[IV_2]], 24
6530eb052f6bSPhilip Reames; IND-NEXT:    [[IV_2_CONV]] = ashr exact i32 [[IV_2_EXT]], 24
6531eb052f6bSPhilip Reames; IND-NEXT:    [[GEP:%.*]] = getelementptr inbounds i32, i32* [[PTR]], i64 [[IV_1]]
6532eb052f6bSPhilip Reames; IND-NEXT:    store i32 [[SCALAR_RECUR]], i32* [[GEP]], align 4
6533eb052f6bSPhilip Reames; IND-NEXT:    [[IV_2_NEXT]] = add nsw i32 [[IV_2_CONV]], [[STEP]]
6534eb052f6bSPhilip Reames; IND-NEXT:    [[IV_1_NEXT]] = add nuw nsw i64 [[IV_1]], 1
6535eb052f6bSPhilip Reames; IND-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV_1_NEXT]], [[N]]
6536eb052f6bSPhilip Reames; IND-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP55:![0-9]+]]
6537eb052f6bSPhilip Reames; IND:       exit:
6538eb052f6bSPhilip Reames; IND-NEXT:    ret void
6539eb052f6bSPhilip Reames;
6540eb052f6bSPhilip Reames; UNROLL-LABEL: @test_optimized_cast_induction_feeding_first_order_recurrence(
6541eb052f6bSPhilip Reames; UNROLL-NEXT:  entry:
6542eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N:%.*]], 4
6543eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
6544eb052f6bSPhilip Reames; UNROLL:       vector.scevcheck:
6545eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP0:%.*]] = add i64 [[N]], -1
6546eb052f6bSPhilip Reames; UNROLL-NEXT:    [[TMP1:%.*]] = trunc i32 [[STEP:%.*]] to i8
654726748bb1SNikita Popov; UNROLL-NEXT:    [[TMP2:%.*]] = icmp slt i8 [[TMP1]], 0
654826748bb1SNikita Popov; UNROLL-NEXT:    [[TMP3:%.*]] = call i8 @llvm.abs.i8(i8 [[TMP1]], i1 false)
654926748bb1SNikita Popov; UNROLL-NEXT:    [[TMP4:%.*]] = trunc i64 [[TMP0]] to i8
655026748bb1SNikita Popov; UNROLL-NEXT:    [[MUL:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[TMP3]], i8 [[TMP4]])
6551eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MUL_RESULT:%.*]] = extractvalue { i8, i1 } [[MUL]], 0
6552eb052f6bSPhilip Reames; UNROLL-NEXT:    [[MUL_OVERFLOW:%.*]] = extractvalue { i8, i1 } [[MUL]], 1
655326748bb1SNikita Popov; UNROLL-NEXT:    [[TMP5:%.*]] = icmp slt i8 [[MUL_RESULT]], 0
655426748bb1SNikita Popov; UNROLL-NEXT:    [[TMP6:%.*]] = icmp ugt i8 [[MUL_RESULT]], -128
655526748bb1SNikita Popov; UNROLL-NEXT:    [[TMP7:%.*]] = select i1 [[TMP2]], i1 [[TMP6]], i1 [[TMP5]]
655626748bb1SNikita Popov; UNROLL-NEXT:    [[TMP8:%.*]] = or i1 [[TMP7]], [[MUL_OVERFLOW]]
655726748bb1SNikita Popov; UNROLL-NEXT:    [[TMP9:%.*]] = icmp ugt i64 [[TMP0]], 255
655826748bb1SNikita Popov; UNROLL-NEXT:    [[TMP10:%.*]] = icmp ne i8 [[TMP1]], 0
655926748bb1SNikita Popov; UNROLL-NEXT:    [[TMP11:%.*]] = and i1 [[TMP9]], [[TMP10]]
656026748bb1SNikita Popov; UNROLL-NEXT:    [[TMP12:%.*]] = or i1 [[TMP8]], [[TMP11]]
656126748bb1SNikita Popov; UNROLL-NEXT:    [[TMP13:%.*]] = add i32 [[STEP]], -128
656226748bb1SNikita Popov; UNROLL-NEXT:    [[TMP14:%.*]] = icmp ult i32 [[TMP13]], -256
656326748bb1SNikita Popov; UNROLL-NEXT:    [[TMP15:%.*]] = or i1 [[TMP12]], [[TMP14]]
656426748bb1SNikita Popov; UNROLL-NEXT:    br i1 [[TMP15]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
6565eb052f6bSPhilip Reames; UNROLL:       vector.ph:
6566eb052f6bSPhilip Reames; UNROLL-NEXT:    [[N_VEC:%.*]] = and i64 [[N]], -4
65670c00dbb9SNikita Popov; UNROLL-NEXT:    [[CAST_VTC:%.*]] = trunc i64 [[N_VEC]] to i32
65680c00dbb9SNikita Popov; UNROLL-NEXT:    [[IND_END:%.*]] = mul i32 [[CAST_VTC]], [[STEP]]
6569e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[STEP]], i64 0
6570eb052f6bSPhilip Reames; UNROLL-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
657126748bb1SNikita Popov; UNROLL-NEXT:    [[TMP16:%.*]] = mul nuw <2 x i32> [[DOTSPLAT]], <i32 0, i32 1>
657226748bb1SNikita Popov; UNROLL-NEXT:    [[TMP17:%.*]] = shl i32 [[STEP]], 1
657326748bb1SNikita Popov; UNROLL-NEXT:    [[DOTSPLATINSERT2:%.*]] = insertelement <2 x i32> poison, i32 [[TMP17]], i64 0
6574eb052f6bSPhilip Reames; UNROLL-NEXT:    [[DOTSPLAT3:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT2]], <2 x i32> poison, <2 x i32> zeroinitializer
6575eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[VECTOR_BODY:%.*]]
6576eb052f6bSPhilip Reames; UNROLL:       vector.body:
6577eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
6578eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VECTOR_RECUR:%.*]] = phi <2 x i32> [ <i32 poison, i32 0>, [[VECTOR_PH]] ], [ [[STEP_ADD:%.*]], [[VECTOR_BODY]] ]
657926748bb1SNikita Popov; UNROLL-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[TMP16]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
6580eb052f6bSPhilip Reames; UNROLL-NEXT:    [[STEP_ADD]] = add <2 x i32> [[VEC_IND]], [[DOTSPLAT3]]
658126748bb1SNikita Popov; UNROLL-NEXT:    [[TMP18:%.*]] = shufflevector <2 x i32> [[VECTOR_RECUR]], <2 x i32> [[VEC_IND]], <2 x i32> <i32 1, i32 2>
658226748bb1SNikita Popov; UNROLL-NEXT:    [[TMP19:%.*]] = shufflevector <2 x i32> [[VEC_IND]], <2 x i32> [[STEP_ADD]], <2 x i32> <i32 1, i32 2>
658326748bb1SNikita Popov; UNROLL-NEXT:    [[TMP20:%.*]] = getelementptr inbounds i32, i32* [[PTR:%.*]], i64 [[INDEX]]
658426748bb1SNikita Popov; UNROLL-NEXT:    [[TMP21:%.*]] = bitcast i32* [[TMP20]] to <2 x i32>*
658526748bb1SNikita Popov; UNROLL-NEXT:    store <2 x i32> [[TMP18]], <2 x i32>* [[TMP21]], align 4
658626748bb1SNikita Popov; UNROLL-NEXT:    [[TMP22:%.*]] = getelementptr inbounds i32, i32* [[TMP20]], i64 2
658726748bb1SNikita Popov; UNROLL-NEXT:    [[TMP23:%.*]] = bitcast i32* [[TMP22]] to <2 x i32>*
658826748bb1SNikita Popov; UNROLL-NEXT:    store <2 x i32> [[TMP19]], <2 x i32>* [[TMP23]], align 4
6589eb052f6bSPhilip Reames; UNROLL-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
6590eb052f6bSPhilip Reames; UNROLL-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[STEP_ADD]], [[DOTSPLAT3]]
659126748bb1SNikita Popov; UNROLL-NEXT:    [[TMP24:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
659226748bb1SNikita Popov; UNROLL-NEXT:    br i1 [[TMP24]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP54:![0-9]+]]
6593eb052f6bSPhilip Reames; UNROLL:       middle.block:
6594eb052f6bSPhilip Reames; UNROLL-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[N]]
6595e6ad9ef4SPhilip Reames; UNROLL-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <2 x i32> [[STEP_ADD]], i64 1
6596eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
6597eb052f6bSPhilip Reames; UNROLL:       scalar.ph:
6598eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
6599eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[ENTRY]] ], [ [[N_VEC]], [[MIDDLE_BLOCK]] ]
6600eb052f6bSPhilip Reames; UNROLL-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[ENTRY]] ], [ [[IND_END]], [[MIDDLE_BLOCK]] ]
6601eb052f6bSPhilip Reames; UNROLL-NEXT:    br label [[LOOP:%.*]]
6602eb052f6bSPhilip Reames; UNROLL:       loop:
6603eb052f6bSPhilip Reames; UNROLL-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ], [ [[IV_2_CONV:%.*]], [[LOOP]] ]
6604eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IV_1:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_1_NEXT:%.*]], [[LOOP]] ]
6605eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IV_2:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[IV_2_NEXT:%.*]], [[LOOP]] ]
6606eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IV_2_EXT:%.*]] = shl i32 [[IV_2]], 24
6607eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IV_2_CONV]] = ashr exact i32 [[IV_2_EXT]], 24
6608eb052f6bSPhilip Reames; UNROLL-NEXT:    [[GEP:%.*]] = getelementptr inbounds i32, i32* [[PTR]], i64 [[IV_1]]
6609eb052f6bSPhilip Reames; UNROLL-NEXT:    store i32 [[SCALAR_RECUR]], i32* [[GEP]], align 4
6610eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IV_2_NEXT]] = add nsw i32 [[IV_2_CONV]], [[STEP]]
6611eb052f6bSPhilip Reames; UNROLL-NEXT:    [[IV_1_NEXT]] = add nuw nsw i64 [[IV_1]], 1
6612eb052f6bSPhilip Reames; UNROLL-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV_1_NEXT]], [[N]]
6613eb052f6bSPhilip Reames; UNROLL-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP55:![0-9]+]]
6614eb052f6bSPhilip Reames; UNROLL:       exit:
6615eb052f6bSPhilip Reames; UNROLL-NEXT:    ret void
6616eb052f6bSPhilip Reames;
6617eb052f6bSPhilip Reames; UNROLL-NO-IC-LABEL: @test_optimized_cast_induction_feeding_first_order_recurrence(
6618eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:  entry:
6619eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N:%.*]], 4
6620eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
6621eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.scevcheck:
6622eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP0:%.*]] = add i64 [[N]], -1
6623eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP1:%.*]] = trunc i32 [[STEP:%.*]] to i8
6624eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP2:%.*]] = sub i8 0, [[TMP1]]
6625eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP3:%.*]] = icmp slt i8 [[TMP1]], 0
6626eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP4:%.*]] = select i1 [[TMP3]], i8 [[TMP2]], i8 [[TMP1]]
6627eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP5:%.*]] = trunc i64 [[TMP0]] to i8
6628eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MUL:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[TMP4]], i8 [[TMP5]])
6629eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MUL_RESULT:%.*]] = extractvalue { i8, i1 } [[MUL]], 0
6630eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[MUL_OVERFLOW:%.*]] = extractvalue { i8, i1 } [[MUL]], 1
66317c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP6:%.*]] = sub i8 0, [[MUL_RESULT]]
66327c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP7:%.*]] = icmp slt i8 [[MUL_RESULT]], 0
66337c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP8:%.*]] = icmp sgt i8 [[TMP6]], 0
66347c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP9:%.*]] = select i1 [[TMP3]], i1 [[TMP8]], i1 [[TMP7]]
66357c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP10:%.*]] = or i1 [[TMP9]], [[MUL_OVERFLOW]]
6636eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP11:%.*]] = icmp ugt i64 [[TMP0]], 255
6637eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP12:%.*]] = icmp ne i8 [[TMP1]], 0
6638eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP13:%.*]] = and i1 [[TMP11]], [[TMP12]]
66397c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP14:%.*]] = or i1 [[TMP10]], [[TMP13]]
66407c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP15:%.*]] = sext i8 [[TMP1]] to i32
66417c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[IDENT_CHECK:%.*]] = icmp ne i32 [[STEP]], [[TMP15]]
66427c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP16:%.*]] = or i1 [[TMP14]], [[IDENT_CHECK]]
66437c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP16]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
6644eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.ph:
6645eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[N]], 4
6646eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[N_VEC:%.*]] = sub i64 [[N]], [[N_MOD_VF]]
66470c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[CAST_VTC:%.*]] = trunc i64 [[N_VEC]] to i32
66480c00dbb9SNikita Popov; UNROLL-NO-IC-NEXT:    [[IND_END:%.*]] = mul i32 [[CAST_VTC]], [[STEP]]
6649eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[STEP]], i32 0
6650eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
66517c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP17:%.*]] = mul <2 x i32> <i32 0, i32 1>, [[DOTSPLAT]]
66527c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[INDUCTION:%.*]] = add <2 x i32> zeroinitializer, [[TMP17]]
66537c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP18:%.*]] = mul i32 [[STEP]], 2
66547c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[DOTSPLATINSERT2:%.*]] = insertelement <2 x i32> poison, i32 [[TMP18]], i32 0
6655eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[DOTSPLAT3:%.*]] = shufflevector <2 x i32> [[DOTSPLATINSERT2]], <2 x i32> poison, <2 x i32> zeroinitializer
6656eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[VECTOR_BODY:%.*]]
6657eb052f6bSPhilip Reames; UNROLL-NO-IC:       vector.body:
6658eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
6659eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VECTOR_RECUR:%.*]] = phi <2 x i32> [ <i32 poison, i32 0>, [[VECTOR_PH]] ], [ [[STEP_ADD:%.*]], [[VECTOR_BODY]] ]
6660eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND:%.*]] = phi <2 x i32> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
6661b3e8ace1SFlorian Hahn; UNROLL-NO-IC-NEXT:    [[STEP_ADD]] = add <2 x i32> [[VEC_IND]], [[DOTSPLAT3]]
66627c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP19:%.*]] = add i64 [[INDEX]], 0
66637c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP20:%.*]] = add i64 [[INDEX]], 2
66647c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP21:%.*]] = shufflevector <2 x i32> [[VECTOR_RECUR]], <2 x i32> [[VEC_IND]], <2 x i32> <i32 1, i32 2>
66657c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP22:%.*]] = shufflevector <2 x i32> [[VEC_IND]], <2 x i32> [[STEP_ADD]], <2 x i32> <i32 1, i32 2>
66667c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP23:%.*]] = getelementptr inbounds i32, i32* [[PTR:%.*]], i64 [[TMP19]]
66677c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP24:%.*]] = getelementptr inbounds i32, i32* [[PTR]], i64 [[TMP20]]
66687c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP25:%.*]] = getelementptr inbounds i32, i32* [[TMP23]], i32 0
66697c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP26:%.*]] = bitcast i32* [[TMP25]] to <2 x i32>*
66707c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[TMP21]], <2 x i32>* [[TMP26]], align 4
66717c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP27:%.*]] = getelementptr inbounds i32, i32* [[TMP23]], i32 2
6672eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[TMP28:%.*]] = bitcast i32* [[TMP27]] to <2 x i32>*
66737c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    store <2 x i32> [[TMP22]], <2 x i32>* [[TMP28]], align 4
6674eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
6675eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VEC_IND_NEXT]] = add <2 x i32> [[STEP_ADD]], [[DOTSPLAT3]]
66767c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    [[TMP29:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
66777c080e46SNikita Popov; UNROLL-NO-IC-NEXT:    br i1 [[TMP29]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP54:![0-9]+]]
6678eb052f6bSPhilip Reames; UNROLL-NO-IC:       middle.block:
6679eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]]
6680eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <2 x i32> [[STEP_ADD]], i32 1
6681eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[VECTOR_RECUR_EXTRACT_FOR_PHI:%.*]] = extractelement <2 x i32> [[STEP_ADD]], i32 0
6682eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
6683eb052f6bSPhilip Reames; UNROLL-NO-IC:       scalar.ph:
6684eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
6685eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
6686eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
6687eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br label [[LOOP:%.*]]
6688eb052f6bSPhilip Reames; UNROLL-NO-IC:       loop:
6689eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ], [ [[IV_2_CONV:%.*]], [[LOOP]] ]
6690eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IV_1:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_1_NEXT:%.*]], [[LOOP]] ]
6691eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IV_2:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[IV_2_NEXT:%.*]], [[LOOP]] ]
6692eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IV_2_EXT:%.*]] = shl i32 [[IV_2]], 24
6693eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IV_2_CONV]] = ashr exact i32 [[IV_2_EXT]], 24
6694eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[GEP:%.*]] = getelementptr inbounds i32, i32* [[PTR]], i64 [[IV_1]]
6695eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    store i32 [[SCALAR_RECUR]], i32* [[GEP]], align 4
6696eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IV_2_NEXT]] = add nsw i32 [[IV_2_CONV]], [[STEP]]
6697eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[IV_1_NEXT]] = add nuw nsw i64 [[IV_1]], 1
6698eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV_1_NEXT]], [[N]]
6699eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP55:![0-9]+]]
6700eb052f6bSPhilip Reames; UNROLL-NO-IC:       exit:
6701eb052f6bSPhilip Reames; UNROLL-NO-IC-NEXT:    ret void
6702eb052f6bSPhilip Reames;
6703eb052f6bSPhilip Reames; INTERLEAVE-LABEL: @test_optimized_cast_induction_feeding_first_order_recurrence(
6704eb052f6bSPhilip Reames; INTERLEAVE-NEXT:  entry:
6705eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N:%.*]], 8
6706eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
6707eb052f6bSPhilip Reames; INTERLEAVE:       vector.scevcheck:
6708eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP0:%.*]] = add i64 [[N]], -1
6709eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[TMP1:%.*]] = trunc i32 [[STEP:%.*]] to i8
671026748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP2:%.*]] = icmp slt i8 [[TMP1]], 0
671126748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP3:%.*]] = call i8 @llvm.abs.i8(i8 [[TMP1]], i1 false)
671226748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP4:%.*]] = trunc i64 [[TMP0]] to i8
671326748bb1SNikita Popov; INTERLEAVE-NEXT:    [[MUL:%.*]] = call { i8, i1 } @llvm.umul.with.overflow.i8(i8 [[TMP3]], i8 [[TMP4]])
6714eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MUL_RESULT:%.*]] = extractvalue { i8, i1 } [[MUL]], 0
6715eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[MUL_OVERFLOW:%.*]] = extractvalue { i8, i1 } [[MUL]], 1
671626748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP5:%.*]] = icmp slt i8 [[MUL_RESULT]], 0
671726748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP6:%.*]] = icmp ugt i8 [[MUL_RESULT]], -128
671826748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP7:%.*]] = select i1 [[TMP2]], i1 [[TMP6]], i1 [[TMP5]]
671926748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP8:%.*]] = or i1 [[TMP7]], [[MUL_OVERFLOW]]
672026748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP9:%.*]] = icmp ugt i64 [[TMP0]], 255
672126748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP10:%.*]] = icmp ne i8 [[TMP1]], 0
672226748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP11:%.*]] = and i1 [[TMP9]], [[TMP10]]
672326748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP12:%.*]] = or i1 [[TMP8]], [[TMP11]]
672426748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP13:%.*]] = add i32 [[STEP]], -128
672526748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP14:%.*]] = icmp ult i32 [[TMP13]], -256
672626748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP15:%.*]] = or i1 [[TMP12]], [[TMP14]]
672726748bb1SNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP15]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
6728eb052f6bSPhilip Reames; INTERLEAVE:       vector.ph:
6729eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[N_VEC:%.*]] = and i64 [[N]], -8
67300c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[CAST_VTC:%.*]] = trunc i64 [[N_VEC]] to i32
67310c00dbb9SNikita Popov; INTERLEAVE-NEXT:    [[IND_END:%.*]] = mul i32 [[CAST_VTC]], [[STEP]]
6732e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[STEP]], i64 0
6733eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <4 x i32> [[DOTSPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
673426748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP16:%.*]] = mul <4 x i32> [[DOTSPLAT]], <i32 0, i32 1, i32 2, i32 3>
673526748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP17:%.*]] = shl i32 [[STEP]], 2
673626748bb1SNikita Popov; INTERLEAVE-NEXT:    [[DOTSPLATINSERT2:%.*]] = insertelement <4 x i32> poison, i32 [[TMP17]], i64 0
6737eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[DOTSPLAT3:%.*]] = shufflevector <4 x i32> [[DOTSPLATINSERT2]], <4 x i32> poison, <4 x i32> zeroinitializer
6738eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[VECTOR_BODY:%.*]]
6739eb052f6bSPhilip Reames; INTERLEAVE:       vector.body:
6740eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
6741eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VECTOR_RECUR:%.*]] = phi <4 x i32> [ <i32 poison, i32 poison, i32 poison, i32 0>, [[VECTOR_PH]] ], [ [[STEP_ADD:%.*]], [[VECTOR_BODY]] ]
674226748bb1SNikita Popov; INTERLEAVE-NEXT:    [[VEC_IND:%.*]] = phi <4 x i32> [ [[TMP16]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
6743eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[STEP_ADD]] = add <4 x i32> [[VEC_IND]], [[DOTSPLAT3]]
674426748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP18:%.*]] = shufflevector <4 x i32> [[VECTOR_RECUR]], <4 x i32> [[VEC_IND]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
674526748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP19:%.*]] = shufflevector <4 x i32> [[VEC_IND]], <4 x i32> [[STEP_ADD]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
674626748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP20:%.*]] = getelementptr inbounds i32, i32* [[PTR:%.*]], i64 [[INDEX]]
674726748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP21:%.*]] = bitcast i32* [[TMP20]] to <4 x i32>*
674826748bb1SNikita Popov; INTERLEAVE-NEXT:    store <4 x i32> [[TMP18]], <4 x i32>* [[TMP21]], align 4
674926748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP22:%.*]] = getelementptr inbounds i32, i32* [[TMP20]], i64 4
675026748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP23:%.*]] = bitcast i32* [[TMP22]] to <4 x i32>*
675126748bb1SNikita Popov; INTERLEAVE-NEXT:    store <4 x i32> [[TMP19]], <4 x i32>* [[TMP23]], align 4
6752eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
6753eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[VEC_IND_NEXT]] = add <4 x i32> [[STEP_ADD]], [[DOTSPLAT3]]
675426748bb1SNikita Popov; INTERLEAVE-NEXT:    [[TMP24:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
675526748bb1SNikita Popov; INTERLEAVE-NEXT:    br i1 [[TMP24]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP54:![0-9]+]]
6756eb052f6bSPhilip Reames; INTERLEAVE:       middle.block:
6757eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[N]]
6758e6ad9ef4SPhilip Reames; INTERLEAVE-NEXT:    [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <4 x i32> [[STEP_ADD]], i64 3
6759eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
6760eb052f6bSPhilip Reames; INTERLEAVE:       scalar.ph:
6761eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[ENTRY:%.*]] ], [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ]
6762eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[ENTRY]] ], [ [[N_VEC]], [[MIDDLE_BLOCK]] ]
6763eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[BC_RESUME_VAL1:%.*]] = phi i32 [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[ENTRY]] ], [ [[IND_END]], [[MIDDLE_BLOCK]] ]
6764eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br label [[LOOP:%.*]]
6765eb052f6bSPhilip Reames; INTERLEAVE:       loop:
6766eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[SCALAR_RECUR:%.*]] = phi i32 [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ], [ [[IV_2_CONV:%.*]], [[LOOP]] ]
6767eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IV_1:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_1_NEXT:%.*]], [[LOOP]] ]
6768eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IV_2:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[IV_2_NEXT:%.*]], [[LOOP]] ]
6769eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IV_2_EXT:%.*]] = shl i32 [[IV_2]], 24
6770eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IV_2_CONV]] = ashr exact i32 [[IV_2_EXT]], 24
6771eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[GEP:%.*]] = getelementptr inbounds i32, i32* [[PTR]], i64 [[IV_1]]
6772eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    store i32 [[SCALAR_RECUR]], i32* [[GEP]], align 4
6773eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IV_2_NEXT]] = add nsw i32 [[IV_2_CONV]], [[STEP]]
6774eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[IV_1_NEXT]] = add nuw nsw i64 [[IV_1]], 1
6775eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV_1_NEXT]], [[N]]
6776eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    br i1 [[EXITCOND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP55:![0-9]+]]
6777eb052f6bSPhilip Reames; INTERLEAVE:       exit:
6778eb052f6bSPhilip Reames; INTERLEAVE-NEXT:    ret void
6779505ad03cSFlorian Hahn;
6780505ad03cSFlorian Hahnentry:
6781505ad03cSFlorian Hahn  br label %loop
6782505ad03cSFlorian Hahn
6783505ad03cSFlorian Hahnloop:
6784505ad03cSFlorian Hahn  %for = phi i32 [ 0, %entry ], [ %iv.2.conv, %loop ]
6785505ad03cSFlorian Hahn  %iv.1 = phi i64 [ 0, %entry ], [ %iv.1.next, %loop ]
6786505ad03cSFlorian Hahn  %iv.2 = phi i32 [ 0, %entry ], [ %iv.2.next, %loop ]
6787505ad03cSFlorian Hahn  %iv.2.ext = shl i32 %iv.2, 24
6788505ad03cSFlorian Hahn  %iv.2.conv = ashr exact i32 %iv.2.ext, 24
6789505ad03cSFlorian Hahn  %gep = getelementptr inbounds i32, i32* %ptr, i64 %iv.1
6790505ad03cSFlorian Hahn  store i32 %for, i32* %gep, align 4
6791505ad03cSFlorian Hahn  %iv.2.next = add nsw i32 %iv.2.conv, %step
6792505ad03cSFlorian Hahn  %iv.1.next = add nuw nsw i64 %iv.1, 1
6793505ad03cSFlorian Hahn  %exitcond = icmp eq i64 %iv.1.next, %n
6794505ad03cSFlorian Hahn  br i1 %exitcond, label %exit, label %loop
6795505ad03cSFlorian Hahn
6796505ad03cSFlorian Hahnexit:
6797505ad03cSFlorian Hahn  ret void
6798505ad03cSFlorian Hahn}
6799