If the block that we're threading through is jumped to by an indirect branch,

then we don't want to set the destination in the indirect branch to the
destination. This is because the indirect branch needs its destinations to have
had their block addresses taken. This isn't so of the new critical edge that's
split during this process. If it turns out that the destination block has only
one predecessor, and that being a BB with an indirect branch, then it won't be
marked as 'used' and may be removed.
PR10072


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@132638 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2011-06-04 09:42:04 +00:00
parent c017bc1c1e
commit 6a648b8538
2 changed files with 72 additions and 1 deletions

View File

@ -1171,6 +1171,8 @@ static bool FoldCondBranchOnPHI(BranchInst *BI, const TargetData *TD) {
BasicBlock *RealDest = BI->getSuccessor(!CB->getZExtValue());
if (RealDest == BB) continue; // Skip self loops.
// Skip if the predecessor's terminator is an indirect branch.
if (isa<IndirectBrInst>(PredBB->getTerminator())) continue;
// The dest block might have PHI nodes, other predecessors and other
// difficult cases. Instead of being smart about this, just insert a new
@ -1226,7 +1228,7 @@ static bool FoldCondBranchOnPHI(BranchInst *BI, const TargetData *TD) {
BB->removePredecessor(PredBB);
PredBBTI->setSuccessor(i, EdgeBB);
}
// Recurse, simplifying any other constants.
return FoldCondBranchOnPHI(BI, TD) | true;
}

View File

@ -180,3 +180,72 @@ L3:
; before SimplifyCFG even looks at the indirectbr.
indirectbr i8* %anchor, [label %L1, label %L2]
}
; PR10072
@xblkx.bbs = internal unnamed_addr constant [9 x i8*] [i8* blockaddress(@indbrtest7, %xblkx.begin), i8* blockaddress(@indbrtest7, %xblkx.begin3), i8* blockaddress(@indbrtest7, %xblkx.begin4), i8* blockaddress(@indbrtest7, %xblkx.begin5), i8* blockaddress(@indbrtest7, %xblkx.begin6), i8* blockaddress(@indbrtest7, %xblkx.begin7), i8* blockaddress(@indbrtest7, %xblkx.begin8), i8* blockaddress(@indbrtest7, %xblkx.begin9), i8* blockaddress(@indbrtest7, %xblkx.end)]
define void @indbrtest7() {
escape-string.top:
%xval202x = call i32 @xfunc5x()
br label %xlab5x
xlab8x: ; preds = %xlab5x
%xvaluex = call i32 @xselectorx()
%xblkx.x = getelementptr [9 x i8*]* @xblkx.bbs, i32 0, i32 %xvaluex
%xblkx.load = load i8** %xblkx.x
indirectbr i8* %xblkx.load, [label %xblkx.begin, label %xblkx.begin3, label %xblkx.begin4, label %xblkx.begin5, label %xblkx.begin6, label %xblkx.begin7, label %xblkx.begin8, label %xblkx.begin9, label %xblkx.end]
xblkx.begin:
br label %xblkx.end
xblkx.begin3:
br label %xblkx.end
xblkx.begin4:
br label %xblkx.end
xblkx.begin5:
br label %xblkx.end
xblkx.begin6:
br label %xblkx.end
xblkx.begin7:
br label %xblkx.end
xblkx.begin8:
br label %xblkx.end
xblkx.begin9:
br label %xblkx.end
xblkx.end:
%yes.0 = phi i1 [ false, %xblkx.begin ], [ true, %xlab8x ], [ false, %xblkx.begin9 ], [ false, %xblkx.begin8 ], [ false, %xblkx.begin7 ], [ false, %xblkx.begin6 ], [ false, %xblkx.begin5 ], [ true, %xblkx.begin4 ], [ false, %xblkx.begin3 ]
br i1 %yes.0, label %v2j, label %xlab17x
v2j:
; CHECK: %xunusedx = call i32 @xactionx()
%xunusedx = call i32 @xactionx()
br label %xlab4x
xlab17x:
br label %xlab4x
xlab4x:
%incr19 = add i32 %xval704x.0, 1
br label %xlab5x
xlab5x:
%xval704x.0 = phi i32 [ 0, %escape-string.top ], [ %incr19, %xlab4x ]
%xval10x = icmp ult i32 %xval704x.0, %xval202x
br i1 %xval10x, label %xlab8x, label %xlab9x
xlab9x:
ret void
}
declare i32 @xfunc5x()
declare i8 @xfunc7x()
declare i32 @xselectorx()
declare i32 @xactionx()