]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
iselStmtVec: take notice of the IR level branch hint.
authorJulian Seward <jseward@acm.org>
Tue, 26 Sep 2017 15:34:28 +0000 (17:34 +0200)
committerJulian Seward <jseward@acm.org>
Tue, 26 Sep 2017 15:34:28 +0000 (17:34 +0200)
When computing the cc to be embedded within the resulting HInstrIfThenElse,
it is necessary to take notice of the branch hint, and invert the sense of
the condition code if the |else| branch is to be the OOL one.

VEX/priv/host_x86_isel.c

index 721c159c23423ff82016ec291c9553b848aa1df4..b98a196198be978f948ffd73c3c594b69b727c38 100644 (file)
@@ -3926,10 +3926,16 @@ static void iselStmtVec(ISelEnv* env, IRStmtVec* stmts)
       HPhiNode* phi_nodes = convertPhiNodes(env, ite->phi_nodes,
                                             ite->hint, &n_phis);
 
-      X86CondCode cc         = iselCondCode(env, ite->cond);
-      /* Note: do not insert any instructions which alter |cc| before it
+      X86CondCode cc = iselCondCode(env, ite->cond);
+      /* cc is the condition code that will be true when we want to execute
+         the |then| branch.  That will be correct if the |then| branch is
+         the out-of-line (unlikely) one.  But if the |else| branch is the
+         OOL one then we need to invert the condition code. */
+      X86CondCode ccOOL
+         = (ite->hint == IfThenElse_ThenLikely) ? (cc ^ 1) : cc;
+      /* Note: do not insert any instructions which alter |ccOOL| before it
          is consumed by the corresponding branch. */
-      HInstrIfThenElse* hite = newHInstrIfThenElse(cc, phi_nodes, n_phis);
+      HInstrIfThenElse* hite = newHInstrIfThenElse(ccOOL, phi_nodes, n_phis);
       X86Instr* instr        = X86Instr_IfThenElse(hite);
       addInstr(env, instr);