Commit ad8323d4 authored by Junjie Gu's avatar Junjie Gu Committed by gbsbuild

ifCvt does not handle goto correctly when head and

tail is merged. When head and tail is merged, goto
instructions in both s0 (then) and s1 (else) must be
removed to avoid gotoing to nonexisting target labels

Change-Id: Ib81afd96b27c014ed8c9b4ca218d50bcaaab49cd
parent 0dfc21dc
......@@ -548,6 +548,9 @@ void IfConverter::fullConvert(IfConvertible &IC) {
"Convertible if is not started with 'if' or 'goto'!");
bool isGoto = (op == G4_goto);
// Skip tail merging if tail has other incoming edge(s).
bool doTailMerging = (tail->Preds.size() == 2);
// forward goto's behavior is platform dependent
bool needReversePredicateForGoto = (isGoto && fg.builder->gotoJumpOnTrue());
// Merge predicated 'if' into header.
......@@ -557,6 +560,8 @@ void IfConverter::fullConvert(IfConvertible &IC) {
if (op == G4_label)
continue;
if (isGoto && s1) {
// Have both s0 and s1, goto in s0 can be
// removed always.
if (op == G4_goto)
continue;
if (isFlagClearingFollowedByGoto(I, s0))
......@@ -564,6 +569,11 @@ void IfConverter::fullConvert(IfConvertible &IC) {
} else {
if (op == G4_else)
continue;
// If there is a goto, its target must be tail.
// If merging is done, we must remove goto as its
// target is gone.
if (doTailMerging && op == G4_goto)
continue;
}
/* Predicate instructions if it's not goto-style or it's not
* neither goto nor its flag clearing instruction */
......@@ -592,6 +602,11 @@ void IfConverter::fullConvert(IfConvertible &IC) {
continue;
if (op == G4_join)
continue;
// If there is a goto, its target must be tail.
// If merging is done, we must remove goto as its
// target is gone.
if (doTailMerging && op == G4_goto)
continue;
/* Predicate instructions if it's not goto-style or it's not
* neither goto nor its flag clearing instruction */
if (!isGoto ||
......@@ -613,8 +628,7 @@ void IfConverter::fullConvert(IfConvertible &IC) {
// Remove 'if' instruction in head.
head->erase(pos);
// Skip tail merging if tail has other incoming edge(s).
if (tail->Preds.size() != 2)
if (!doTailMerging)
return;
// Remove 'label' and 'endif'/'join' instructions in tail.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment