310 lines · plain
1; RUN: opt -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s2 3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"4target triple = "x86_64-unknown-linux-gnu"5 6define void @f_sadd_0(ptr %a) {7; CHECK-LABEL: Classifying expressions for: @f_sadd_08entry:9 br label %for.body10 11for.cond.cleanup: ; preds = %cont12 ret void13 14for.body: ; preds = %entry, %cont15; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]16; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.body> U: [0,16) S: [0,16)17 18 %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]19 %idxprom = sext i32 %i.04 to i6420 %arrayidx = getelementptr inbounds i8, ptr %a, i64 %idxprom21 store i8 0, ptr %arrayidx, align 122 %tmp0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)23 %tmp1 = extractvalue { i32, i1 } %tmp0, 124 br i1 %tmp1, label %trap, label %cont, !nosanitize !{}25 26trap: ; preds = %for.body27 tail call void @llvm.trap() #2, !nosanitize !{}28 unreachable, !nosanitize !{}29 30cont: ; preds = %for.body31 %tmp2 = extractvalue { i32, i1 } %tmp0, 032 %cmp = icmp slt i32 %tmp2, 1633 br i1 %cmp, label %for.body, label %for.cond.cleanup34; CHECK: Loop %for.body: constant max backedge-taken count is i32 1535}36 37define void @f_sadd_1(ptr %a) {38; CHECK-LABEL: Classifying expressions for: @f_sadd_139entry:40 br label %for.body41 42for.cond.cleanup: ; preds = %cont43 ret void44 45for.body: ; preds = %entry, %cont46; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]47; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.body> U: [0,16) S: [0,16)48 49; SCEV can prove <nsw> for the above induction variable; but it does50; not bother so before it sees the sext below since it is not a 100%51; obvious.52 53 %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]54 %idxprom = sext i32 %i.04 to i6455 %arrayidx = getelementptr inbounds i8, ptr %a, i64 %idxprom56 store i8 0, ptr %arrayidx, align 157 %tmp0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)58 %tmp1 = extractvalue { i32, i1 } %tmp0, 159 br i1 %tmp1, label %trap, label %cont, !nosanitize !{}60 61trap: ; preds = %for.body62 63 br label %cont64 65cont: ; preds = %for.body66 %tmp2 = extractvalue { i32, i1 } %tmp0, 067 %cmp = icmp slt i32 %tmp2, 1668 br i1 %cmp, label %for.body, label %for.cond.cleanup69; CHECK: Loop %for.body: constant max backedge-taken count is i32 1570}71 72define void @f_sadd_2(ptr %a, ptr %c) {73; CHECK-LABEL: Classifying expressions for: @f_sadd_274entry:75 br label %for.body76 77for.cond.cleanup: ; preds = %cont78 ret void79 80for.body: ; preds = %entry, %cont81; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]82; CHECK-NEXT: --> {0,+,1}<%for.body>83 84 %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]85 %idxprom = sext i32 %i.04 to i6486 %arrayidx = getelementptr inbounds i8, ptr %a, i64 %idxprom87 store i8 0, ptr %arrayidx, align 188 %tmp0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)89 %tmp1 = extractvalue { i32, i1 } %tmp0, 190 br i1 %tmp1, label %trap, label %cont, !nosanitize !{}91 92trap: ; preds = %for.body93 94 br label %cont95 96cont: ; preds = %for.body97 %tmp2 = extractvalue { i32, i1 } %tmp0, 098 %cond = load volatile i1, ptr %c99 br i1 %cond, label %for.body, label %for.cond.cleanup100}101 102define void @f_sadd_3(ptr %a, ptr %c) {103; CHECK-LABEL: Classifying expressions for: @f_sadd_3104entry:105 br label %for.body106 107for.cond.cleanup: ; preds = %cont108 ret void109 110for.body: ; preds = %entry, %cont111; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %for.body ]112; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.body>113 114 %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %for.body ]115 %idxprom = sext i32 %i.04 to i64116 %arrayidx = getelementptr inbounds i8, ptr %a, i64 %idxprom117 store i8 0, ptr %arrayidx, align 1118 %tmp0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)119 %tmp1 = extractvalue { i32, i1 } %tmp0, 1120 %tmp2 = extractvalue { i32, i1 } %tmp0, 0121 br i1 %tmp1, label %trap, label %for.body, !nosanitize !{}122 123trap: ; preds = %for.body124 tail call void @llvm.trap() #2, !nosanitize !{}125 unreachable, !nosanitize !{}126}127 128define void @f_sadd_4(ptr %a, ptr %c) {129; CHECK-LABEL: Classifying expressions for: @f_sadd_4130entry:131 br label %for.body132 133for.cond.cleanup: ; preds = %cont134 ret void135 136for.body: ; preds = %entry, %cont137; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %merge ]138; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.body>139 140 %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %merge ]141 %idxprom = sext i32 %i.04 to i64142 %arrayidx = getelementptr inbounds i8, ptr %a, i64 %idxprom143 store i8 0, ptr %arrayidx, align 1144 %tmp0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)145 %tmp1 = extractvalue { i32, i1 } %tmp0, 1146 %tmp2 = extractvalue { i32, i1 } %tmp0, 0147 br i1 %tmp1, label %notrap, label %merge148 149notrap:150 br label %merge151 152merge:153 %tmp3 = extractvalue { i32, i1 } %tmp0, 1154 br i1 %tmp3, label %trap, label %for.body, !nosanitize !{}155 156trap: ; preds = %for.body157 tail call void @llvm.trap() #2, !nosanitize !{}158 unreachable, !nosanitize !{}159}160 161define void @f_sadd_may_overflow(ptr %a, ptr %c) {162; CHECK-LABEL: Classifying expressions for: @f_sadd_may_overflow163entry:164 br label %for.body165 166for.cond.cleanup: ; preds = %cont167 ret void168 169for.body: ; preds = %entry, %cont170; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp1, %cont ]171; CHECK-NEXT: --> {0,+,1}<%for.body> U: full-set S: full-set172 173 %i.04 = phi i32 [ 0, %entry ], [ %tmp1, %cont ]174 %idxprom = sext i32 %i.04 to i64175 %arrayidx = getelementptr inbounds i8, ptr %a, i64 %idxprom176 store i8 0, ptr %arrayidx, align 1177 %tmp0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)178 %cond1 = load volatile i1, ptr %c179 br i1 %cond1, label %trap, label %cont, !nosanitize !{}180 181trap: ; preds = %for.body182 tail call void @llvm.trap() #2, !nosanitize !{}183 unreachable, !nosanitize !{}184 185cont: ; preds = %for.body186 %tmp1 = extractvalue { i32, i1 } %tmp0, 0187 %cond = load volatile i1, ptr %c188 br i1 %cond, label %for.body, label %for.cond.cleanup189}190 191define void @f_uadd(ptr %a) {192; CHECK-LABEL: Classifying expressions for: @f_uadd193entry:194 br label %for.body195 196for.cond.cleanup: ; preds = %cont197 ret void198 199for.body: ; preds = %entry, %cont200; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]201; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.body> U: [0,16) S: [0,16)202 203 %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]204 %idxprom = sext i32 %i.04 to i64205 %arrayidx = getelementptr inbounds i8, ptr %a, i64 %idxprom206 store i8 0, ptr %arrayidx, align 1207 %tmp0 = tail call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %i.04, i32 1)208 %tmp1 = extractvalue { i32, i1 } %tmp0, 1209 br i1 %tmp1, label %trap, label %cont, !nosanitize !{}210 211trap: ; preds = %for.body212 tail call void @llvm.trap(), !nosanitize !{}213 unreachable, !nosanitize !{}214 215cont: ; preds = %for.body216 %tmp2 = extractvalue { i32, i1 } %tmp0, 0217 %cmp = icmp slt i32 %tmp2, 16218 br i1 %cmp, label %for.body, label %for.cond.cleanup219; CHECK: Loop %for.body: constant max backedge-taken count is i32 15220}221 222define void @f_ssub(ptr nocapture %a) {223; CHECK-LABEL: Classifying expressions for: @f_ssub224entry:225 br label %for.body226 227for.cond.cleanup: ; preds = %cont228 ret void229 230for.body: ; preds = %entry, %cont231; CHECK: %i.04 = phi i32 [ 15, %entry ], [ %tmp2, %cont ]232; CHECK-NEXT: --> {15,+,-1}<nsw><%for.body> U: [0,16) S: [0,16)233 234 %i.04 = phi i32 [ 15, %entry ], [ %tmp2, %cont ]235 %idxprom = sext i32 %i.04 to i64236 %arrayidx = getelementptr inbounds i8, ptr %a, i64 %idxprom237 store i8 0, ptr %arrayidx, align 1238 %tmp0 = tail call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 %i.04, i32 1)239 %tmp1 = extractvalue { i32, i1 } %tmp0, 1240 br i1 %tmp1, label %trap, label %cont, !nosanitize !{}241 242trap: ; preds = %for.body243 tail call void @llvm.trap(), !nosanitize !{}244 unreachable, !nosanitize !{}245 246cont: ; preds = %for.body247 %tmp2 = extractvalue { i32, i1 } %tmp0, 0248 %cmp = icmp sgt i32 %tmp2, -1249 br i1 %cmp, label %for.body, label %for.cond.cleanup250; CHECK: Loop %for.body: constant max backedge-taken count is i32 15251}252 253define void @f_usub(ptr nocapture %a) {254; CHECK-LABEL: Classifying expressions for: @f_usub255entry:256 br label %for.body257 258for.cond.cleanup: ; preds = %cont259 ret void260 261for.body: ; preds = %entry, %cont262; CHECK: %i.04 = phi i32 [ 15, %entry ], [ %tmp2, %cont ]263; CHECK-NEXT: --> {15,+,-1}<nsw><%for.body> U: [0,16) S: [0,16)264 265 %i.04 = phi i32 [ 15, %entry ], [ %tmp2, %cont ]266 %idxprom = sext i32 %i.04 to i64267 %arrayidx = getelementptr inbounds i8, ptr %a, i64 %idxprom268 store i8 0, ptr %arrayidx, align 1269 %tmp0 = tail call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %i.04, i32 1)270 %tmp1 = extractvalue { i32, i1 } %tmp0, 1271 br i1 %tmp1, label %trap, label %cont, !nosanitize !{}272 273trap: ; preds = %for.body274 tail call void @llvm.trap(), !nosanitize !{}275 unreachable, !nosanitize !{}276 277cont: ; preds = %for.body278 %tmp2 = extractvalue { i32, i1 } %tmp0, 0279 %cmp = icmp sgt i32 %tmp2, -1280 br i1 %cmp, label %for.body, label %for.cond.cleanup281; CHECK: Loop %for.body: constant max backedge-taken count is i32 15282}283 284define i32 @f_smul(i32 %val_a, i32 %val_b) {285; CHECK-LABEL: Classifying expressions for: @f_smul286 %agg = tail call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %val_a, i32 %val_b)287; CHECK: %mul = extractvalue { i32, i1 } %agg, 0288; CHECK-NEXT: --> (%val_a * %val_b) U: full-set S: full-set289 %mul = extractvalue { i32, i1 } %agg, 0290 ret i32 %mul291}292 293define i32 @f_umul(i32 %val_a, i32 %val_b) {294; CHECK-LABEL: Classifying expressions for: @f_umul295 %agg = tail call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %val_a, i32 %val_b)296; CHECK: %mul = extractvalue { i32, i1 } %agg, 0297; CHECK-NEXT: --> (%val_a * %val_b) U: full-set S: full-set298 %mul = extractvalue { i32, i1 } %agg, 0299 ret i32 %mul300}301 302declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) nounwind readnone303declare { i32, i1 } @llvm.uadd.with.overflow.i32(i32, i32) nounwind readnone304declare { i32, i1 } @llvm.ssub.with.overflow.i32(i32, i32) nounwind readnone305declare { i32, i1 } @llvm.usub.with.overflow.i32(i32, i32) nounwind readnone306declare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32) nounwind readnone307declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32) nounwind readnone308 309declare void @llvm.trap() #2310