| author | |
| committer | |
| log | 4582ec518f9984a26c68b8427a914bad6dc80c4a |
| tree | bffaa526c169c38d1918afad3aa0315c0e9c551f |
| parent | 9a324ecb42f69791d49bc8e62e935aec75b5e920 |
| signature |
```zig
export fn entry() void {
var x: @Vector(4, i32) = undefined;
var y: [4]i32 = x;
}
```
```llvm
define void @entry() #2 !dbg !35 {
Entry:
%x = alloca <4 x i32>, align 16
%y = alloca [4 x i32], align 4
%0 = bitcast <4 x i32>* %x to i8*, !dbg !47
call void @llvm.memset.p0i8.i64(i8* align 16 %0, i8 -86, i64 16, i1 false), !dbg !47
call void @llvm.dbg.declare(metadata <4 x i32>* %x, metadata !39, metadata !DIExpression()), !dbg !47
%1 = load <4 x i32>, <4 x i32>* %x, align 16, !dbg !48
%2 = bitcast [4 x i32]* %y to <4 x i32>*, !dbg !48
store <4 x i32> %1, <4 x i32>* %2, align 16, !dbg !48
call void @llvm.dbg.declare(metadata [4 x i32]* %y, metadata !45, metadata !DIExpression()), !dbg !49
ret void, !dbg !50
}
```4 files changed, 17 insertions(+), 16 deletions(-)
src/all_types.hpp+1-1| ... | ... | @@ -3522,7 +3522,7 @@ struct IrInstructionVectorToArray { |
| 3522 | 3522 | IrInstruction base; |
| 3523 | 3523 | |
| 3524 | 3524 | IrInstruction *vector; |
| 3525 | LLVMValueRef tmp_ptr; | |
| 3525 | IrInstruction *result_loc; | |
| 3526 | 3526 | }; |
| 3527 | 3527 | |
| 3528 | 3528 | struct IrInstructionAssertZero { |
src/codegen.cpp+3-7| ... | ... | @@ -5386,12 +5386,12 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab |
| 5386 | 5386 | ZigType *array_type = instruction->base.value.type; |
| 5387 | 5387 | assert(array_type->id == ZigTypeIdArray); |
| 5388 | 5388 | assert(handle_is_ptr(array_type)); |
| 5389 | assert(instruction->tmp_ptr); | |
| 5389 | LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc); | |
| 5390 | 5390 | LLVMValueRef vector = ir_llvm_value(g, instruction->vector); |
| 5391 | LLVMValueRef casted_ptr = LLVMBuildBitCast(g->builder, instruction->tmp_ptr, | |
| 5391 | LLVMValueRef casted_ptr = LLVMBuildBitCast(g->builder, result_loc, | |
| 5392 | 5392 | LLVMPointerType(get_llvm_type(g, instruction->vector->value.type), 0), ""); |
| 5393 | 5393 | gen_store_untyped(g, vector, casted_ptr, 0, false); |
| 5394 | return instruction->tmp_ptr; | |
| 5394 | return result_loc; | |
| 5395 | 5395 | } |
| 5396 | 5396 | |
| 5397 | 5397 | static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executable, |
| ... | ... | @@ -6838,10 +6838,6 @@ static void do_code_gen(CodeGen *g) { |
| 6838 | 6838 | slot = &ref_instruction->tmp_ptr; |
| 6839 | 6839 | assert(instruction->value.type->id == ZigTypeIdPointer); |
| 6840 | 6840 | slot_type = instruction->value.type->data.pointer.child_type; |
| 6841 | } else if (instruction->id == IrInstructionIdVectorToArray) { | |
| 6842 | IrInstructionVectorToArray *vector_to_array_instruction = (IrInstructionVectorToArray *)instruction; | |
| 6843 | alignment_bytes = get_abi_alignment(g, vector_to_array_instruction->vector->value.type); | |
| 6844 | slot = &vector_to_array_instruction->tmp_ptr; | |
| 6845 | 6841 | } else { |
| 6846 | 6842 | zig_unreachable(); |
| 6847 | 6843 | } |
src/ir.cpp+11-7| ... | ... | @@ -3131,16 +3131,16 @@ static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, |
| 3131 | 3131 | } |
| 3132 | 3132 | |
| 3133 | 3133 | static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3134 | IrInstruction *vector, ZigType *result_type) | |
| 3134 | ZigType *result_type, IrInstruction *vector, IrInstruction *result_loc) | |
| 3135 | 3135 | { |
| 3136 | 3136 | IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb, |
| 3137 | 3137 | source_instruction->scope, source_instruction->source_node); |
| 3138 | 3138 | instruction->base.value.type = result_type; |
| 3139 | 3139 | instruction->vector = vector; |
| 3140 | instruction->result_loc = result_loc; | |
| 3140 | 3141 | |
| 3141 | 3142 | ir_ref_instruction(vector, ira->new_irb.current_basic_block); |
| 3142 | ||
| 3143 | ir_add_alloca(ira, &instruction->base, result_type); | |
| 3143 | ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); | |
| 3144 | 3144 | |
| 3145 | 3145 | return &instruction->base; |
| 3146 | 3146 | } |
| ... | ... | @@ -11985,7 +11985,7 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction * |
| 11985 | 11985 | } |
| 11986 | 11986 | |
| 11987 | 11987 | static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *source_instr, |
| 11988 | IrInstruction *vector, ZigType *array_type) | |
| 11988 | IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc) | |
| 11989 | 11989 | { |
| 11990 | 11990 | if (instr_is_comptime(vector)) { |
| 11991 | 11991 | // arrays and vectors have the same ConstExprValue representation |
| ... | ... | @@ -11994,7 +11994,11 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * |
| 11994 | 11994 | result->value.type = array_type; |
| 11995 | 11995 | return result; |
| 11996 | 11996 | } |
| 11997 | return ir_build_vector_to_array(ira, source_instr, vector, array_type); | |
| 11997 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr); | |
| 11998 | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { | |
| 11999 | return result_loc_inst; | |
| 12000 | } | |
| 12001 | return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst); | |
| 11998 | 12002 | } |
| 11999 | 12003 | |
| 12000 | 12004 | static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| ... | ... | @@ -12453,7 +12457,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12453 | 12457 | types_match_const_cast_only(ira, wanted_type->data.array.child_type, |
| 12454 | 12458 | actual_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk) |
| 12455 | 12459 | { |
| 12456 | return ir_analyze_vector_to_array(ira, source_instr, value, wanted_type); | |
| 12460 | return ir_analyze_vector_to_array(ira, source_instr, value, wanted_type, result_loc); | |
| 12457 | 12461 | } |
| 12458 | 12462 | |
| 12459 | 12463 | // cast from [N]T to @Vector(N, T) |
| ... | ... | @@ -24484,6 +24488,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24484 | 24488 | case IrInstructionIdPtrOfArrayToSlice: |
| 24485 | 24489 | case IrInstructionIdSliceGen: |
| 24486 | 24490 | case IrInstructionIdOptionalWrap: |
| 24491 | case IrInstructionIdVectorToArray: | |
| 24487 | 24492 | return true; |
| 24488 | 24493 | |
| 24489 | 24494 | case IrInstructionIdPhi: |
| ... | ... | @@ -24578,7 +24583,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24578 | 24583 | case IrInstructionIdFromBytes: |
| 24579 | 24584 | case IrInstructionIdToBytes: |
| 24580 | 24585 | case IrInstructionIdEnumToInt: |
| 24581 | case IrInstructionIdVectorToArray: | |
| 24582 | 24586 | case IrInstructionIdArrayToVector: |
| 24583 | 24587 | case IrInstructionIdHasDecl: |
| 24584 | 24588 | case IrInstructionIdAllocaSrc: |
src/ir_print.cpp+2-1| ... | ... | @@ -1102,7 +1102,8 @@ static void ir_print_array_to_vector(IrPrint *irp, IrInstructionArrayToVector *i |
| 1102 | 1102 | static void ir_print_vector_to_array(IrPrint *irp, IrInstructionVectorToArray *instruction) { |
| 1103 | 1103 | fprintf(irp->f, "VectorToArray("); |
| 1104 | 1104 | ir_print_other_instruction(irp, instruction->vector); |
| 1105 | fprintf(irp->f, ")"); | |
| 1105 | fprintf(irp->f, ")result="); | |
| 1106 | ir_print_other_instruction(irp, instruction->result_loc); | |
| 1106 | 1107 | } |
| 1107 | 1108 | |
| 1108 | 1109 | static void ir_print_ptr_of_array_to_slice(IrPrint *irp, IrInstructionPtrOfArrayToSlice *instruction) { |