[ValueTracking] test trunc to i1 as condition in dominating condition. (NFC)
[llvm-project.git] / llvm / test / Transforms / LoopVectorize / induction-unroll-novec.ll
blobbfc9e716fc9b896acca130f9c55b2db7691f1d45
1 ; RUN: opt -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 -S %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"
6 ; Test for PR54427.
7 define void @test_nonconst_start_and_step(ptr %dst, i32 %start, i32 %step, i64 %N) {
8 ; CHECK-LABEL: @test_nonconst_start_and_step(
9 ; CHECK:         [[NEG_STEP:%.+]] = sub i32 0, %step
10 ; CHECK:       vector.body:
11 ; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
12 ; CHECK-NEXT:    [[INDUCTION3:%.*]] = add i64 [[INDEX]], 0
13 ; CHECK-NEXT:    [[INDUCTION4:%.*]] = add i64 [[INDEX]], 1
14 ; CHECK-NEXT:    [[TMP2:%.*]] = trunc i64 [[INDEX]] to i32
15 ; CHECK-NEXT:    [[TMP3:%.*]] = mul i32 [[TMP2]], [[NEG_STEP]]
16 ; CHECK-NEXT:    [[OFFSET_IDX:%.*]] = add i32 %start, [[TMP3]]
17 ; CHECK-NEXT:    [[TMP4:%.*]] = mul i32 0, [[NEG_STEP]]
18 ; CHECK-NEXT:    [[INDUCTION:%.*]] = add i32 [[OFFSET_IDX]], [[TMP4]]
19 ; CHECK-NEXT:    [[TMP5:%.*]] = mul i32 1, [[NEG_STEP]]
20 ; CHECK-NEXT:    [[INDUCTION2:%.*]] = add i32 [[OFFSET_IDX]], [[TMP5]]
21 ; CHECK-NEXT:    [[TMP6:%.*]] = sub nsw i32 [[INDUCTION]], %step
22 ; CHECK-NEXT:    [[TMP7:%.*]] = sub nsw i32 [[INDUCTION2]], %step
23 ; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds i32, ptr [[DST:%.*]], i64 [[INDUCTION3]]
24 ; CHECK-NEXT:    [[TMP9:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 [[INDUCTION4]]
25 ; CHECK-NEXT:    store i32 [[TMP6]], ptr [[TMP8]], align 2
26 ; CHECK-NEXT:    store i32 [[TMP7]], ptr [[TMP9]], align 2
27 ; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
28 ; CHECK-NEXT:    [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]]
29 ; CHECK-NEXT:    br i1 [[TMP10]], label %middle.block, label %vector.body
31 entry:
32   br label %loop
34 loop:
35   %primary.iv = phi i64 [ 0, %entry ], [ %primary.iv.next, %loop ]
36   %iv.down = phi i32 [ %start, %entry ], [ %iv.down.next, %loop ]
37   %iv.down.next = sub nsw i32 %iv.down, %step
38   %gep.dst = getelementptr inbounds i32, ptr %dst, i64 %primary.iv
39   store i32 %iv.down.next, ptr %gep.dst, align 2
40   %primary.iv.next = add nuw nsw i64 %primary.iv, 1
41   %exitcond = icmp eq i64 %primary.iv.next, %N
42   br i1 %exitcond, label %exit, label %loop
44 exit:
45   ret void