Merge empty landing pads in SimplifyCFG
authorPhilip Reames <listmail@philipreames.com>
Tue, 24 Mar 2015 22:28:45 +0000 (22:28 +0000)
committerPhilip Reames <listmail@philipreames.com>
Tue, 24 Mar 2015 22:28:45 +0000 (22:28 +0000)
commit6bde9f699422c041cfa613dd9034e8ea5d827414
treeac65ae86a473cce18a562c3a65f73ff870b497ad
parent54ce82e4971fcb748068fbb047077749498f0fa5
Merge empty landing pads in SimplifyCFG

This patch tries to merge duplicate landing pads when they branch to a common shared target.

Given IR that looks like this:
lpad1:
  %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
         cleanup
  br label %shared_resume
lpad2:
  %exn2 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
          cleanup
  br label %shared_resume
shared_resume:
  call void @fn()
  ret void
}

We can rewrite the users of both landing pad blocks to use one of them. This will generally allow the shared_resume block to be merged with the common landing pad as well.

Without this change, tail duplication would likely kick in - creating N (2 in this case) copies of the shared_resume basic block.

Differential Revision: http://reviews.llvm.org/D8297

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233125 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/duplicate-landingpad.ll [new file with mode: 0644]