1 ; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -dce -instcombine -S | FileCheck %s
3 target 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"
5 ; PR15882: This test ensures that we do not produce wrapping arithmetic when
6 ; creating constant reverse step vectors.
8 ; int foo(int n, int *A) {
10 ; for (int i=n; i > 0; i--)
17 ;CHECK: <i32 0, i32 -1, i32 -2, i32 -3>
19 define i32 @foo(i32 %n, i32* nocapture %A) {
20 %1 = icmp sgt i32 %n, 0
21 br i1 %1, label %.lr.ph, label %._crit_edge
24 %2 = sext i32 %n to i64
27 ; <label>:3 ; preds = %.lr.ph, %3
28 %indvars.iv = phi i64 [ %2, %.lr.ph ], [ %indvars.iv.next, %3 ]
29 %sum.01 = phi i32 [ undef, %.lr.ph ], [ %9, %3 ]
30 %4 = trunc i64 %indvars.iv to i32
31 %5 = shl nsw i32 %4, 1
32 %6 = sext i32 %5 to i64
33 %7 = getelementptr inbounds i32, i32* %A, i64 %6
34 %8 = load i32, i32* %7, align 4
35 %9 = add nsw i32 %8, %sum.01
36 %indvars.iv.next = add i64 %indvars.iv, -1
37 %10 = trunc i64 %indvars.iv.next to i32
38 %11 = icmp sgt i32 %10, 0
39 br i1 %11, label %3, label %._crit_edge
41 ._crit_edge: ; preds = %3, %0
42 %sum.0.lcssa = phi i32 [ undef, %0 ], [ %9, %3 ]