1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -loop-reduce -S | FileCheck %s
4 target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
5 target triple = "riscv64"
8 define void @test1(ptr %a) {
11 ; CHECK-NEXT: [[SCEVGEP2:%.*]] = getelementptr i8, ptr [[A:%.*]], i64 128000
12 ; CHECK-NEXT: br label [[LOOP:%.*]]
14 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi ptr [ [[SCEVGEP:%.*]], [[LOOP]] ], [ [[A]], [[ENTRY:%.*]] ]
15 ; CHECK-NEXT: store float 1.000000e+00, ptr [[LSR_IV1]], align 4
16 ; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, ptr [[LSR_IV1]], i64 4
17 ; CHECK-NEXT: [[LSR_FOLD_TERM_COND_REPLACED_TERM_COND:%.*]] = icmp eq ptr [[SCEVGEP]], [[SCEVGEP2]]
18 ; CHECK-NEXT: br i1 [[LSR_FOLD_TERM_COND_REPLACED_TERM_COND]], label [[EXIT:%.*]], label [[LOOP]]
20 ; CHECK-NEXT: ret void
25 loop: ; preds = %loop, %entry
26 %t15 = phi i64 [ 0, %entry ], [ %t20, %loop ]
27 %t19 = getelementptr inbounds [32000 x float], ptr %a, i64 0, i64 %t15
28 store float 1.0, ptr %t19, align 4
29 %t20 = add nuw nsw i64 %t15, 1
30 %t21 = icmp eq i64 %t20, 32000
31 br i1 %t21, label %exit, label %loop
37 ; Same as test1, but with a use of a added outside the loop
38 define void @test2(ptr %a) {
39 ; CHECK-LABEL: @test2(
41 ; CHECK-NEXT: [[SCEVGEP2:%.*]] = getelementptr i8, ptr [[A:%.*]], i64 128000
42 ; CHECK-NEXT: br label [[LOOP:%.*]]
44 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi ptr [ [[SCEVGEP:%.*]], [[LOOP]] ], [ [[A]], [[ENTRY:%.*]] ]
45 ; CHECK-NEXT: store float 1.000000e+00, ptr [[LSR_IV1]], align 4
46 ; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, ptr [[LSR_IV1]], i64 4
47 ; CHECK-NEXT: [[LSR_FOLD_TERM_COND_REPLACED_TERM_COND:%.*]] = icmp eq ptr [[SCEVGEP]], [[SCEVGEP2]]
48 ; CHECK-NEXT: br i1 [[LSR_FOLD_TERM_COND_REPLACED_TERM_COND]], label [[EXIT:%.*]], label [[LOOP]]
50 ; CHECK-NEXT: call void @use(ptr [[A]])
51 ; CHECK-NEXT: ret void
56 loop: ; preds = %loop, %entry
57 %t15 = phi i64 [ 0, %entry ], [ %t20, %loop ]
58 %t19 = getelementptr inbounds [32000 x float], ptr %a, i64 0, i64 %t15
59 store float 1.0, ptr %t19, align 4
60 %t20 = add nuw nsw i64 %t15, 1
61 %t21 = icmp eq i64 %t20, 32000
62 br i1 %t21, label %exit, label %loop
65 call void @use(ptr %a)
70 define void @test3(ptr %a, ptr %b) {
71 ; CHECK-LABEL: @test3(
73 ; CHECK-NEXT: [[SCEVGEP4:%.*]] = getelementptr i8, ptr [[B:%.*]], i64 128000
74 ; CHECK-NEXT: br label [[LOOP:%.*]]
76 ; CHECK-NEXT: [[LSR_IV2:%.*]] = phi ptr [ [[SCEVGEP3:%.*]], [[LOOP]] ], [ [[A:%.*]], [[ENTRY:%.*]] ]
77 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi ptr [ [[SCEVGEP:%.*]], [[LOOP]] ], [ [[B]], [[ENTRY]] ]
78 ; CHECK-NEXT: [[T17:%.*]] = load float, ptr [[LSR_IV2]], align 4
79 ; CHECK-NEXT: [[T18:%.*]] = fadd float [[T17]], 1.000000e+00
80 ; CHECK-NEXT: store float [[T18]], ptr [[LSR_IV1]], align 4
81 ; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, ptr [[LSR_IV1]], i64 4
82 ; CHECK-NEXT: [[SCEVGEP3]] = getelementptr i8, ptr [[LSR_IV2]], i64 4
83 ; CHECK-NEXT: [[LSR_FOLD_TERM_COND_REPLACED_TERM_COND:%.*]] = icmp eq ptr [[SCEVGEP]], [[SCEVGEP4]]
84 ; CHECK-NEXT: br i1 [[LSR_FOLD_TERM_COND_REPLACED_TERM_COND]], label [[EXIT:%.*]], label [[LOOP]]
86 ; CHECK-NEXT: ret void
91 loop: ; preds = %loop, %entry
92 %t15 = phi i64 [ 0, %entry ], [ %t20, %loop ]
93 %t16 = getelementptr inbounds [32000 x float], ptr %a, i64 0, i64 %t15
94 %t17 = load float, ptr %t16, align 4
95 %t18 = fadd float %t17, 1.000000e+00
96 %t19 = getelementptr inbounds [32000 x float], ptr %b, i64 0, i64 %t15
97 store float %t18, ptr %t19, align 4
98 %t20 = add nuw nsw i64 %t15, 1
99 %t21 = icmp eq i64 %t20, 32000
100 br i1 %t21, label %exit, label %loop
102 exit: ; preds = %loop
106 ; Same as test3, but with a use of both a and b outside the loop
107 define void @test4(ptr %a, ptr %b) {
108 ; CHECK-LABEL: @test4(
110 ; CHECK-NEXT: [[SCEVGEP4:%.*]] = getelementptr i8, ptr [[B:%.*]], i64 128000
111 ; CHECK-NEXT: br label [[LOOP:%.*]]
113 ; CHECK-NEXT: [[LSR_IV2:%.*]] = phi ptr [ [[SCEVGEP3:%.*]], [[LOOP]] ], [ [[A:%.*]], [[ENTRY:%.*]] ]
114 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi ptr [ [[SCEVGEP:%.*]], [[LOOP]] ], [ [[B]], [[ENTRY]] ]
115 ; CHECK-NEXT: [[T17:%.*]] = load float, ptr [[LSR_IV2]], align 4
116 ; CHECK-NEXT: [[T18:%.*]] = fadd float [[T17]], 1.000000e+00
117 ; CHECK-NEXT: store float [[T18]], ptr [[LSR_IV1]], align 4
118 ; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, ptr [[LSR_IV1]], i64 4
119 ; CHECK-NEXT: [[SCEVGEP3]] = getelementptr i8, ptr [[LSR_IV2]], i64 4
120 ; CHECK-NEXT: [[LSR_FOLD_TERM_COND_REPLACED_TERM_COND:%.*]] = icmp eq ptr [[SCEVGEP]], [[SCEVGEP4]]
121 ; CHECK-NEXT: br i1 [[LSR_FOLD_TERM_COND_REPLACED_TERM_COND]], label [[EXIT:%.*]], label [[LOOP]]
123 ; CHECK-NEXT: call void @use(ptr [[A]])
124 ; CHECK-NEXT: call void @use(ptr [[B]])
125 ; CHECK-NEXT: ret void
130 loop: ; preds = %loop, %entry
131 %t15 = phi i64 [ 0, %entry ], [ %t20, %loop ]
132 %t16 = getelementptr inbounds [32000 x float], ptr %a, i64 0, i64 %t15
133 %t17 = load float, ptr %t16, align 4
134 %t18 = fadd float %t17, 1.000000e+00
135 %t19 = getelementptr inbounds [32000 x float], ptr %b, i64 0, i64 %t15
136 store float %t18, ptr %t19, align 4
137 %t20 = add nuw nsw i64 %t15, 1
138 %t21 = icmp eq i64 %t20, 32000
139 br i1 %t21, label %exit, label %loop
141 exit: ; preds = %loop
142 call void @use(ptr %a)
143 call void @use(ptr %b)
147 declare void @use(ptr)