From 985d6ae2d43443723cd91b162cec7eca74c6ab14 Mon Sep 17 00:00:00 2001 From: Xin Tong Date: Tue, 17 Jan 2017 21:26:36 +0000 Subject: [PATCH] Add a test case for LICM when promoting locals that may be read after the throw within the loop. NFCI. Summary: Add a test case for LICM when promoting locals that may be read after the throw within the loop. Reviewers: eli.friedman, hfinkel, sanjoy Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D28822 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292261 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/LICM/scalar-promote-unwind.ll | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/test/Transforms/LICM/scalar-promote-unwind.ll b/test/Transforms/LICM/scalar-promote-unwind.ll index dd3693b4af6..917da04d89c 100644 --- a/test/Transforms/LICM/scalar-promote-unwind.ll +++ b/test/Transforms/LICM/scalar-promote-unwind.ll @@ -69,4 +69,82 @@ for.cond.cleanup: ret void } +@_ZTIi = external constant i8* + +; In this test, the loop is within a try block. There is an explicit unwind edge out of the loop. +; Make sure this edge is treated as a loop exit, and that the loads and stores are promoted as +; expected +define void @loop_within_tryblock() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: + %a = alloca i32, align 4 + store i32 0, i32* %a, align 4 + br label %for.cond + +for.cond: + %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] + %cmp = icmp slt i32 %i.0, 1024 + br i1 %cmp, label %for.body, label %for.end + +; CHECK: for.body: +; CHECK-NOT: load +; CHECK-NOT: store +; CHECK: invoke +for.body: + %0 = load i32, i32* %a, align 4 + %add = add nsw i32 %0, 1 + store i32 %add, i32* %a, align 4 + invoke void @boo() + to label %invoke.cont unwind label %lpad + +invoke.cont: + br label %for.inc + +for.inc: + %inc = add nsw i32 %i.0, 1 + br label %for.cond + +; CHECK: lpad: +; CHECK: store +; CHECK: br +lpad: + %1 = landingpad { i8*, i32 } + catch i8* bitcast (i8** @_ZTIi to i8*) + %2 = extractvalue { i8*, i32 } %1, 0 + %3 = extractvalue { i8*, i32 } %1, 1 + br label %catch.dispatch + +catch.dispatch: + %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3 + %matches = icmp eq i32 %3, %4 + br i1 %matches, label %catch, label %eh.resume + +catch: + %5 = call i8* @__cxa_begin_catch(i8* %2) #3 + %6 = bitcast i8* %5 to i32* + %7 = load i32, i32* %6, align 4 + call void @__cxa_end_catch() #3 + br label %try.cont + +try.cont: + ret void + +for.end: + br label %try.cont + +eh.resume: + %lpad.val = insertvalue { i8*, i32 } undef, i8* %2, 0 + %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %3, 1 + resume { i8*, i32 } %lpad.val3 +} + +declare void @boo() + +declare i32 @__gxx_personality_v0(...) + +declare i32 @llvm.eh.typeid.for(i8*) + +declare i8* @__cxa_begin_catch(i8*) + +declare void @__cxa_end_catch() + declare void @f() uwtable