3 ; RUN: opt -mtriple arm64-linux -passes=loop-vectorize -mattr=+sve -debug-only=loop-vectorize -disable-output <%s 2>&1 | FileCheck %s
5 ; Invariant register usage calculation should take into account if the
6 ; invariant would be used in widened instructions. Only in such cases, a vector
7 ; register would be required for holding the invariant. For all other cases
8 ; such as below(where usage of %0 in loop doesnt require vector register), a
9 ; general purpose register suffices.
10 ; Check that below test doesn't crash while calculating register usage for
13 @string = internal unnamed_addr constant [5 x i8] c"abcd\00", align 1
14 define void @get_invariant_reg_usage(ptr %z) {
15 ; CHECK: LV: Checking a loop in 'get_invariant_reg_usage'
16 ; CHECK: LV(REG): VF = vscale x 16
17 ; CHECK-NEXT: LV(REG): Found max usage: 1 item
18 ; CHECK-NEXT: LV(REG): RegisterClass: Generic::ScalarRC, 3 registers
19 ; CHECK-NEXT: LV(REG): Found invariant usage: 2 item
20 ; CHECK-NEXT: LV(REG): RegisterClass: Generic::ScalarRC, 2 registers
21 ; CHECK-NEXT: LV(REG): RegisterClass: Generic::VectorRC, 8 registers
24 %0 = load i128, ptr %z, align 16
25 %1 = icmp slt i128 %0, 1
26 %a = getelementptr i8, ptr %z, i64 1
27 br i1 %1, label %return, label %loopbody
29 loopbody: ;preds = %L.entry, %loopbody
30 %b = phi ptr [ %2, %loopbody ], [ @string, %L.entry ]
31 %len_input = phi i128 [ %len, %loopbody ], [ %0, %L.entry ]
32 %len = add nsw i128 %len_input, -1
33 %2 = getelementptr i8, ptr %b, i64 1
34 %3 = load i8, ptr %b, align 1
35 store i8 %3, ptr %a, align 4
36 %.not = icmp eq i128 %len, 0
37 br i1 %.not, label %return, label %loopbody
39 return: ;preds = %loopexit, %L.entry