1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=loop-rotate -verify-memoryssa < %s | FileCheck %s
3 ; RUN: opt -S -passes='require<targetir>,require<assumptions>,loop(loop-rotate)' < %s | FileCheck %s
5 ; Demonstrate handling of invalid costs in LoopRotate. This test uses
6 ; scalable vectors on RISCV w/o +V to create a situation where a construct
7 ; can not be lowered, and is thus invalid regardless of what the target
8 ; does or does not implement in terms of a cost model.
10 target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
11 target triple = "riscv64-unknown-unknown"
13 define void @valid() nounwind ssp {
14 ; CHECK-LABEL: @valid(
16 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
18 ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_COND]] ]
19 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_0]], 100
20 ; CHECK-NEXT: [[INC]] = add nsw i32 [[I_0]], 1
21 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_COND]], label [[FOR_END:%.*]]
23 ; CHECK-NEXT: ret void
28 for.cond: ; preds = %for.body, %entry
29 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
30 %cmp = icmp slt i32 %i.0, 100
31 br i1 %cmp, label %for.body, label %for.end
34 for.body: ; preds = %for.cond
35 %inc = add nsw i32 %i.0, 1
38 for.end: ; preds = %for.cond
42 ; Despite having an invalid cost, we can rotate this because we don't
43 ; need to duplicate any instructions or execute them more frequently.
44 define void @invalid_no_dup(ptr %p) nounwind ssp {
45 ; CHECK-LABEL: @invalid_no_dup(
47 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
49 ; CHECK-NEXT: [[I_01:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
50 ; CHECK-NEXT: [[A:%.*]] = load <vscale x 1 x i8>, ptr [[P:%.*]], align 1
51 ; CHECK-NEXT: [[B:%.*]] = add <vscale x 1 x i8> [[A]], [[A]]
52 ; CHECK-NEXT: store <vscale x 1 x i8> [[B]], ptr [[P]], align 1
53 ; CHECK-NEXT: [[INC]] = add nsw i32 [[I_01]], 1
54 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], 100
55 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
57 ; CHECK-NEXT: ret void
62 for.cond: ; preds = %for.body, %entry
63 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
64 %cmp = icmp slt i32 %i.0, 100
65 br i1 %cmp, label %for.body, label %for.end
68 for.body: ; preds = %for.cond
69 %a = load <vscale x 1 x i8>, ptr %p
70 %b = add <vscale x 1 x i8> %a, %a
71 store <vscale x 1 x i8> %b, ptr %p
72 %inc = add nsw i32 %i.0, 1
75 for.end: ; preds = %for.cond
79 ; This demonstrates a case where a) loop rotate needs a cost estimate to
80 ; know if rotation is profitable, and b) there is no cost estimate available
81 ; due to invalid costs in the loop. We can't rotate this loop.
82 define void @invalid_dup_required(ptr %p) nounwind ssp {
83 ; CHECK-LABEL: @invalid_dup_required(
85 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
87 ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_BODY:%.*]] ]
88 ; CHECK-NEXT: [[A:%.*]] = load <vscale x 1 x i8>, ptr [[P:%.*]], align 1
89 ; CHECK-NEXT: [[B:%.*]] = add <vscale x 1 x i8> [[A]], [[A]]
90 ; CHECK-NEXT: store <vscale x 1 x i8> [[B]], ptr [[P]], align 1
91 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_0]], 100
92 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
94 ; CHECK-NEXT: call void @f()
95 ; CHECK-NEXT: [[INC]] = add nsw i32 [[I_0]], 1
96 ; CHECK-NEXT: br label [[FOR_COND]]
98 ; CHECK-NEXT: ret void
103 for.cond: ; preds = %for.body, %entry
104 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
105 %a = load <vscale x 1 x i8>, ptr %p
106 %b = add <vscale x 1 x i8> %a, %a
107 store <vscale x 1 x i8> %b, ptr %p
108 %cmp = icmp slt i32 %i.0, 100
109 br i1 %cmp, label %for.body, label %for.end
112 for.body: ; preds = %for.cond
114 %inc = add nsw i32 %i.0, 1
117 for.end: ; preds = %for.cond