[PATCH] D28822: Add a test case for LICM when promoting locals that may be read after the throw within the loop. NFCI.

Xin Tong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 17 13:00:02 PST 2017


trentxintong created this revision.

Add a test case for LICM when promoting locals that may be read after the throw within the loop.


https://reviews.llvm.org/D28822

Files:
  test/Transforms/LICM/scalar-promote-unwind.ll


Index: test/Transforms/LICM/scalar-promote-unwind.ll
===================================================================
--- test/Transforms/LICM/scalar-promote-unwind.ll
+++ test/Transforms/LICM/scalar-promote-unwind.ll
@@ -69,4 +69,82 @@
   ret void
 }
 
+ at _ZTIi = external constant i8*
+
+; This is a test which the loop is within a try block, we must make sure that there is the explicit
+; unwind edge out of the loop due to the fact that boo() may throw and its treated as a loop exit.
+; And that loads/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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28822.84725.patch
Type: text/x-patch
Size: 2286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170117/552b230f/attachment.bin>


More information about the llvm-commits mailing list