TailDuplicator::tailDuplicate currently uses the result of a failed analyzeBranch call. canTailDuplicate checks that PredBB can be analyzed, but this isn't sufficient. After the tail block is cloned into PredBB, analyzeBranch is called again and not checked. Adding an assert to catch this fails in these testcases:
I suspect this just needs to call analyzeBranch on TailBB before making any changes. Once the terminators of TailBB are cloned into PredBB, they should be the same so it should be equivalent?
On closer inspection it appears nothing is actually done with the result of this. The comment says "simplify", so maybe this was assuming for the AllowModify = true by default?
Extended Description
TailDuplicator::tailDuplicate currently uses the result of a failed analyzeBranch call. canTailDuplicate checks that PredBB can be analyzed, but this isn't sufficient. After the tail block is cloned into PredBB, analyzeBranch is called again and not checked. Adding an assert to catch this fails in these testcases:
I suspect this just needs to call analyzeBranch on TailBB before making any changes. Once the terminators of TailBB are cloned into PredBB, they should be the same so it should be equivalent?