[llvm] 471b25e - [Test] Add test showing profitable peeling opportunity

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 5 03:52:29 PDT 2021


Author: Max Kazantsev
Date: 2021-10-05T17:51:45+07:00
New Revision: 471b25e217e635e058bbdbca8c693e2998380a60

URL: https://github.com/llvm/llvm-project/commit/471b25e217e635e058bbdbca8c693e2998380a60
DIFF: https://github.com/llvm/llvm-project/commit/471b25e217e635e058bbdbca8c693e2998380a60.diff

LOG: [Test] Add test showing profitable peeling opportunity

Patch by Dmitry Makogon!

Added: 
    

Modified: 
    llvm/test/Transforms/LoopUnroll/peel-multiple-unreachable-exits.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/LoopUnroll/peel-multiple-unreachable-exits.ll b/llvm/test/Transforms/LoopUnroll/peel-multiple-unreachable-exits.ll
index 8e4054885beba..e82210c7ff341 100644
--- a/llvm/test/Transforms/LoopUnroll/peel-multiple-unreachable-exits.ll
+++ b/llvm/test/Transforms/LoopUnroll/peel-multiple-unreachable-exits.ll
@@ -261,5 +261,78 @@ unreachable.term:
   unreachable
 }
 
+define void @peel_exits_to_blocks_branch_to_unreachable_block_with_invariant_load(i32* %ptr, i32 %N, i32 %x, i1 %c.1, i32 %y, i32* %size_ptr) {
+; CHECK-LABEL: @peel_exits_to_blocks_branch_to_unreachable_block_with_invariant_load(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[LOOP_HEADER:%.*]]
+; CHECK:       loop.header:
+; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
+; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[IV]], [[Y:%.*]]
+; CHECK-NEXT:    br i1 [[C]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK:       then:
+; CHECK-NEXT:    br i1 [[C_1:%.*]], label [[EXIT_1:%.*]], label [[LOOP_LATCH]]
+; CHECK:       else:
+; CHECK-NEXT:    [[C_2:%.*]] = icmp eq i32 [[IV]], [[X:%.*]]
+; CHECK-NEXT:    br i1 [[C_2]], label [[EXIT_2:%.*]], label [[LOOP_LATCH]]
+; CHECK:       loop.latch:
+; CHECK-NEXT:    [[M:%.*]] = phi i32 [ 0, [[THEN]] ], [ [[X]], [[ELSE]] ]
+; CHECK-NEXT:    [[GEP:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[IV]]
+; CHECK-NEXT:    store i32 [[M]], i32* [[GEP]], align 4
+; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
+; CHECK-NEXT:    [[SIZE:%.*]] = load i32, i32* [[SIZE_PTR:%.*]], align 4
+; CHECK-NEXT:    [[C_3:%.*]] = icmp ult i32 [[IV_NEXT]], [[SIZE]]
+; CHECK-NEXT:    br i1 [[C_3]], label [[LOOP_HEADER]], label [[EXIT:%.*]]
+; CHECK:       exit:
+; CHECK-NEXT:    ret void
+; CHECK:       exit.1:
+; CHECK-NEXT:    call void @foo()
+; CHECK-NEXT:    br label [[UNREACHABLE_TERM:%.*]]
+; CHECK:       exit.2:
+; CHECK-NEXT:    call void @bar()
+; CHECK-NEXT:    br label [[UNREACHABLE_TERM]]
+; CHECK:       unreachable.term:
+; CHECK-NEXT:    call void @baz()
+; CHECK-NEXT:    unreachable
+;
+entry:
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]
+  %c = icmp ult i32 %iv, %y
+  br i1 %c, label %then, label %else
+
+then:
+  br i1 %c.1, label %exit.1, label %loop.latch
+
+else:
+  %c.2 = icmp eq i32 %iv, %x
+  br i1 %c.2, label %exit.2, label %loop.latch
+
+loop.latch:
+  %m = phi i32 [ 0, %then ], [ %x, %else ]
+  %gep = getelementptr i32, i32* %ptr, i32 %iv
+  store i32 %m, i32* %gep
+  %iv.next = add nuw nsw i32 %iv, 1
+  %size = load i32, i32* %size_ptr, align 4
+  %c.3 = icmp ult i32 %iv.next, %size
+  br i1 %c.3, label %loop.header, label %exit
+
+exit:
+  ret void
+
+exit.1:
+  call void @foo()
+  br label %unreachable.term
+
+exit.2:
+  call void @bar()
+  br label %unreachable.term
+
+unreachable.term:
+  call void @baz()
+  unreachable
+}
+
 declare void @bar()
 declare void @baz()


        


More information about the llvm-commits mailing list