From b60fe4f9f684da0cec798ba56a002b6a60d4811c Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Tue, 26 Sep 2017 17:34:28 +0200 Subject: [PATCH] iselStmtVec: take notice of the IR level branch hint. 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 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/VEX/priv/host_x86_isel.c b/VEX/priv/host_x86_isel.c index 721c159c23..b98a196198 100644 --- a/VEX/priv/host_x86_isel.c +++ b/VEX/priv/host_x86_isel.c @@ -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); -- 2.47.2