[SCEV] Add a testcase for zero max btc with non-constant exact btc
authorPhilip Reames <listmail@philipreames.com>
Tue, 31 Aug 2021 17:59:02 +0000 (10:59 -0700)
committerPhilip Reames <listmail@philipreames.com>
Tue, 31 Aug 2021 18:00:41 +0000 (11:00 -0700)
Reduced from the ArchiveCommandLine.ll case seen in D108848.

llvm/test/Analysis/ScalarEvolution/max-trip-count.ll

index f50ff14..36cf882 100644 (file)
@@ -517,3 +517,38 @@ loop:
 exit:
   ret void
 }
+
+; This is a case where our max-backedge taken count logic happens to be
+; able to prove a zero btc, but our symbolic logic doesn't due to a lack
+; of context sensativity.
+define void @ne_zero_max_btc(i32 %a) {
+; CHECK-LABEL: Determining loop execution counts for: @ne_zero_max_btc
+; CHECK: Loop %for.body: backedge-taken count is (-1 + (zext i32 (1 umax (1 smin %a)) to i64))<nsw>
+; CHECK: Loop %for.body: max backedge-taken count is 0
+entry:
+  %cmp = icmp slt i32 %a, 1
+  %spec.select = select i1 %cmp, i32 %a, i32 1
+  %cmp8 = icmp sgt i32 %a, 0
+  br i1 %cmp8, label %for.body.preheader, label %loopexit
+
+for.body.preheader:                         ; preds = %if.then4.i.i
+  %umax = call i32 @llvm.umax.i32(i32 %spec.select, i32 1)
+  %umax.i.i = zext i32 %umax to i64
+  br label %for.body
+
+for.body:                                   ; preds = %for.inc, %for.body.preheader
+  %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.inc ]
+  call void @unknown()
+  br label %for.inc
+
+for.inc:                                    ; preds = %for.body
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond.i.not.i534 = icmp ne i64 %indvars.iv.next, %umax.i.i
+  br i1 %exitcond.i.not.i534, label %for.body, label %loopexit
+
+loopexit:
+  ret void
+}
+
+declare void @unknown()
+declare i32 @llvm.umax.i32(i32, i32)