From c7e69e46c86c3f3785441de45db4b7bc6d26e321 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 24 Jul 2021 17:00:16 +0200 Subject: [PATCH] [Tests] Add additional tests for incorrect willreturn handling (NFC) Highlight a few of the places that don't handle non-willreturn calls correctly right now. --- llvm/test/Transforms/LICM/sinking.ll | 22 +++++++++++++++++++++ .../LoopDeletion/noop-loops-with-subloops.ll | 23 ++++++++++++++++++++++ llvm/test/Transforms/SCCP/calltest.ll | 9 +++++++++ 3 files changed, 54 insertions(+) diff --git a/llvm/test/Transforms/LICM/sinking.ll b/llvm/test/Transforms/LICM/sinking.ll index a9c0f45..ee7f633 100644 --- a/llvm/test/Transforms/LICM/sinking.ll +++ b/llvm/test/Transforms/LICM/sinking.ll @@ -979,6 +979,28 @@ try.cont: ret void } +; TODO: Should not get sunk. +define i32 @not_willreturn(i8* %p) { +; CHECK-LABEL: @not_willreturn( +; CHECK-NEXT: br label [[LOOP:%.*]] +; CHECK: loop: +; CHECK-NEXT: store volatile i8 0, i8* [[P:%.*]], align 1 +; CHECK-NEXT: br i1 true, label [[LOOP]], label [[OUT:%.*]] +; CHECK: out: +; CHECK-NEXT: [[X_LE:%.*]] = call i32 @getv() #[[ATTR5:[0-9]+]] +; CHECK-NEXT: ret i32 [[X_LE]] +; + br label %loop + +loop: + %x = call i32 @getv() nounwind readnone + store volatile i8 0, i8* %p + br i1 true, label %loop, label %out + +out: + ret i32 %x +} + declare void @may_throw() declare void @may_throw2() declare i32 @__CxxFrameHandler3(...) diff --git a/llvm/test/Transforms/LoopDeletion/noop-loops-with-subloops.ll b/llvm/test/Transforms/LoopDeletion/noop-loops-with-subloops.ll index 715915b..9163c9c 100644 --- a/llvm/test/Transforms/LoopDeletion/noop-loops-with-subloops.ll +++ b/llvm/test/Transforms/LoopDeletion/noop-loops-with-subloops.ll @@ -394,6 +394,29 @@ exit: ret void } +; Inner infinite loop hidden behind a call. +; TODO: Loop should not get deleted. +define void @not_willreturn() { +; CHECK-LABEL: @not_willreturn( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[EXIT:%.*]] +; CHECK: exit: +; CHECK-NEXT: ret void +; +entry: + br label %loop + +loop: + %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ] + call void @sideeffect() nounwind readonly + %iv.next = add nuw i32 %iv, 1 + %c = icmp ult i32 %iv, 100 + br i1 %c, label %loop, label %exit + +exit: + ret void +} + !1 = !{!"llvm.loop.mustprogress"} !2 = distinct !{!2, !1} !3 = distinct !{!3, !1} diff --git a/llvm/test/Transforms/SCCP/calltest.ll b/llvm/test/Transforms/SCCP/calltest.ll index cf43ea2..de79363 100644 --- a/llvm/test/Transforms/SCCP/calltest.ll +++ b/llvm/test/Transforms/SCCP/calltest.ll @@ -33,3 +33,12 @@ define i32 @test_1() { %1 = call %empty @has_side_effects() ret i32 0 } + +; TODO: Call should not get dropped. +define i32 @test_not_willreturn() { +; CHECK-LABEL: @test_not_willreturn( +; CHECK-NEXT: ret i32 0 +; + %1 = call %empty @has_side_effects() nounwind readonly + ret i32 0 +} -- 2.7.4