mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
11cbc372b6
Summary: This fixes PR32721 in IfConvertTriangle and possible similar problems in IfConvertSimple, IfConvertDiamond and IfConvertForkedDiamond. In PR32721 we had a triangle EBB | \ | | | TBB | / FBB where FBB didn't have any successors at all since it ended with an unconditional return. Then TBB and FBB were be merged into EBB, but EBB would still keep its successors, and the use of analyzeBranch and CorrectExtraCFGEdges wouldn't help to remove them since the return instruction is not analyzable (at least not on ARM). The edge updating code and branch probability updating code is now pushed into MergeBlocks() which allows us to share the same update logic between more callsites. This lets us remove several dependencies on analyzeBranch and completely eliminate RemoveExtraEdges. One thing that showed up with this patch was that IfConversion sometimes left a successor with 0% probability even if there was no branch or fallthrough to the successor. One such example from the test case ifcvt_bad_zero_prob_succ.mir. The indirect branch tBRIND can only jump to bb.1, but without the patch we got: bb.0: successors: %bb.1(0x80000000) bb.1: successors: %bb.1(0x80000000), %bb.2(0x00000000) tBRIND %r1, 1, %cpsr B %bb.1 bb.2: There is no way to jump from bb.1 to bb2, but still there is a 0% edge from bb.1 to bb.2. With the patch applied we instead get the expected: bb.0: successors: %bb.1(0x80000000) bb.1: successors: %bb.1(0x80000000) tBRIND %r1, 1, %cpsr B %bb.1 Since bb.2 had no predecessor at all, it was removed. Several testcases had to be updated due to this since the removed successor made the "Branch Probability Basic Block Placement" pass sometimes place blocks in a different order. Finally added a couple of new test cases: * PR32721_ifcvt_triangle_unanalyzable.mir: Regression test for the original problem dexcribed in PR 32721. * ifcvt_triangleWoCvtToNextEdge.mir: Regression test for problem that caused a revert of my first attempt to solve PR 32721. * ifcvt_simple_bad_zero_prob_succ.mir: Test case showing the problem where a wrong successor with 0% probability was previously left. * ifcvt_[diamond|forked_diamond|simple]_unanalyzable.mir Very simple test cases for the simple and (forked) diamond cases involving unanalyzable branches that can be nice to have as a base if wanting to write more complicated tests. Reviewers: iteratee, MatzeB, grosser, kparzysz Reviewed By: kparzysz Subscribers: kbarton, davide, aemerson, nemanjai, javed.absar, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D34099 llvm-svn: 310697
44 lines
1.4 KiB
LLVM
44 lines
1.4 KiB
LLVM
; REQUIRES: asserts
|
|
; RUN: llc < %s -mtriple=thumbv7-apple-ios -arm-atomic-cfg-tidy=0 -stats 2>&1 | FileCheck %s
|
|
|
|
; If ARMBaseInstrInfo::AnalyzeBlocks returns the wrong value, which was possible
|
|
; for blocks with indirect branches, the IfConverter could end up deleting
|
|
; blocks that were the destinations of indirect branches, leaving branches to
|
|
; nowhere.
|
|
; <rdar://problem/14464830>
|
|
|
|
define i32 @preserve_blocks(i32 %x) {
|
|
; preserve_blocks:
|
|
; CHECK: Block address taken
|
|
; CHECK: %ibt1
|
|
; CHECK: movs r0, #2
|
|
; CHECK: Block address taken
|
|
; CHECK: %ibt2
|
|
; CHECK: movs r0, #1
|
|
; CHECK-NOT: Address of block that was removed by CodeGen
|
|
|
|
; Separate bug. There are no valid diamonds to if-convert in this file.
|
|
; There was a bug in the if-conversion code that would if-convert a false
|
|
; diamond where one side had a return and the other had an indirect branch.
|
|
; Make sure no diamond conversions occurred while compiling this file.
|
|
; CHECK: Statistics Collected
|
|
; CHECK-NOT: 1 ifcvt - Number of diamond if-conversions performed
|
|
entry:
|
|
%c2 = icmp slt i32 %x, 3
|
|
%blockaddr = select i1 %c2, i8* blockaddress(@preserve_blocks, %ibt1), i8* blockaddress(@preserve_blocks, %ibt2)
|
|
%c1 = icmp eq i32 %x, 0
|
|
br i1 %c1, label %pre_ib, label %nextblock
|
|
|
|
nextblock:
|
|
ret i32 3
|
|
|
|
ibt1:
|
|
ret i32 2
|
|
|
|
ibt2:
|
|
ret i32 1
|
|
|
|
pre_ib:
|
|
indirectbr i8* %blockaddr, [ label %ibt1, label %ibt2 ]
|
|
}
|