[llvm] r187283 - Reimplement isPotentiallyReachable to make nocapture deduction much stronger.

Chris Lattner clattner at apple.com
Sat Jul 27 09:11:49 PDT 2013


On Jul 26, 2013, at 6:24 PM, Nick Lewycky <nicholas at mxc.ca> wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=187283&view=rev
> Log:
> Reimplement isPotentiallyReachable to make nocapture deduction much stronger.
> Adds unit tests for it too.
> 
> Split BasicBlockUtils into an analysis-half and a transforms-half, and put the
> analysis bits into a new Analysis/CFG.{h,cpp}. Promote isPotentiallyReachable
> into llvm::isPotentiallyReachable and move it into Analysis/CFG.

Random unit test question for you:

> +TEST_F(IsPotentiallyReachableTest, SameBlockNoPath) {
> +  ParseAssembly(
> +      "define void @test() {\n"
> +      "entry:\n"
> +      "  bitcast i8 undef to i8\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  bitcast i8 undef to i8\n"
> +      "  bitcast i8 undef to i8\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  ret void\n"
> +      "}\n");
> +  ExpectPath(false);
> +}

I understand the value of unit tests for stuff like this, but dumping swaths of LLVM IR into them seems really weird to me.  Why not just express these tests in terms of the benefit, i.e., cases that make nocapture inference work better?  Then they can be written as .ll files like most of our testsuite.

-Chris

> +
> +TEST_F(IsPotentiallyReachableTest, SameBlockPath) {
> +  ParseAssembly(
> +      "define void @test() {\n"
> +      "entry:\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  bitcast i8 undef to i8\n"
> +      "  bitcast i8 undef to i8\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  ret void\n"
> +      "}\n");
> +  ExpectPath(true);
> +}
> +
> +TEST_F(IsPotentiallyReachableTest, StraightNoPath) {
> +  ParseAssembly(
> +      "define void @test() {\n"
> +      "entry:\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  br label %exit\n"
> +      "exit:\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  ret void\n"
> +      "}");
> +  ExpectPath(false);
> +}
> +
> +TEST_F(IsPotentiallyReachableTest, StraightPath) {
> +  ParseAssembly(
> +      "define void @test() {\n"
> +      "entry:\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  br label %exit\n"
> +      "exit:\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  ret void\n"
> +      "}");
> +  ExpectPath(true);
> +}
> +
> +TEST_F(IsPotentiallyReachableTest, DestUnreachable) {
> +  ParseAssembly(
> +      "define void @test() {\n"
> +      "entry:\n"
> +      "  br label %midblock\n"
> +      "midblock:\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  ret void\n"
> +      "unreachable:\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  br label %midblock\n"
> +      "}");
> +  ExpectPath(false);
> +}
> +
> +TEST_F(IsPotentiallyReachableTest, BranchToReturn) {
> +  ParseAssembly(
> +      "define void @test(i1 %x) {\n"
> +      "entry:\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  br i1 %x, label %block1, label %block2\n"
> +      "block1:\n"
> +      "  ret void\n"
> +      "block2:\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  ret void\n"
> +      "}");
> +  ExpectPath(true);
> +}
> +
> +TEST_F(IsPotentiallyReachableTest, SimpleLoop1) {
> +  ParseAssembly(
> +      "declare i1 @switch()\n"
> +      "\n"
> +      "define void @test() {\n"
> +      "entry:\n"
> +      "  br label %loop\n"
> +      "loop:\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  %x = call i1 @switch()\n"
> +      "  br i1 %x, label %loop, label %exit\n"
> +      "exit:\n"
> +      "  ret void\n"
> +      "}");
> +  ExpectPath(true);
> +}
> +
> +TEST_F(IsPotentiallyReachableTest, SimpleLoop2) {
> +  ParseAssembly(
> +      "declare i1 @switch()\n"
> +      "\n"
> +      "define void @test() {\n"
> +      "entry:\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  br label %loop\n"
> +      "loop:\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  %x = call i1 @switch()\n"
> +      "  br i1 %x, label %loop, label %exit\n"
> +      "exit:\n"
> +      "  ret void\n"
> +      "}");
> +  ExpectPath(false);
> +}
> +
> +TEST_F(IsPotentiallyReachableTest, SimpleLoop3) {
> +  ParseAssembly(
> +      "declare i1 @switch()\n"
> +      "\n"
> +      "define void @test() {\n"
> +      "entry:\n"
> +      "  br label %loop\n"
> +      "loop:\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  %x = call i1 @switch()\n"
> +      "  br i1 %x, label %loop, label %exit\n"
> +      "exit:\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  ret void\n"
> +      "}");
> +  ExpectPath(false);
> +}
> +
> +
> +TEST_F(IsPotentiallyReachableTest, OneLoopAfterTheOther1) {
> +  ParseAssembly(
> +      "declare i1 @switch()\n"
> +      "\n"
> +      "define void @test() {\n"
> +      "entry:\n"
> +      "  br label %loop1\n"
> +      "loop1:\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  %x = call i1 @switch()\n"
> +      "  br i1 %x, label %loop1, label %loop1exit\n"
> +      "loop1exit:\n"
> +      "  br label %loop2\n"
> +      "loop2:\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  %y = call i1 @switch()\n"
> +      "  br i1 %x, label %loop2, label %loop2exit\n"
> +      "loop2exit:"
> +      "  ret void\n"
> +      "}");
> +  ExpectPath(true);
> +}
> +
> +TEST_F(IsPotentiallyReachableTest, OneLoopAfterTheOther2) {
> +  ParseAssembly(
> +      "declare i1 @switch()\n"
> +      "\n"
> +      "define void @test() {\n"
> +      "entry:\n"
> +      "  br label %loop1\n"
> +      "loop1:\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  %x = call i1 @switch()\n"
> +      "  br i1 %x, label %loop1, label %loop1exit\n"
> +      "loop1exit:\n"
> +      "  br label %loop2\n"
> +      "loop2:\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  %y = call i1 @switch()\n"
> +      "  br i1 %x, label %loop2, label %loop2exit\n"
> +      "loop2exit:"
> +      "  ret void\n"
> +      "}");
> +  ExpectPath(false);
> +}
> +
> +TEST_F(IsPotentiallyReachableTest, OneLoopAfterTheOtherInsideAThirdLoop) {
> +  ParseAssembly(
> +      "declare i1 @switch()\n"
> +      "\n"
> +      "define void @test() {\n"
> +      "entry:\n"
> +      "  br label %outerloop3\n"
> +      "outerloop3:\n"
> +      "  br label %innerloop1\n"
> +      "innerloop1:\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  %x = call i1 @switch()\n"
> +      "  br i1 %x, label %innerloop1, label %innerloop1exit\n"
> +      "innerloop1exit:\n"
> +      "  br label %innerloop2\n"
> +      "innerloop2:\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  %y = call i1 @switch()\n"
> +      "  br i1 %x, label %innerloop2, label %innerloop2exit\n"
> +      "innerloop2exit:"
> +      "  ;; In outer loop3 now.\n"
> +      "  %z = call i1 @switch()\n"
> +      "  br i1 %z, label %outerloop3, label %exit\n"
> +      "exit:\n"
> +      "  ret void\n"
> +      "}");
> +  ExpectPath(true);
> +}
> +
> +TEST_F(IsPotentiallyReachableTest, BranchInsideLoop) {
> +  ParseAssembly(
> +      "declare i1 @switch()\n"
> +      "\n"
> +      "define void @test() {\n"
> +      "entry:\n"
> +      "  br label %loop\n"
> +      "loop:\n"
> +      "  %x = call i1 @switch()\n"
> +      "  br i1 %x, label %nextloopblock, label %exit\n"
> +      "nextloopblock:\n"
> +      "  %y = call i1 @switch()\n"
> +      "  br i1 %y, label %left, label %right\n"
> +      "left:\n"
> +      "  %A = bitcast i8 undef to i8\n"
> +      "  br label %loop\n"
> +      "right:\n"
> +      "  %B = bitcast i8 undef to i8\n"
> +      "  br label %loop\n"
> +      "exit:\n"
> +      "  ret void\n"
> +      "}");
> +  ExpectPath(true);
> +}
> 
> Modified: llvm/trunk/unittests/Analysis/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/CMakeLists.txt?rev=187283&r1=187282&r2=187283&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/Analysis/CMakeLists.txt (original)
> +++ llvm/trunk/unittests/Analysis/CMakeLists.txt Fri Jul 26 20:24:00 2013
> @@ -1,5 +1,6 @@
> set(LLVM_LINK_COMPONENTS
>   Analysis
> +  AsmParser
>   )
> 
> add_llvm_unittest(AnalysisTests
> 
> Modified: llvm/trunk/unittests/Analysis/Makefile
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/Makefile?rev=187283&r1=187282&r2=187283&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/Analysis/Makefile (original)
> +++ llvm/trunk/unittests/Analysis/Makefile Fri Jul 26 20:24:00 2013
> @@ -9,7 +9,7 @@
> 
> LEVEL = ../..
> TESTNAME = Analysis
> -LINK_COMPONENTS := analysis
> +LINK_COMPONENTS := analysis asmparser
> 
> include $(LEVEL)/Makefile.config
> include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130727/8739278f/attachment.html>


More information about the llvm-commits mailing list