[llvm] 557906d - [Test] Fix test to make the transform for which is was added legal

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Mon May 17 03:19:12 PDT 2021


Author: Max Kazantsev
Date: 2021-05-17T17:19:01+07:00
New Revision: 557906d3be7b8825a6728e9ff4feaadc816aebce

URL: https://github.com/llvm/llvm-project/commit/557906d3be7b8825a6728e9ff4feaadc816aebce
DIFF: https://github.com/llvm/llvm-project/commit/557906d3be7b8825a6728e9ff4feaadc816aebce.diff

LOG: [Test] Fix test to make the transform for which is was added legal

%limit in these tests is supposed to be positive.

Added: 
    

Modified: 
    llvm/test/Transforms/LoopDeletion/eval_first_iteration.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/LoopDeletion/eval_first_iteration.ll b/llvm/test/Transforms/LoopDeletion/eval_first_iteration.ll
index 692787b39dfbd..b42f7f4359e86 100644
--- a/llvm/test/Transforms/LoopDeletion/eval_first_iteration.ll
+++ b/llvm/test/Transforms/LoopDeletion/eval_first_iteration.ll
@@ -11,10 +11,13 @@
 define i32 @test_ne(i32 %limit) {
 ; CHECK-LABEL: @test_ne(
 ; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
+; CHECK-NEXT:    br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
+; CHECK:       loop.preheader:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
-; CHECK-NEXT:    [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[LIMIT:%.*]], [[SUM]]
+; CHECK-NEXT:    [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
+; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
 ; CHECK-NEXT:    [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
 ; CHECK-NEXT:    br i1 [[IS_POSITIVE]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
 ; CHECK:       if.false:
@@ -27,9 +30,12 @@ define i32 @test_ne(i32 %limit) {
 ; CHECK:       done:
 ; CHECK-NEXT:    [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
 ; CHECK-NEXT:    ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK:       failure:
+; CHECK-NEXT:    unreachable
 ;
 entry:
-  br label %loop
+  %loop_guard = icmp sgt i32 %limit, 0
+  br i1 %loop_guard, label %loop, label %failure
 
 loop:                                             ; preds = %backedge, %entry
   %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
@@ -49,16 +55,22 @@ backedge:                                         ; preds = %if.false, %loop
 done:                                             ; preds = %backedge
   %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
   ret i32 %sum.next.lcssa
+
+failure:
+  unreachable
 }
 
 ; TODO: We can break the backedge here.
 define i32 @test_slt(i32 %limit) {
 ; CHECK-LABEL: @test_slt(
 ; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
+; CHECK-NEXT:    br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
+; CHECK:       loop.preheader:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
-; CHECK-NEXT:    [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[LIMIT:%.*]], [[SUM]]
+; CHECK-NEXT:    [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
+; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
 ; CHECK-NEXT:    [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
 ; CHECK-NEXT:    br i1 [[IS_POSITIVE]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
 ; CHECK:       if.false:
@@ -71,9 +83,12 @@ define i32 @test_slt(i32 %limit) {
 ; CHECK:       done:
 ; CHECK-NEXT:    [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
 ; CHECK-NEXT:    ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK:       failure:
+; CHECK-NEXT:    unreachable
 ;
 entry:
-  br label %loop
+  %loop_guard = icmp sgt i32 %limit, 0
+  br i1 %loop_guard, label %loop, label %failure
 
 loop:                                             ; preds = %backedge, %entry
   %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
@@ -93,16 +108,22 @@ backedge:                                         ; preds = %if.false, %loop
 done:                                             ; preds = %backedge
   %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
   ret i32 %sum.next.lcssa
+
+failure:
+  unreachable
 }
 
 ; TODO: We can break the backedge here.
 define i32 @test_ult(i32 %limit) {
 ; CHECK-LABEL: @test_ult(
 ; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
+; CHECK-NEXT:    br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
+; CHECK:       loop.preheader:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
-; CHECK-NEXT:    [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[LIMIT:%.*]], [[SUM]]
+; CHECK-NEXT:    [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
+; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
 ; CHECK-NEXT:    [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
 ; CHECK-NEXT:    br i1 [[IS_POSITIVE]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
 ; CHECK:       if.false:
@@ -115,9 +136,12 @@ define i32 @test_ult(i32 %limit) {
 ; CHECK:       done:
 ; CHECK-NEXT:    [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
 ; CHECK-NEXT:    ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK:       failure:
+; CHECK-NEXT:    unreachable
 ;
 entry:
-  br label %loop
+  %loop_guard = icmp sgt i32 %limit, 0
+  br i1 %loop_guard, label %loop, label %failure
 
 loop:                                             ; preds = %backedge, %entry
   %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
@@ -137,16 +161,22 @@ backedge:                                         ; preds = %if.false, %loop
 done:                                             ; preds = %backedge
   %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
   ret i32 %sum.next.lcssa
+
+failure:
+  unreachable
 }
 
 ; TODO: We can break the backedge here.
 define i32 @test_sgt(i32 %limit) {
 ; CHECK-LABEL: @test_sgt(
 ; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
+; CHECK-NEXT:    br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
+; CHECK:       loop.preheader:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
-; CHECK-NEXT:    [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[LIMIT:%.*]], [[SUM]]
+; CHECK-NEXT:    [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
+; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
 ; CHECK-NEXT:    [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
 ; CHECK-NEXT:    br i1 [[IS_POSITIVE]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
 ; CHECK:       if.false:
@@ -159,9 +189,12 @@ define i32 @test_sgt(i32 %limit) {
 ; CHECK:       done:
 ; CHECK-NEXT:    [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
 ; CHECK-NEXT:    ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK:       failure:
+; CHECK-NEXT:    unreachable
 ;
 entry:
-  br label %loop
+  %loop_guard = icmp sgt i32 %limit, 0
+  br i1 %loop_guard, label %loop, label %failure
 
 loop:                                             ; preds = %backedge, %entry
   %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
@@ -181,16 +214,22 @@ backedge:                                         ; preds = %if.false, %loop
 done:                                             ; preds = %backedge
   %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
   ret i32 %sum.next.lcssa
+
+failure:
+  unreachable
 }
 
 ; TODO: We can break the backedge here.
 define i32 @test_ugt(i32 %limit) {
 ; CHECK-LABEL: @test_ugt(
 ; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
+; CHECK-NEXT:    br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
+; CHECK:       loop.preheader:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
-; CHECK-NEXT:    [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[LIMIT:%.*]], [[SUM]]
+; CHECK-NEXT:    [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
+; CHECK-NEXT:    [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
 ; CHECK-NEXT:    [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
 ; CHECK-NEXT:    br i1 [[IS_POSITIVE]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
 ; CHECK:       if.false:
@@ -203,9 +242,12 @@ define i32 @test_ugt(i32 %limit) {
 ; CHECK:       done:
 ; CHECK-NEXT:    [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
 ; CHECK-NEXT:    ret i32 [[SUM_NEXT_LCSSA]]
+; CHECK:       failure:
+; CHECK-NEXT:    unreachable
 ;
 entry:
-  br label %loop
+  %loop_guard = icmp sgt i32 %limit, 0
+  br i1 %loop_guard, label %loop, label %failure
 
 loop:                                             ; preds = %backedge, %entry
   %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
@@ -225,4 +267,7 @@ backedge:                                         ; preds = %if.false, %loop
 done:                                             ; preds = %backedge
   %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
   ret i32 %sum.next.lcssa
+
+failure:
+  unreachable
 }


        


More information about the llvm-commits mailing list