From 432a12c8037293bd1ff919a82f1d4412772ac534 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Wed, 6 Nov 2019 14:56:59 +0300 Subject: [PATCH] [NFC][LoopUnroll] Update test coverage for peeling w/ inequality predicates --- .../Transforms/LoopUnroll/peel-loop-conditions.ll | 94 ++++++++++++++++++++-- 1 file changed, 89 insertions(+), 5 deletions(-) diff --git a/llvm/test/Transforms/LoopUnroll/peel-loop-conditions.ll b/llvm/test/Transforms/LoopUnroll/peel-loop-conditions.ll index 3d889c6..8c577ec 100644 --- a/llvm/test/Transforms/LoopUnroll/peel-loop-conditions.ll +++ b/llvm/test/Transforms/LoopUnroll/peel-loop-conditions.ll @@ -1,5 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt < %s -S -loop-unroll -verify-dom-info | FileCheck %s +; RUN: opt < %s -S -loop-unroll -unroll-peel-max-count=4 -verify-dom-info | FileCheck %s declare void @f1() declare void @f2() @@ -522,8 +522,6 @@ for.end: } define void @test7(i32 %k) { -; FIXME: Could simplify loop body by peeling one additional iteration after -; i != 3 becomes false ; CHECK-LABEL: @test7( ; CHECK-NEXT: for.body.lr.ph: ; CHECK-NEXT: br label [[FOR_BODY:%.*]] @@ -563,8 +561,6 @@ for.end: } define void @test8(i32 %k) { -; FIXME: Could simplify loop body by peeling one additional iteration after -; i == 3 becomes true. ; CHECK-LABEL: @test8( ; CHECK-NEXT: for.body.lr.ph: ; CHECK-NEXT: br label [[FOR_BODY:%.*]] @@ -779,6 +775,8 @@ if.end: ; preds = %if.then, %for.body br i1 %exitcond, label %for.cond.cleanup, label %for.body } +; NOTE: here we should only peel the first iteration, +; i.e. all calls to sink() must stay in loop. define void @test12__peel_first_iter_via_eq_pred(i32 %len) { ; CHECK-LABEL: @test12__peel_first_iter_via_eq_pred( ; CHECK-NEXT: entry: @@ -826,6 +824,8 @@ if.end: ; preds = %if.then, %for.body br i1 %exitcond, label %for.cond.cleanup, label %for.body } +; NOTE: here we should only peel the first iteration, +; i.e. all calls to sink() must stay in loop. define void @test13__peel_first_iter_via_ne_pred(i32 %len) { ; CHECK-LABEL: @test13__peel_first_iter_via_ne_pred( ; CHECK-NEXT: entry: @@ -873,6 +873,7 @@ if.end: ; preds = %if.then, %for.body br i1 %exitcond, label %for.cond.cleanup, label %for.body } +; No peeling is profitable here. define void @test15__ivar_mod2_is_1(i32 %len) { ; CHECK-LABEL: @test15__ivar_mod2_is_1( ; CHECK-NEXT: entry: @@ -922,6 +923,7 @@ if.end: ; preds = %if.then, %for.body br i1 %exitcond, label %for.cond.cleanup, label %for.body } +; No peeling is profitable here. define void @test16__ivar_mod2_is_0(i32 %len) { ; CHECK-LABEL: @test16__ivar_mod2_is_0( ; CHECK-NEXT: entry: @@ -971,5 +973,87 @@ if.end: ; preds = %if.then, %for.body br i1 %exitcond, label %for.cond.cleanup, label %for.body } +; Similar to @test7, we need to peel one extra iteration, and we can't do that +; as per the -unroll-peel-max-count=4, so this shouldn't be peeled at all. +define void @test17(i32 %k) { +; CHECK-LABEL: @test17( +; CHECK-NEXT: for.body.lr.ph: +; CHECK-NEXT: br label [[FOR_BODY:%.*]] +; CHECK: for.body: +; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ] +; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[I_05]], 4 +; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[FOR_INC]] +; CHECK: if.then: +; CHECK-NEXT: call void @f1() +; CHECK-NEXT: br label [[FOR_INC]] +; CHECK: for.inc: +; CHECK-NEXT: [[INC]] = add nsw i32 [[I_05]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K:%.*]] +; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]] +; CHECK: for.end: +; CHECK-NEXT: ret void +; +for.body.lr.ph: + br label %for.body + +for.body: + %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ] + %cmp1 = icmp ne i32 %i.05, 4 + br i1 %cmp1, label %if.then, label %for.inc + +if.then: + call void @f1() + br label %for.inc + +for.inc: + %inc = add nsw i32 %i.05, 1 + %cmp = icmp slt i32 %inc, %k + br i1 %cmp, label %for.body, label %for.end + +for.end: + ret void +} + +; Similar to @test8, we need to peel one extra iteration, and we can't do that +; as per the -unroll-peel-max-count=4, so this shouldn't be peeled at all. +define void @test18(i32 %k) { +; CHECK-LABEL: @test18( +; CHECK-NEXT: for.body.lr.ph: +; CHECK-NEXT: br label [[FOR_BODY:%.*]] +; CHECK: for.body: +; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ] +; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[I_05]], 4 +; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[FOR_INC]] +; CHECK: if.then: +; CHECK-NEXT: call void @f1() +; CHECK-NEXT: br label [[FOR_INC]] +; CHECK: for.inc: +; CHECK-NEXT: [[INC]] = add nsw i32 [[I_05]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K:%.*]] +; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]] +; CHECK: for.end: +; CHECK-NEXT: ret void +; +for.body.lr.ph: + br label %for.body + +for.body: + %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ] + %cmp1 = icmp eq i32 %i.05, 4 + br i1 %cmp1, label %if.then, label %for.inc + +if.then: + call void @f1() + br label %for.inc + +for.inc: + %inc = add nsw i32 %i.05, 1 + %cmp = icmp slt i32 %inc, %k + br i1 %cmp, label %for.body, label %for.end + +for.end: + ret void +} + declare void @init() declare void @sink() -- 2.7.4