From 72f3f6713710c6d4cf7b1977cae94cefe9fe4a99 Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Tue, 20 Apr 2021 10:07:58 -0700 Subject: [PATCH] [test] Add a couple extra tests for recurrence matching in unreachable code These are salvaged from D100004 as we took a different approach to the fix. --- .../Analysis/ScalarEvolution/shift-recurrences.ll | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/llvm/test/Analysis/ScalarEvolution/shift-recurrences.ll b/llvm/test/Analysis/ScalarEvolution/shift-recurrences.ll index 0b9525d..9622525 100644 --- a/llvm/test/Analysis/ScalarEvolution/shift-recurrences.ll +++ b/llvm/test/Analysis/ScalarEvolution/shift-recurrences.ll @@ -440,6 +440,60 @@ unreachable: br label %for.cond2295 } +; Was pr49856. We can match the recurrence without a loop +; since dominance collapses in unreachable code. Conceptually, +; this is a recurrence which only executes one iteration. +define void @nonloop_recurrence() { +; CHECK-LABEL: 'nonloop_recurrence' +; CHECK-NEXT: Classifying expressions for: @nonloop_recurrence +; CHECK-NEXT: %tmp = phi i32 [ 2, %bb ], [ %tmp2, %bb3 ] +; CHECK-NEXT: --> %tmp U: [1,-2147483648) S: [0,-2147483648) +; CHECK-NEXT: %tmp2 = add nuw nsw i32 %tmp, 1 +; CHECK-NEXT: --> (1 + %tmp) U: [1,-2147483647) S: [1,-2147483647) +; CHECK-NEXT: Determining loop execution counts for: @nonloop_recurrence +; +bb: + br label %bb1 + +bb1: ; preds = %bb3, %bb + %tmp = phi i32 [ 2, %bb ], [ %tmp2, %bb3 ] + %tmp2 = add nuw nsw i32 %tmp, 1 + ret void + +bb3: ; No predecessors! + br label %bb1 +} + +; Tweak of pr49856 test case - analogous, but there is a loop +; it's trip count simply doesn't relate to the single iteration +; "recurrence" we found. +define void @nonloop_recurrence_2() { +; CHECK-LABEL: 'nonloop_recurrence_2' +; CHECK-NEXT: Classifying expressions for: @nonloop_recurrence_2 +; CHECK-NEXT: %tmp = phi i32 [ 2, %loop ], [ %tmp2, %bb3 ] +; CHECK-NEXT: --> %tmp U: [1,-2147483648) S: [0,-2147483648) Exits: <> LoopDispositions: { %loop: Variant } +; CHECK-NEXT: %tmp2 = add nuw nsw i32 %tmp, 1 +; CHECK-NEXT: --> (1 + %tmp) U: [1,-2147483647) S: [1,-2147483647) Exits: <> LoopDispositions: { %loop: Variant } +; CHECK-NEXT: Determining loop execution counts for: @nonloop_recurrence_2 +; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count. +; CHECK-NEXT: Loop %loop: Unpredictable max backedge-taken count. +; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count. +; +bb: + br label %loop + +loop: + br label %bb1 +bb1: ; preds = %bb3, %loop + %tmp = phi i32 [ 2, %loop ], [ %tmp2, %bb3 ] + %tmp2 = add nuw nsw i32 %tmp, 1 + br label %loop + +bb3: ; No predecessors! + br label %bb1 +} + + ; Next batch of tests show where we can get tighter ranges on ashr/lshr ; by using the trip count information on the loop. -- 2.7.4