Skip to content

Commit ad8323d

Browse files
jgu222gfxbot
authored andcommitted
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
1 parent 0dfc21d commit ad8323d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

visa/ifcvt.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ void IfConverter::fullConvert(IfConvertible &IC) {
548548
"Convertible if is not started with 'if' or 'goto'!");
549549
bool isGoto = (op == G4_goto);
550550

551+
// Skip tail merging if tail has other incoming edge(s).
552+
bool doTailMerging = (tail->Preds.size() == 2);
553+
551554
// forward goto's behavior is platform dependent
552555
bool needReversePredicateForGoto = (isGoto && fg.builder->gotoJumpOnTrue());
553556
// Merge predicated 'if' into header.
@@ -557,13 +560,20 @@ void IfConverter::fullConvert(IfConvertible &IC) {
557560
if (op == G4_label)
558561
continue;
559562
if (isGoto && s1) {
563+
// Have both s0 and s1, goto in s0 can be
564+
// removed always.
560565
if (op == G4_goto)
561566
continue;
562567
if (isFlagClearingFollowedByGoto(I, s0))
563568
continue;
564569
} else {
565570
if (op == G4_else)
566571
continue;
572+
// If there is a goto, its target must be tail.
573+
// If merging is done, we must remove goto as its
574+
// target is gone.
575+
if (doTailMerging && op == G4_goto)
576+
continue;
567577
}
568578
/* Predicate instructions if it's not goto-style or it's not
569579
* neither goto nor its flag clearing instruction */
@@ -592,6 +602,11 @@ void IfConverter::fullConvert(IfConvertible &IC) {
592602
continue;
593603
if (op == G4_join)
594604
continue;
605+
// If there is a goto, its target must be tail.
606+
// If merging is done, we must remove goto as its
607+
// target is gone.
608+
if (doTailMerging && op == G4_goto)
609+
continue;
595610
/* Predicate instructions if it's not goto-style or it's not
596611
* neither goto nor its flag clearing instruction */
597612
if (!isGoto ||
@@ -613,8 +628,7 @@ void IfConverter::fullConvert(IfConvertible &IC) {
613628
// Remove 'if' instruction in head.
614629
head->erase(pos);
615630

616-
// Skip tail merging if tail has other incoming edge(s).
617-
if (tail->Preds.size() != 2)
631+
if (!doTailMerging)
618632
return;
619633

620634
// Remove 'label' and 'endif'/'join' instructions in tail.

0 commit comments

Comments
 (0)