* builtins.c (expand_builtin_expect_jump): Simplify logic. Handle
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 13 Jan 2004 01:32:42 +0000 (01:32 +0000)
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 13 Jan 2004 01:32:42 +0000 (01:32 +0000)
conditional jumps that drop through to unconditional jumps or the
end of the sequence.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@75780 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/builtins.c

index b7e8573..d237ad9 100644 (file)
@@ -1,3 +1,9 @@
+2004-01-12  Roger Sayle  <roger@eyesopen.com>
+
+       * builtins.c (expand_builtin_expect_jump): Simplify logic. Handle
+       conditional jumps that drop through to unconditional jumps or the
+       end of the sequence.
+
 2004-01-13  Jan Hubicka  <jh@suse.cz>
 
        * alias.c (new_alias_set): Construct the alias_set varray.
index 2957309..5b49b08 100644 (file)
@@ -4460,10 +4460,7 @@ expand_builtin_expect_jump (tree exp, rtx if_false_label, rtx if_true_label)
       if (! if_false_label)
        if_false_label = drop_through_label;
 
-      /* Now that the __builtin_expect has been validated, go through and add
-        the expect's to each of the conditional jumps.  If we run into an
-        error, just give up and generate the 'safe' code of doing a SCC
-        operation and then doing a branch on that.  */
+      /* Go through and add the expect's to each of the conditional jumps.  */
       insn = ret;
       while (insn != NULL_RTX)
        {
@@ -4472,54 +4469,65 @@ expand_builtin_expect_jump (tree exp, rtx if_false_label, rtx if_true_label)
          if (GET_CODE (insn) == JUMP_INSN && any_condjump_p (insn))
            {
              rtx ifelse = SET_SRC (pc_set (insn));
-             rtx label;
-             int taken;
-
-             if (GET_CODE (XEXP (ifelse, 1)) == LABEL_REF)
-               {
-                 taken = 1;
-                 label = XEXP (XEXP (ifelse, 1), 0);
-               }
-             /* An inverted jump reverses the probabilities.  */
-             else if (GET_CODE (XEXP (ifelse, 2)) == LABEL_REF)
+             rtx then_dest = XEXP (ifelse, 1);
+             rtx else_dest = XEXP (ifelse, 2);
+             int taken = -1;
+
+             /* First check if we recognize any of the labels.  */
+             if (GET_CODE (then_dest) == LABEL_REF
+                 && XEXP (then_dest, 1) == if_true_label)
+               taken = 1;
+             else if (GET_CODE (then_dest) == LABEL_REF
+                      && XEXP (then_dest, 1) == if_false_label)
+               taken = 0;
+             else if (GET_CODE (else_dest) == LABEL_REF
+                      && XEXP (else_dest, 1) == if_false_label)
+               taken = 1;
+             else if (GET_CODE (else_dest) == LABEL_REF
+                      && XEXP (else_dest, 1) == if_true_label)
+               taken = 0;
+             /* Otherwise check where we drop through.  */
+             else if (else_dest == pc_rtx)
                {
-                 taken = 0;
-                 label = XEXP (XEXP (ifelse, 2), 0);
+                 if (next && GET_CODE (next) == NOTE)
+                   next = next_nonnote_insn (next);
+
+                 if (next && GET_CODE (next) == JUMP_INSN
+                     && any_uncondjump_p (next))
+                   next = XEXP (SET_SRC (pc_set (next)), 1);
+
+                 /* NEXT is either a CODE_LABEL, NULL_RTX or something
+                    else that can't possibly match either target label.  */
+                 if (next == if_false_label)
+                   taken = 1;
+                 else if (next == if_true_label)
+                   taken = 0;
                }
-             /* We shouldn't have to worry about conditional returns during
-                the expansion stage, but handle it gracefully anyway.  */
-             else if (GET_CODE (XEXP (ifelse, 1)) == RETURN)
+             else if (then_dest == pc_rtx)
                {
-                 taken = 1;
-                 label = NULL_RTX;
+                 if (next && GET_CODE (next) == NOTE)
+                   next = next_nonnote_insn (next);
+
+                 if (next && GET_CODE (next) == JUMP_INSN
+                     && any_uncondjump_p (next))
+                   next = XEXP (SET_SRC (pc_set (next)), 1);
+
+                 if (next == if_false_label)
+                   taken = 0;
+                 else if (next == if_true_label)
+                   taken = 1;
                }
-             /* An inverted return reverses the probabilities.  */
-             else if (GET_CODE (XEXP (ifelse, 2)) == RETURN)
+
+             if (taken != -1)
                {
-                 taken = 0;
-                 label = NULL_RTX;
+                 /* If the test is expected to fail, reverse the
+                    probabilities.  */
+                 if (integer_zerop (arg1))
+                   taken = 1 - taken;
+                 predict_insn_def (insn, PRED_BUILTIN_EXPECT, taken);
                }
-             else
-               goto do_next_insn;
-
-             /* If the test is expected to fail, reverse the
-                probabilities.  */
-             if (integer_zerop (arg1))
-               taken = 1 - taken;
-
-             /* If we are jumping to the false label, reverse the
-                probabilities.  */
-             if (label == NULL_RTX)
-               ;               /* conditional return */
-             else if (label == if_false_label)
-               taken = 1 - taken;
-             else if (label != if_true_label)
-               goto do_next_insn;
-
-             predict_insn_def (insn, PRED_BUILTIN_EXPECT, taken);
            }
 
-       do_next_insn:
          insn = next;
        }
     }