Skip to content

Commit 766e6c9

Browse files
committed
[mono] Always store to allocas in OP_LLVM_OUTARG_VT
OP_LLVM_OUTARG_VT will, for some argument passing conventions, create an alloca and mirror its source SSA value into this alloca. If such an OP_LLVM_OUTARG_VT is first encountered in a basic block that does not contain the definition of the SSA value being mirrored, then sibling basic blocks (e.g. a loop body that may sometimes be skipped) can use garbage data if they also have OP_LLVM_OUTARG_VT opcodes referring to the same SSA values. This commit works around this by unconditionally storing the source OP_LLVM_OUTARG_VT value into its associated alloca. The resulting IR would be a little easier to read if we eagerly stored to an alloca mirror exactly once at each value's definition, but that would require more work to implement.
1 parent 0bf7e14 commit 766e6c9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7486,7 +7486,7 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
74867486
addresses [ins->dreg] = addresses [ins->sreg1];
74877487
} else {
74887488
if (!addresses [ins->sreg1]) {
7489-
addresses [ins->sreg1] = build_alloca (ctx, t);
7489+
addresses [ins->sreg1] = build_named_alloca (ctx, t, "llvm_outarg_vt");
74907490
g_assert (values [ins->sreg1]);
74917491
LLVMBuildStore (builder, convert (ctx, values [ins->sreg1], type_to_llvm_type (ctx, t)), addresses [ins->sreg1]);
74927492
addresses [ins->dreg] = addresses [ins->sreg1];
@@ -7496,6 +7496,11 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
74967496
LLVMValueRef v = LLVMBuildLoad (builder, addresses [ins->sreg1], "llvm_outarg_vt_copy");
74977497
LLVMBuildStore (builder, convert (ctx, v, type_to_llvm_type (ctx, t)), addresses [ins->dreg]);
74987498
} else {
7499+
if (values [ins->sreg1]) {
7500+
LLVMTypeRef src_t = LLVMTypeOf (values [ins->sreg1]);
7501+
LLVMValueRef dst = convert (ctx, addresses [ins->sreg1], LLVMPointerType (src_t, 0));
7502+
LLVMBuildStore (builder, values [ins->sreg1], dst);
7503+
}
74997504
addresses [ins->dreg] = addresses [ins->sreg1];
75007505
}
75017506
}

0 commit comments

Comments
 (0)