[llvm] If a true/false branch of a conditional branch is marked as out-of-line, emit...
authorZoltan Varga <vargaz@gmail.com>
Tue, 9 Apr 2019 01:57:44 +0000 (21:57 -0400)
committerGitHub <noreply@github.com>
Tue, 9 Apr 2019 01:57:44 +0000 (21:57 -0400)
Commit migrated from https://github.com/mono/mono/commit/69b6667e2fbddaf15fa670b2c4b7ef1a9ddb7f8c

src/mono/mono/mini/mini-llvm.c

index eeb0ee2..35c9bbe 100644 (file)
@@ -4971,6 +4971,14 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
                        CompRelation rel;
                        LLVMValueRef cmp, args [16];
                        gboolean likely = (ins->flags & MONO_INST_LIKELY) != 0;
+                       gboolean unlikely = FALSE;
+
+                       if (MONO_IS_COND_BRANCH_OP (ins->next)) {
+                               if (ins->next->inst_false_bb->out_of_line)
+                                       likely = TRUE;
+                               else if (ins->next->inst_true_bb->out_of_line)
+                                       unlikely = TRUE;
+                       }
 
                        if (ins->next->opcode == OP_NOP)
                                break;
@@ -5026,9 +5034,9 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
                        } else
                                cmp = LLVMBuildICmp (builder, cond_to_llvm_cond [rel], lhs, rhs, "");
 
-                       if (likely) {
+                       if (likely || unlikely) {
                                args [0] = cmp;
-                               args [1] = LLVMConstInt (LLVMInt1Type (), 1, FALSE);
+                               args [1] = LLVMConstInt (LLVMInt1Type (), likely ? 1 : 0, FALSE);
                                cmp = LLVMBuildCall (ctx->builder, get_intrinsic (ctx, "llvm.expect.i1"), args, 2, "");
                        }