diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 27c9120d2..78de94a64 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -352,6 +352,9 @@ typedef struct VarDecl_ bool shadow : 1; bool vararg : 1; bool is_static : 1; + bool is_read : 1; + bool is_written : 1; + bool is_addr : 1; bool is_threadlocal : 1; TypeInfo *type_info; union @@ -585,7 +588,12 @@ typedef struct Decl_ bool is_substruct : 1; bool has_variable_array : 1; bool no_scope : 1; - void *backend_ref; + bool is_value : 1; + union + { + void *backend_ref; + void *backend_value; + }; const char *extname; AlignSize alignment; const char *section; diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index cb974bb33..3864af281 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -763,6 +763,17 @@ void llvm_value_set_address_align(BEValue *value, LLVMValueRef llvm_value, Type value->type = type_lowering(type); } +void llvm_value_set_decl(BEValue *value, Decl *decl) +{ + decl = decl_flatten(decl); + if (decl->is_value) + { + llvm_value_set(value, decl->backend_value, decl->type); + return; + } + llvm_value_set_decl_address(value, decl); +} + void llvm_value_set_decl_address(BEValue *value, Decl *decl) { decl = decl_flatten(decl); @@ -1186,6 +1197,7 @@ LLVMValueRef llvm_store_aligned(GenContext *context, LLVMValueRef pointer, LLVMV void llvm_store_aligned_decl(GenContext *context, Decl *decl, LLVMValueRef value) { + assert(!decl->is_value); llvm_store_aligned(context, decl->backend_ref, value, decl->alignment); } @@ -1203,6 +1215,7 @@ void llvm_emit_memcpy(GenContext *c, LLVMValueRef dest, unsigned dest_align, LLV void llvm_emit_memcpy_to_decl(GenContext *c, Decl *decl, LLVMValueRef source, unsigned source_alignment) { if (source_alignment == 0) source_alignment = type_abi_alignment(decl->type); + assert(!decl->is_value); llvm_emit_memcpy(c, decl->backend_ref, decl->alignment, source, source_alignment, type_size(decl->type)); } diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index 30a3bf5e9..c10eec061 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -5181,8 +5181,8 @@ static inline void llvm_emit_argv_to_subarray(GenContext *c, BEValue *value, Exp { BEValue argc_value; BEValue argv_value; - llvm_value_set_decl_address(&argc_value, expr->argv_expr.argc); - llvm_value_set_decl_address(&argv_value, expr->argv_expr.argv); + llvm_value_set_decl(&argc_value, expr->argv_expr.argc); + llvm_value_set_decl(&argv_value, expr->argv_expr.argv); llvm_value_rvalue(c, &argc_value); llvm_value_rvalue(c, &argv_value); LLVMValueRef argv_ptr = argv_value.value; @@ -5374,7 +5374,7 @@ void llvm_emit_expr(GenContext *c, BEValue *value, Expr *expr) UNREACHABLE case EXPR_IDENTIFIER: case EXPR_CONST_IDENTIFIER: - llvm_value_set_decl_address(value, expr->identifier_expr.decl); + llvm_value_set_decl(value, expr->identifier_expr.decl); return; case EXPR_SUBSCRIPT: case EXPR_SUBSCRIPT_ADDR: diff --git a/src/compiler/llvm_codegen_function.c b/src/compiler/llvm_codegen_function.c index 9031aa18a..c9fa8ef63 100644 --- a/src/compiler/llvm_codegen_function.c +++ b/src/compiler/llvm_codegen_function.c @@ -133,6 +133,7 @@ static inline void llvm_process_parameter_value(GenContext *c, Decl *decl, unsig { // A simple memcopy, with alignment respected. LLVMValueRef pointer = llvm_get_next_param(c, index); + llvm_emit_and_set_decl_alloca(c, decl); llvm_emit_memcpy_to_decl(c, decl, pointer, info->indirect.alignment); return; } @@ -141,6 +142,7 @@ static inline void llvm_process_parameter_value(GenContext *c, Decl *decl, unsig // Create the expand type: LLVMTypeRef coerce_type = llvm_get_coerce_type(c, info); LLVMValueRef temp = LLVMBuildBitCast(c->builder, decl->backend_ref, LLVMPointerType(coerce_type, 0), "coerce"); + llvm_emit_and_set_decl_alloca(c, decl); AlignSize alignment = decl->alignment; AlignSize element_align; @@ -155,6 +157,7 @@ static inline void llvm_process_parameter_value(GenContext *c, Decl *decl, unsig } case ABI_ARG_DIRECT_PAIR: { + llvm_emit_and_set_decl_alloca(c, decl); // Here we do the following transform: // lo, hi -> { lo, hi } -> struct LLVMTypeRef lo = llvm_abi_type(c, info->direct_pair.lo); @@ -175,6 +178,14 @@ static inline void llvm_process_parameter_value(GenContext *c, Decl *decl, unsig return; } case ABI_ARG_DIRECT: + DIRECT_FROM_COERCE: + if (!decl->var.is_written && !decl->var.is_addr) + { + decl->backend_value = llvm_get_next_param(c, index); + decl->is_value = true; + return; + } + llvm_emit_and_set_decl_alloca(c, decl); llvm_store_aligned_decl(c, decl, llvm_get_next_param(c, index)); return; case ABI_ARG_DIRECT_COERCE: @@ -182,9 +193,9 @@ static inline void llvm_process_parameter_value(GenContext *c, Decl *decl, unsig LLVMTypeRef coerce_type = llvm_get_coerce_type(c, info); if (!coerce_type || coerce_type == llvm_get_type(c, decl->type)) { - llvm_store_aligned_decl(c, decl, llvm_get_next_param(c, index)); - return; + goto DIRECT_FROM_COERCE; } + llvm_emit_and_set_decl_alloca(c, decl); // If we're not flattening, we simply do a store. if (!abi_info_should_flatten(info)) @@ -214,6 +225,7 @@ static inline void llvm_process_parameter_value(GenContext *c, Decl *decl, unsig } case ABI_ARG_EXPAND: { + llvm_emit_and_set_decl_alloca(c, decl); llvm_expand_from_args(c, decl->type, decl->backend_ref, index, decl->alignment); if (info->expand.padding_type) { @@ -228,7 +240,6 @@ static inline void llvm_emit_parameter(GenContext *context, Decl *decl, unsigned assert(decl->decl_kind == DECL_VAR && decl->var.kind == VARDECL_PARAM); // Allocate room on stack, but do not copy. - llvm_emit_and_set_decl_alloca(context, decl); llvm_process_parameter_value(context, decl, index); if (llvm_use_debug(context)) { diff --git a/src/compiler/llvm_codegen_internal.h b/src/compiler/llvm_codegen_internal.h index 04bff7e58..9a89fb087 100644 --- a/src/compiler/llvm_codegen_internal.h +++ b/src/compiler/llvm_codegen_internal.h @@ -213,6 +213,7 @@ void llvm_value_set_int(GenContext *c, BEValue *value, Type *type, uint64_t i); void llvm_value_set_address_align(BEValue *value, LLVMValueRef llvm_value, Type *type, AlignSize alignment); void llvm_value_set_address(BEValue *value, LLVMValueRef llvm_value, Type *type); void llvm_value_set_decl_address(BEValue *value, Decl *decl); +void llvm_value_set_decl(BEValue *value, Decl *decl); void llvm_value_fold_failable(GenContext *c, BEValue *value); void llvm_value_struct_gep(GenContext *c, BEValue *element, BEValue *struct_pointer, unsigned index); @@ -346,6 +347,7 @@ static inline LLVMValueRef decl_failable_ref(Decl *decl) static inline LLVMValueRef decl_ref(Decl *decl) { if (decl->decl_kind == DECL_VAR && decl->var.kind == VARDECL_UNWRAPPED) return decl_ref(decl->var.alias); + assert(!decl->is_value); return decl->backend_ref; } diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 7f03a3944..1d8c513bc 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -894,6 +894,7 @@ static inline bool sema_expr_analyse_identifier(SemaContext *context, Type *to, } if (decl->decl_kind == DECL_VAR) { + decl->var.is_read = true; switch (decl->var.kind) { case VARDECL_CONST: @@ -4183,6 +4184,8 @@ static bool sema_expr_analyse_assign(SemaContext *context, Expr *expr, Expr *lef return false; } + if (left->expr_kind == EXPR_IDENTIFIER) left->identifier_expr.decl->var.is_written = true; + bool is_unwrapped_var = expr_is_unwrapped_ident(left); // 3. Evaluate right side to required type. @@ -4257,6 +4260,8 @@ static bool sema_expr_analyse_common_assign(SemaContext *context, Expr *expr, Ex return false; } + if (left->expr_kind == EXPR_IDENTIFIER) left->identifier_expr.decl->var.is_written = true; + Type *no_fail = type_no_fail(left->type); // 3. If this is only defined for ints (*%, ^= |= &= %=) verify that this is an int. @@ -4354,6 +4359,8 @@ static bool sema_expr_analyse_add_sub_assign(SemaContext *context, Expr *expr, E return false; } + if (left->expr_kind == EXPR_IDENTIFIER) left->identifier_expr.decl->var.is_written = true; + Type *left_type_canonical = left->type->canonical; // 4. Analyse right hand side @@ -4919,6 +4926,8 @@ static bool sema_expr_analyse_shift_assign(SemaContext *context, Expr *expr, Exp return false; } + if (left->expr_kind == EXPR_IDENTIFIER) left->identifier_expr.decl->var.is_written = true; + // 3. Only integers may be shifted. if (!both_any_integer_or_integer_vector(left, right)) return sema_type_error_on_binop(expr); @@ -5199,6 +5208,7 @@ static bool sema_expr_analyse_deref(SemaContext *context, Expr *expr) static inline bool sema_take_addr_of_var(Expr *expr, Decl *decl) { if (decl->decl_kind != DECL_VAR) return false; + decl->var.is_addr = true; bool is_void = type_flatten(decl->type) == type_void; switch (decl->var.kind) { @@ -5533,6 +5543,8 @@ static inline bool sema_expr_analyse_incdec(SemaContext *context, Expr *expr) return false; } + if (inner->expr_kind == EXPR_IDENTIFIER) inner->identifier_expr.decl->var.is_written = true; + // 3. This might be a $foo, if to handle it. if (inner->expr_kind == EXPR_CT_IDENT) { diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index 8bbd1a815..c5aa816fc 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -196,6 +196,8 @@ static inline bool sema_analyse_try_unwrap(SemaContext *context, Expr *expr) return false; } + if (ident->expr_kind == EXPR_IDENTIFIER) ident->identifier_expr.decl->var.is_written = true; + // 3c. It can't be failable either. if (IS_FAILABLE(ident)) { @@ -336,6 +338,8 @@ static inline bool sema_analyse_catch_unwrap(SemaContext *context, Expr *expr) return false; } + if (ident->expr_kind == EXPR_IDENTIFIER) ident->identifier_expr.decl->var.is_written = true; + if (ident->type->canonical != type_anyerr) { SEMA_ERROR(ident, "Expected the variable to have the type %s, not %s.", type_quoted_error_string(type_anyerr), @@ -1297,8 +1301,10 @@ static inline bool sema_analyse_foreach_stmt(SemaContext *context, Ast *statemen bool is_variable = false; if (expr_is_ltype(enumerator)) { + if (enumerator->expr_kind == EXPR_IDENTIFIER) { + enumerator->identifier_expr.decl->var.is_written = true; is_variable = true; } else diff --git a/src/version.h b/src/version.h index 590077abd..6bb16ea80 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "PRE.9" \ No newline at end of file +#define COMPILER_VERSION "PRE.10" \ No newline at end of file diff --git a/test/test_suite/abi/vec2_aarch64.c3t b/test/test_suite/abi/vec2_aarch64.c3t index 014c4f562..24f350614 100644 --- a/test/test_suite/abi/vec2_aarch64.c3t +++ b/test/test_suite/abi/vec2_aarch64.c3t @@ -64,14 +64,12 @@ entry: define %Vector2 @vector2_add_value(float %0, float %1, float %2) entry: %v = alloca %Vector2, align 4 - %add = alloca float, align 4 %literal = alloca %Vector2, align 4 %coerce = bitcast %Vector2* %v to { float, float }* %3 = getelementptr inbounds { float, float }, { float, float }* %coerce, i32 0, i32 0 store float %0, float* %3, align 4 %4 = getelementptr inbounds { float, float }, { float, float }* %coerce, i32 0, i32 1 store float %1, float* %4, align 4 - store float %2, float* %add, align 4 %5 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 0 store float 0.000000e+00, float* %5, align 4 %6 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 1 @@ -106,14 +104,12 @@ entry: define %Vector2 @vector2_subtract_value(float %0, float %1, float %2) entry: %v = alloca %Vector2, align 4 - %sub = alloca float, align 4 %literal = alloca %Vector2, align 4 %coerce = bitcast %Vector2* %v to { float, float }* %3 = getelementptr inbounds { float, float }, { float, float }* %coerce, i32 0, i32 0 store float %0, float* %3, align 4 %4 = getelementptr inbounds { float, float }, { float, float }* %coerce, i32 0, i32 1 store float %1, float* %4, align 4 - store float %2, float* %sub, align 4 %5 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 0 store float 0.000000e+00, float* %5, align 4 %6 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 1 diff --git a/test/test_suite/abi/vec2_wasm.c3t b/test/test_suite/abi/vec2_wasm.c3t index ca4fa2b39..27db72fac 100644 --- a/test/test_suite/abi/vec2_wasm.c3t +++ b/test/test_suite/abi/vec2_wasm.c3t @@ -67,12 +67,10 @@ entry: define void @vector2_add_value(%Vector2* noalias sret(%Vector2) align 4 %0, %Vector2* byval(%Vector2) align 4 %1, float %2) #0 { entry: %v = alloca %Vector2, align 4 - %add = alloca float, align 4 %literal = alloca %Vector2, align 4 %3 = bitcast %Vector2* %v to i8* %4 = bitcast %Vector2* %1 to i8* call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %3, i8* align 4 %4, i32 8, i1 false) - store float %2, float* %add, align 4 %5 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 0 store float 0.000000e+00, float* %5, align 4 %6 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 1 @@ -107,12 +105,10 @@ entry: define void @vector2_subtract_value(%Vector2* noalias sret(%Vector2) align 4 %0, %Vector2* byval(%Vector2) align 4 %1, float %2) #0 { entry: %v = alloca %Vector2, align 4 - %sub = alloca float, align 4 %literal = alloca %Vector2, align 4 %3 = bitcast %Vector2* %v to i8* %4 = bitcast %Vector2* %1 to i8* call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %3, i8* align 4 %4, i32 8, i1 false) - store float %2, float* %sub, align 4 %5 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 0 store float 0.000000e+00, float* %5, align 4 %6 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 1 diff --git a/test/test_suite/abi/vec2_x64.c3t b/test/test_suite/abi/vec2_x64.c3t index b477afbc3..0a5c551f0 100644 --- a/test/test_suite/abi/vec2_x64.c3t +++ b/test/test_suite/abi/vec2_x64.c3t @@ -16,7 +16,7 @@ extern fn Vector2 vector2_subtract_value(Vector2 v, float sub) { return Vector2 %Vector2 = type { float, float } -define <2 x float> @vector2_zero() +define <2 x float> @vector2_zero() #0 { entry: %literal = alloca %Vector2, align 4 %tempcoerce = alloca <2 x float>, align 8 @@ -31,7 +31,8 @@ entry: ret <2 x float> %4 } -define <2 x float> @vector2_one() +define <2 x float> @vector2_one() #0 { +entry: %literal = alloca %Vector2, align 4 %tempcoerce = alloca <2 x float>, align 8 %0 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 0 @@ -45,7 +46,7 @@ define <2 x float> @vector2_one() ret <2 x float> %4 } -define <2 x float> @vector2_add(<2 x float> %0, <2 x float> %1) +define <2 x float> @vector2_add(<2 x float> %0, <2 x float> %1) #0 { entry: %v1 = alloca %Vector2, align 4 %v2 = alloca %Vector2, align 4 @@ -67,13 +68,12 @@ entry: } define <2 x float> @vector2_add_value(<2 x float> %0, float %1) #0 { +entry: %v = alloca %Vector2, align 4 - %add = alloca float, align 4 %literal = alloca %Vector2, align 4 %tempcoerce = alloca <2 x float>, align 8 %2 = bitcast %Vector2* %v to <2 x float>* store <2 x float> %0, <2 x float>* %2, align 4 - store float %1, float* %add, align 4 %3 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 0 store float 0.000000e+00, float* %3, align 4 %4 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 1 @@ -85,7 +85,7 @@ define <2 x float> @vector2_add_value(<2 x float> %0, float %1) #0 { ret <2 x float> %7 } -define <2 x float> @vector2_subtract(<2 x float> %0, <2 x float> %1) +define <2 x float> @vector2_subtract(<2 x float> %0, <2 x float> %1) #0 { entry: %v1 = alloca %Vector2, align 4 %v2 = alloca %Vector2, align 4 @@ -106,15 +106,13 @@ entry: ret <2 x float> %8 } -define <2 x float> @vector2_subtract_value(<2 x float> %0, float %1) +define <2 x float> @vector2_subtract_value(<2 x float> %0, float %1) #0 { entry: %v = alloca %Vector2, align 4 - %sub = alloca float, align 4 %literal = alloca %Vector2, align 4 %tempcoerce = alloca <2 x float>, align 8 %2 = bitcast %Vector2* %v to <2 x float>* store <2 x float> %0, <2 x float>* %2, align 4 - store float %1, float* %sub, align 4 %3 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 0 store float 0.000000e+00, float* %3, align 4 %4 = getelementptr inbounds %Vector2, %Vector2* %literal, i32 0, i32 1 diff --git a/test/test_suite/arrays/array_literal.c3t b/test/test_suite/arrays/array_literal.c3t index 9d343d267..6765f03a5 100644 --- a/test/test_suite/arrays/array_literal.c3t +++ b/test/test_suite/arrays/array_literal.c3t @@ -16,14 +16,13 @@ fn double test(uint x) @.__const = private constant [30 x double] [double 0.000000e+00, double 1.270600e+01, double 4.303000e+00, double 3.182000e+00, double 2.776000e+00, double 2.571000e+00, double 2.447000e+00, double 2.365000e+00, double 2.306000e+00, double 2.262000e+00, double 2.228000e+00, double 2.201000e+00, double 2.179000e+00, double 2.160000e+00, double 2.145000e+00, double 2.131000e+00, double 2.120000e+00, double 2.110000e+00, double 2.101000e+00, double 2.093000e+00, double 2.086000e+00, double 2.080000e+00, double 2.074000e+00, double 2.069000e+00, double 2.064000e+00, double 2.060000e+00, double 2.056000e+00, double 2.052000e+00, double 2.048000e+00, double 2.045000e+00], align 16 +define double @array_literal.test(i32 %0) #0 { entry: - %x = alloca i32, align 4 %student_t = alloca [30 x double], align 16 - store i32 %0, i32* %x, align 4 %1 = bitcast [30 x double]* %student_t to i8* call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 16 %1, i8* align 16 bitcast ([30 x double]* @.__const to i8*), i32 240, i1 false) - %2 = load i32, i32* %x, align 4 - %uiuiext = zext i32 %2 to i64 - %3 = getelementptr inbounds [30 x double], [30 x double]* %student_t, i64 0, i64 %uiuiext - %4 = load double, double* %3, align 8 - ret double %4 + %uiuiext = zext i32 %0 to i64 + %2 = getelementptr inbounds [30 x double], [30 x double]* %student_t, i64 0, i64 %uiuiext + %3 = load double, double* %2, align 8 + ret double %3 +} diff --git a/test/test_suite/arrays/index_into_global.c3t b/test/test_suite/arrays/index_into_global.c3t index 9c6338da0..869c1a11d 100644 --- a/test/test_suite/arrays/index_into_global.c3t +++ b/test/test_suite/arrays/index_into_global.c3t @@ -24,14 +24,10 @@ fn void test_bar(int idx) define void @foo.test_bar(i32 %0) #0 { entry: - %idx = alloca i32, align 4 - store i32 %0, i32* %idx, align 4 - %1 = load i32, i32* %idx, align 4 - %sisiext = sext i32 %1 to i64 - %2 = getelementptr inbounds [6 x %Bar], [6 x %Bar]* @foo.bar, i64 0, i64 %sisiext - %3 = getelementptr inbounds %Bar, %Bar* %2, i32 0, i32 0 - store i32 0, i32* %3, align 4 - %4 = load i32, i32* %idx, align 4 - store i32 %4, i32* getelementptr inbounds ([6 x %Bar], [6 x %Bar]* @foo.bar, i64 0, i64 0, i32 0), align 4 + %sisiext = sext i32 %0 to i64 + %1 = getelementptr inbounds [6 x %Bar], [6 x %Bar]* @foo.bar, i64 0, i64 %sisiext + %2 = getelementptr inbounds %Bar, %Bar* %1, i32 0, i32 0 + store i32 0, i32* %2, align 4 + store i32 %0, i32* getelementptr inbounds ([6 x %Bar], [6 x %Bar]* @foo.bar, i64 0, i64 0, i32 0), align 4 ret void -} \ No newline at end of file +} diff --git a/test/test_suite/builtins/simple_builtins.c3t b/test/test_suite/builtins/simple_builtins.c3t index e73bdcf90..761ce25ad 100644 --- a/test/test_suite/builtins/simple_builtins.c3t +++ b/test/test_suite/builtins/simple_builtins.c3t @@ -20,42 +20,39 @@ fn int foo(double b) define i32 @foo.foo(double %0) #0 { entry: - %b = alloca double, align 8 %d = alloca double, align 8 %e = alloca double, align 8 %f = alloca double, align 8 %xeb = alloca i32, align 4 %abcd = alloca [3 x i32], align 4 %sy = alloca i32, align 4 - store double %0, double* %b, align 8 - %1 = load double, double* %b, align 8 - %2 = call double @llvm.ceil.f64(double %1) - store double %2, double* %d, align 8 - %3 = call double @llvm.maxnum.f64(double 1.000000e+00, double 1.000000e+00) - store double %3, double* %e, align 8 + %1 = call double @llvm.ceil.f64(double %0) + store double %1, double* %d, align 8 + %2 = call double @llvm.maxnum.f64(double 1.000000e+00, double 1.000000e+00) + store double %2, double* %e, align 8 + %3 = load double, double* %d, align 8 %4 = load double, double* %d, align 8 %5 = load double, double* %d, align 8 - %6 = load double, double* %d, align 8 - %7 = call double @llvm.fma.f64(double %4, double %5, double %6) - store double %7, double* %f, align 8 + %6 = call double @llvm.fma.f64(double %3, double %4, double %5) + store double %6, double* %f, align 8 store i32 13, i32* %xeb, align 4 - %8 = getelementptr inbounds [3 x i32], [3 x i32]* %abcd, i64 0, i64 0 + %7 = getelementptr inbounds [3 x i32], [3 x i32]* %abcd, i64 0, i64 0 + store i32 0, i32* %7, align 4 + %8 = getelementptr inbounds [3 x i32], [3 x i32]* %abcd, i64 0, i64 1 store i32 0, i32* %8, align 4 - %9 = getelementptr inbounds [3 x i32], [3 x i32]* %abcd, i64 0, i64 1 + %9 = getelementptr inbounds [3 x i32], [3 x i32]* %abcd, i64 0, i64 2 store i32 0, i32* %9, align 4 - %10 = getelementptr inbounds [3 x i32], [3 x i32]* %abcd, i64 0, i64 2 - store i32 0, i32* %10, align 4 - %11 = load volatile i32, i32* %xeb, align 4 - store i32 %11, i32* %sy, align 4 - %12 = load i32, i32* %sy, align 4 - %add = add i32 %12, 1 + %10 = load volatile i32, i32* %xeb, align 4 + store i32 %10, i32* %sy, align 4 + %11 = load i32, i32* %sy, align 4 + %add = add i32 %11, 1 store volatile i32 %add, i32* %xeb, align 4 - %13 = getelementptr inbounds [3 x i32], [3 x i32]* %abcd, i64 0, i64 2 - %14 = load i32, i32* %sy, align 4 - %add1 = add i32 %14, 2 - store volatile i32 %add1, i32* %13, align 4 - %15 = getelementptr inbounds [3 x i32], [3 x i32]* %abcd, i64 0, i64 2 - %16 = load volatile i32, i32* %15, align 4 - store i32 %16, i32* %sy, align 4 + %12 = getelementptr inbounds [3 x i32], [3 x i32]* %abcd, i64 0, i64 2 + %13 = load i32, i32* %sy, align 4 + %add1 = add i32 %13, 2 + store volatile i32 %add1, i32* %12, align 4 + %14 = getelementptr inbounds [3 x i32], [3 x i32]* %abcd, i64 0, i64 2 + %15 = load volatile i32, i32* %14, align 4 + store i32 %15, i32* %sy, align 4 ret i32 1 } \ No newline at end of file diff --git a/test/test_suite/errors/general_error_regression.c3t b/test/test_suite/errors/general_error_regression.c3t index 42c7942fc..fb8338389 100644 --- a/test/test_suite/errors/general_error_regression.c3t +++ b/test/test_suite/errors/general_error_regression.c3t @@ -73,24 +73,18 @@ fn void main() define void @foo.Foo__hello(i64* %0) #0 { entry: - %f = alloca i64*, align 8 - store i64* %0, i64** %f, align 8 %1 = call i32 @"std::io.println"(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i32 0, i32 0)) #1 ret void } define void @foo.Bar__hello(i32* %0) #0 { entry: - %b = alloca i32*, align 8 - store i32* %0, i32** %b, align 8 %1 = call i32 @"std::io.println"(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i32 0, i32 0)) #1 ret void } define void @foo.MyEnum__hello(i32* %0) #0 { entry: - %myenum = alloca i32*, align 8 - store i32* %0, i32** %myenum, align 8 %1 = call i32 @"std::io.println"(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i32 0, i32 0)) #1 ret void } diff --git a/test/test_suite/errors/try_unwrap_using_assert.c3t b/test/test_suite/errors/try_unwrap_using_assert.c3t index 13be65c5c..e2847bd96 100644 --- a/test/test_suite/errors/try_unwrap_using_assert.c3t +++ b/test/test_suite/errors/try_unwrap_using_assert.c3t @@ -15,12 +15,10 @@ fn int tester(int n) define i32 @test.tester(i32 %0) #0 { entry: - %n = alloca i32, align 4 %num = alloca i32, align 4 %num.f = alloca i64, align 8 %retparam = alloca i32, align 4 %x = alloca i32, align 4 - store i32 %0, i32* %n, align 4 %1 = call i64 @maybe(i32* %retparam) %not_err = icmp eq i64 %1, 0 br i1 %not_err, label %after.errcheck, label %error diff --git a/test/test_suite/errors/try_with_unwrapper.c3t b/test/test_suite/errors/try_with_unwrapper.c3t index 5f48b7f6d..394d0c5ce 100644 --- a/test/test_suite/errors/try_with_unwrapper.c3t +++ b/test/test_suite/errors/try_with_unwrapper.c3t @@ -46,10 +46,7 @@ fn void test2() ; Function Attrs: nounwind define i32 @try_with_unwrapper.hello(i32 %0) #0 { entry: - %x = alloca i32, align 4 - store i32 %0, i32* %x, align 4 - %1 = load i32, i32* %x, align 4 - %add = add i32 %1, 1 + %add = add i32 %0, 1 ret i32 %add } diff --git a/test/test_suite/expressions/elvis.c3t b/test/test_suite/expressions/elvis.c3t index f85342de4..925829c05 100644 --- a/test/test_suite/expressions/elvis.c3t +++ b/test/test_suite/expressions/elvis.c3t @@ -17,36 +17,51 @@ fn bool elvis3(bool x, bool y) // #expect: elvis.ll - store i32* %0, i32** %x - store i32* %1, i32** %y - %2 = load i32*, i32** %x - %ptrbool = icmp ne i32* %2, null - br i1 %ptrbool, label %cond.phi, label %cond.rhs -cond.rhs: - %3 = load i32*, i32** %y - br label %cond.phi -cond.phi: - %val = phi i32* [ %2, %entry ], [ %3, %cond.rhs ] - ret i32* %val +define i32* @elvis.elvis(i32* %0, i32* %1) #0 { +entry: + %ptrbool = icmp ne i32* %0, null + br i1 %ptrbool, label %cond.phi, label %cond.rhs - store i32* %0, i32** %x - store i32* %1, i32** %y - %2 = load i32*, i32** %x - %ptrbool = icmp ne i32* %2, null - br i1 %ptrbool, label %cond.phi3, label %cond.rhs -cond.rhs: - %3 = load i32*, i32** %y - %ptrbool1 = icmp ne i32* %3, null - br i1 %ptrbool1, label %cond.phi, label %cond.rhs2 +cond.rhs: ; preds = %entry + br label %cond.phi -cond.rhs2: - %4 = load i32*, i32** %x - br label %cond.phi +cond.phi: ; preds = %cond.rhs, %entry + %val = phi i32* [ %0, %entry ], [ %1, %cond.rhs ] + ret i32* %val +} -cond.phi: - %val = phi i32* [ %3, %cond.rhs ], [ %4, %cond.rhs2 ] - br label %cond.phi3 +define i32* @elvis.elvis2(i32* %0, i32* %1) #0 { +entry: + %ptrbool = icmp ne i32* %0, null + br i1 %ptrbool, label %cond.phi3, label %cond.rhs -cond.phi3: - %val4 = phi i32* [ %2, %entry ], [ %val, %cond.phi ] - ret i32* %val4 +cond.rhs: ; preds = %entry + %ptrbool1 = icmp ne i32* %1, null + br i1 %ptrbool1, label %cond.phi, label %cond.rhs2 + +cond.rhs2: ; preds = %cond.rhs + br label %cond.phi + +cond.phi: ; preds = %cond.rhs2, %cond.rhs + %val = phi i32* [ %1, %cond.rhs ], [ %0, %cond.rhs2 ] + br label %cond.phi3 + +cond.phi3: ; preds = %cond.phi, %entry + %val4 = phi i32* [ %0, %entry ], [ %val, %cond.phi ] + ret i32* %val4 +} + +define zeroext i8 @elvis.elvis3(i8 zeroext %0, i8 zeroext %1) #0 { +entry: + %2 = trunc i8 %0 to i1 + br i1 %2, label %cond.phi, label %cond.rhs + +cond.rhs: ; preds = %entry + %3 = trunc i8 %1 to i1 + br label %cond.phi + +cond.phi: ; preds = %cond.rhs, %entry + %val = phi i1 [ %2, %entry ], [ %3, %cond.rhs ] + %4 = zext i1 %val to i8 + ret i8 %4 +} diff --git a/test/test_suite/expressions/simple_float_sub_neg.c3t b/test/test_suite/expressions/simple_float_sub_neg.c3t index 4b434d6aa..79cb304ab 100644 --- a/test/test_suite/expressions/simple_float_sub_neg.c3t +++ b/test/test_suite/expressions/simple_float_sub_neg.c3t @@ -7,21 +7,11 @@ fn double test(double a, double b, double c, double d) // #expect: simple_float_sub_neg.ll +define double @simple_float_sub_neg.test(double %0, double %1, double %2, double %3) #0 { entry: - %a = alloca double, align 8 - %b = alloca double, align 8 - %c = alloca double, align 8 - %d = alloca double, align 8 - store double %0, double* %a, align 8 - store double %1, double* %b, align 8 - store double %2, double* %c, align 8 - store double %3, double* %d, align 8 - %4 = load double, double* %a, align 8 - %5 = load double, double* %b, align 8 - %fsub = fsub double %4, %5 + %fsub = fsub double %0, %1 %fneg = fneg double %fsub - %6 = load double, double* %c, align 8 - %7 = load double, double* %d, align 8 - %fsub1 = fsub double %6, %7 + %fsub1 = fsub double %2, %3 %fsub2 = fsub double %fneg, %fsub1 - ret double %fsub2 \ No newline at end of file + ret double %fsub2 +} diff --git a/test/test_suite/from_docs/examples_defer.c3t b/test/test_suite/from_docs/examples_defer.c3t index ab16b1a91..0ca07f8b0 100644 --- a/test/test_suite/from_docs/examples_defer.c3t +++ b/test/test_suite/from_docs/examples_defer.c3t @@ -25,54 +25,50 @@ fn void main() define void @defer1.test(i32 %0) #0 { entry: - %x = alloca i32, align 4 - store i32 %0, i32* %x, align 4 - %1 = load i32, i32* %x, align 4 - %eq = icmp eq i32 %1, 1 + %eq = icmp eq i32 %0, 1 br i1 %eq, label %if.then, label %if.exit if.then: ; preds = %entry - %2 = call i32 @"std::io.print"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0)) + %1 = call i32 @"std::io.print"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0)) br label %exit exit: ; preds = %if.then - %3 = call i32 @"std::io.println"(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0)) #1 + %2 = call i32 @"std::io.println"(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0)) #1 br label %exit1 exit1: ; preds = %exit ret void if.exit: ; preds = %entry - %4 = load i32, i32* %x, align 4 - %eq2 = icmp eq i32 %4, 0 + %eq2 = icmp eq i32 %0, 0 br i1 %eq2, label %if.then3, label %if.exit7 if.then3: ; preds = %if.exit - %5 = call i32 @"std::io.print"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0)) + %3 = call i32 @"std::io.print"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0)) br label %exit4 exit4: ; preds = %if.then3 - %6 = call i32 @"std::io.print"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0)) + %4 = call i32 @"std::io.print"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0)) br label %exit5 exit5: ; preds = %exit4 - %7 = call i32 @"std::io.println"(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i32 0, i32 0)) #1 + %5 = call i32 @"std::io.println"(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i32 0, i32 0)) #1 br label %exit6 exit6: ; preds = %exit5 ret void if.exit7: ; preds = %if.exit - %8 = call i32 @"std::io.print"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i32 0, i32 0)) + %6 = call i32 @"std::io.print"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i32 0, i32 0)) br label %exit8 exit8: ; preds = %if.exit7 - %9 = call i32 @"std::io.print"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0)) - %10 = call i32 @"std::io.print"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0)) + %7 = call i32 @"std::io.print"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0)) + %8 = call i32 @"std::io.print"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0)) br label %exit9 exit9: ; preds = %exit8 - %11 = call i32 @"std::io.println"(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.8, i32 0, i32 0)) #1 + %9 = call i32 @"std::io.println"(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.8, i32 0, i32 0)) #1 br label %exit10 exit10: ; preds = %exit9 diff --git a/test/test_suite/from_docs/examples_forswitch.c3t b/test/test_suite/from_docs/examples_forswitch.c3t index c867d95c0..943041707 100644 --- a/test/test_suite/from_docs/examples_forswitch.c3t +++ b/test/test_suite/from_docs/examples_forswitch.c3t @@ -117,7 +117,6 @@ loop.exit: ; preds = %loop.cond ; Function Attrs: nounwind define void @examples.demo_enum(i32 %0) #0 { entry: - %h = alloca i32, align 4 %switch = alloca i32, align 4 %switch2 = alloca i32, align 4 %switch7 = alloca i32, align 4 @@ -125,56 +124,52 @@ entry: %switch17 = alloca i32, align 4 %a = alloca i32, align 4 %a21 = alloca i32, align 4 - store i32 %0, i32* %h, align 4 - %1 = load i32, i32* %h, align 4 - store i32 %1, i32* %switch, align 4 + store i32 %0, i32* %switch, align 4 br label %switch.entry switch.entry: ; preds = %entry - %2 = load i32, i32* %switch, align 4 - switch i32 %2, label %switch.exit [ + %1 = load i32, i32* %switch, align 4 + switch i32 %1, label %switch.exit [ i32 0, label %switch.case i32 1, label %switch.case i32 2, label %switch.case1 ] switch.case: ; preds = %switch.entry, %switch.entry - %3 = call i32 @"std::io.println"(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0)) #1 + %2 = call i32 @"std::io.println"(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0)) #1 br label %switch.exit switch.case1: ; preds = %switch.entry - %4 = call i32 @"std::io.println"(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0)) #1 + %3 = call i32 @"std::io.println"(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0)) #1 br label %switch.exit switch.exit: ; preds = %switch.case1, %switch.case, %switch.entry - %5 = load i32, i32* %h, align 4 - store i32 %5, i32* %switch2, align 4 + store i32 %0, i32* %switch2, align 4 br label %switch.entry3 switch.entry3: ; preds = %switch.exit - %6 = load i32, i32* %switch2, align 4 - switch i32 %6, label %switch.exit6 [ + %4 = load i32, i32* %switch2, align 4 + switch i32 %4, label %switch.exit6 [ i32 0, label %switch.case4 i32 1, label %switch.case4 i32 2, label %switch.case5 ] switch.case4: ; preds = %switch.entry3, %switch.entry3 - %7 = call i32 @"std::io.println"(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0)) #1 + %5 = call i32 @"std::io.println"(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0)) #1 br label %switch.exit6 switch.case5: ; preds = %switch.entry3 - %8 = call i32 @"std::io.println"(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0)) #1 + %6 = call i32 @"std::io.println"(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0)) #1 br label %switch.exit6 switch.exit6: ; preds = %switch.case5, %switch.case4, %switch.entry3 - %9 = load i32, i32* %h, align 4 - store i32 %9, i32* %switch7, align 4 + store i32 %0, i32* %switch7, align 4 br label %switch.entry8 switch.entry8: ; preds = %switch.exit6 - %10 = load i32, i32* %switch7, align 4 - switch i32 %10, label %switch.exit12 [ + %7 = load i32, i32* %switch7, align 4 + switch i32 %7, label %switch.exit12 [ i32 0, label %switch.case9 i32 1, label %switch.case10 i32 2, label %switch.case11 @@ -184,20 +179,19 @@ switch.case9: ; preds = %switch.entry8 br label %switch.exit12 switch.case10: ; preds = %switch.entry8 - %11 = call i32 @"std::io.println"(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0)) #1 + %8 = call i32 @"std::io.println"(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0)) #1 br label %switch.exit12 switch.case11: ; preds = %switch.entry8 br label %switch.exit12 switch.exit12: ; preds = %switch.case11, %switch.case10, %switch.case9, %switch.entry8 - %12 = load i32, i32* %h, align 4 - store i32 %12, i32* %switch13, align 4 + store i32 %0, i32* %switch13, align 4 br label %switch.entry14 switch.entry14: ; preds = %switch.exit12 - %13 = load i32, i32* %switch13, align 4 - switch i32 %13, label %switch.default [ + %9 = load i32, i32* %switch13, align 4 + switch i32 %9, label %switch.default [ i32 0, label %switch.case15 i32 1, label %switch.case15 i32 2, label %switch.case15 @@ -210,13 +204,12 @@ switch.default: ; preds = %switch.entry14 br label %switch.exit16 switch.exit16: ; preds = %switch.default, %switch.case15 - %14 = load i32, i32* %h, align 4 - store i32 %14, i32* %switch17, align 4 + store i32 %0, i32* %switch17, align 4 br label %switch.entry18 switch.entry18: ; preds = %switch.exit16 - %15 = load i32, i32* %switch17, align 4 - switch i32 %15, label %switch.exit23 [ + %10 = load i32, i32* %switch17, align 4 + switch i32 %10, label %switch.exit23 [ i32 0, label %switch.case19 i32 1, label %switch.case20 i32 2, label %switch.case22 @@ -224,16 +217,16 @@ switch.entry18: ; preds = %switch.exit16 switch.case19: ; preds = %switch.entry18 store i32 1, i32* %a, align 4 - %16 = call i32 @"std::io.println"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0)) #1 + %11 = call i32 @"std::io.println"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0)) #1 br label %switch.case20 switch.case20: ; preds = %switch.entry18, %switch.case19 store i32 2, i32* %a21, align 4 - %17 = call i32 @"std::io.println"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0)) #1 + %12 = call i32 @"std::io.println"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0)) #1 br label %switch.case22 switch.case22: ; preds = %switch.entry18, %switch.case20 - %18 = call i32 @"std::io.println"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i32 0, i32 0)) #1 + %13 = call i32 @"std::io.println"(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i32 0, i32 0)) #1 br label %switch.exit23 switch.exit23: ; preds = %switch.case22, %switch.entry18 diff --git a/test/test_suite/from_docs/examples_functionpointer.c3t b/test/test_suite/from_docs/examples_functionpointer.c3t index 44272343a..25aa75f45 100644 --- a/test/test_suite/from_docs/examples_functionpointer.c3t +++ b/test/test_suite/from_docs/examples_functionpointer.c3t @@ -20,10 +20,6 @@ fn void main() define i32 @demo.my_callback(i8* %0, i32 %1) #0 { entry: - %text = alloca i8*, align 8 - %value = alloca i32, align 4 - store i8* %0, i8** %text, align 8 - store i32 %1, i32* %value, align 4 ret i32 0 } diff --git a/test/test_suite/from_docs/examples_if_catch.c3t b/test/test_suite/from_docs/examples_if_catch.c3t index 2c04d4e30..e7d941dd3 100644 --- a/test/test_suite/from_docs/examples_if_catch.c3t +++ b/test/test_suite/from_docs/examples_if_catch.c3t @@ -47,14 +47,9 @@ fn void main() define i64 @demo.divide(double* %0, i32 %1, i32 %2) #0 { entry: - %a = alloca i32, align 4 - %b = alloca i32, align 4 %reterr = alloca i64, align 8 %reterr1 = alloca i64, align 8 - store i32 %1, i32* %a, align 4 - store i32 %2, i32* %b, align 4 - %3 = load i32, i32* %b, align 4 - %eq = icmp eq i32 %3, 0 + %eq = icmp eq i32 %2, 0 br i1 %eq, label %if.then, label %if.exit if.then: ; preds = %entry @@ -66,14 +61,12 @@ postfailed: ; No predecessors! ret i64 0 err_retblock: ; preds = %if.then - %4 = load i64, i64* %reterr, align 8 - ret i64 %4 + %3 = load i64, i64* %reterr, align 8 + ret i64 %3 if.exit: ; preds = %entry - %5 = load i32, i32* %a, align 4 - %sifp = sitofp i32 %5 to double - %6 = load i32, i32* %b, align 4 - %sifp2 = sitofp i32 %6 to double + %sifp = sitofp i32 %1 to double + %sifp2 = sitofp i32 %2 to double %fdiv = fdiv double %sifp, %sifp2 store double %fdiv, double* %0, align 8 ret i64 0 diff --git a/test/test_suite/from_docs/examples_macro_function.c3t b/test/test_suite/from_docs/examples_macro_function.c3t index b5096cb80..1a820de0f 100644 --- a/test/test_suite/from_docs/examples_macro_function.c3t +++ b/test/test_suite/from_docs/examples_macro_function.c3t @@ -25,11 +25,7 @@ fn int test() define i32 @example.square(i32 %0) #0 { entry: - %x = alloca i32, align 4 - store i32 %0, i32* %x, align 4 - %1 = load i32, i32* %x, align 4 - %2 = load i32, i32* %x, align 4 - %mul = mul i32 %1, %2 + %mul = mul i32 %0, %0 ret i32 %mul } diff --git a/test/test_suite/functions/assorted_tests.c3t b/test/test_suite/functions/assorted_tests.c3t index ef3784bfc..386d0daf0 100644 --- a/test/test_suite/functions/assorted_tests.c3t +++ b/test/test_suite/functions/assorted_tests.c3t @@ -50,6 +50,8 @@ fn void denormalize(InternalFPF* ptr) // #expect: test.ll +define i32 @test.foo1() #0 { +entry: %pp = alloca i8*, align 8 %w_cnt = alloca i32, align 4 %0 = load i32, i32* %w_cnt, align 4 @@ -60,59 +62,57 @@ fn void denormalize(InternalFPF* ptr) store i32 %add, i32* %w_cnt, align 4 %3 = load i32, i32* %w_cnt, align 4 ret i32 %3 +} - %x = alloca i32, align 4 - store i32 %0, i32* %x, align 4 - %1 = load i32, i32* %x, align 4 - %2 = load i32, i32* %x, align 4 - %intbool = icmp ne i32 %2, 0 +define void @test.foo2(i32 %0) #0 { +entry: + %intbool = icmp ne i32 %0, 0 br i1 %intbool, label %cond.lhs, label %cond.rhs -cond.lhs: - br label %cond.phi -cond.rhs: - br label %cond.phi -cond.phi: - %val = phi double [ 1.000000e+00, %cond.lhs ], [ 1.250000e+01, %cond.rhs ] - call void @test2(i32 %1, double %val, float 1.000000e+00) - ret void - %s = alloca i8*, align 8 - %x = alloca i32, align 4 +cond.lhs: ; preds = %entry + br label %cond.phi + +cond.rhs: ; preds = %entry + br label %cond.phi + +cond.phi: ; preds = %cond.rhs, %cond.lhs + %val = phi double [ 1.000000e+00, %cond.lhs ], [ 1.250000e+01, %cond.rhs ] + call void @test2(i32 %0, double %val, float 1.000000e+00) + ret void +} + +define i32 @test.trys(i8* %0, i32 %1) #0 { +entry: %asa = alloca i32, align 4 %val = alloca double, align 8 %lls = alloca i32, align 4 - store i32 %1, i32* %x, align 4 - %2 = load i32, i32* %x, align 4 - %intbool = icmp ne i32 %2, 0 + %intbool = icmp ne i32 %1, 0 br i1 %intbool, label %if.then, label %if.exit -if.then: - %3 = load i32, i32* %lls, align 4 - %4 = load i32, i32* %asa, align 4 - %add = add i32 %3, %4 +if.then: ; preds = %entry + %2 = load i32, i32* %lls, align 4 + %3 = load i32, i32* %asa, align 4 + %add = add i32 %2, %3 store i32 %add, i32* %asa, align 4 br label %if.exit -if.exit: - %5 = load i32, i32* %asa, align 4 - %6 = load double, double* %val, align 8 - %fpui = fptoui double %6 to i32 - %add1 = add i32 %5, %fpui +if.exit: ; preds = %if.then, %entry + %4 = load i32, i32* %asa, align 4 + %5 = load double, double* %val, align 8 + %fpui = fptoui double %5 to i32 + %add1 = add i32 %4, %fpui ret i32 %add1 +} - -void @test.setInternalFPFZero(%InternalFPF* %0) - %dest = alloca %InternalFPF*, align 8 - store %InternalFPF* %0, %InternalFPF** %dest, align 8 - %1 = load %InternalFPF*, %InternalFPF** %dest, align 8 - %2 = getelementptr inbounds %InternalFPF, %InternalFPF* %1, i32 0, i32 0 - store i8 0, i8* %2, align 8 - ret void - -void @test.denormalize(%InternalFPF* %0) +define void @test.setInternalFPFZero(%InternalFPF* %0) #1 { entry: - %ptr = alloca %InternalFPF*, align 8 - store %InternalFPF* %0, %InternalFPF** %ptr, align 8 - %1 = load %InternalFPF*, %InternalFPF** %ptr, align 8 - call void @test.setInternalFPFZero(%InternalFPF* %1) + %1 = getelementptr inbounds %InternalFPF, %InternalFPF* %0, i32 0, i32 0 + store i8 0, i8* %1, align 8 ret void +} + +define void @test.denormalize(%InternalFPF* %0) #0 { +entry: + call void @test.setInternalFPFZero(%InternalFPF* %0) + ret void +} diff --git a/test/test_suite/functions/test_regression.c3t b/test/test_suite/functions/test_regression.c3t index ac5f873b1..adb91f339 100644 --- a/test/test_suite/functions/test_regression.c3t +++ b/test/test_suite/functions/test_regression.c3t @@ -248,26 +248,20 @@ fn Type getValue(Blob blob) define void @test.Foo2__printme(%Foo2* %0) #0 { entry: - %foo = alloca %Foo2*, align 8 - store %Foo2* %0, %Foo2** %foo, align 8 - %1 = load %Foo2*, %Foo2** %foo, align 8 - %2 = getelementptr inbounds %Foo2, %Foo2* %1, i32 0, i32 0 - %3 = load i32, i32* %2, align 8 - %4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.21, i32 0, i32 0), i32 %3) + %1 = getelementptr inbounds %Foo2, %Foo2* %0, i32 0, i32 0 + %2 = load i32, i32* %1, align 8 + %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.21, i32 0, i32 0), i32 %2) ret void } ; Function Attrs: nounwind define i32 @test.Foo2__mutate(%Foo2* %0) #0 { entry: - %foo = alloca %Foo2*, align 8 - store %Foo2* %0, %Foo2** %foo, align 8 %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.22, i32 0, i32 0)) - %2 = load %Foo2*, %Foo2** %foo, align 8 - %3 = getelementptr inbounds %Foo2, %Foo2* %2, i32 0, i32 0 - %4 = load i32, i32* %3, align 8 - %add = add i32 %4, 1 - store i32 %add, i32* %3, align 8 + %2 = getelementptr inbounds %Foo2, %Foo2* %0, i32 0, i32 0 + %3 = load i32, i32* %2, align 8 + %add = add i32 %3, 1 + store i32 %add, i32* %2, align 8 ret i32 %add } @@ -296,12 +290,10 @@ entry: ; Function Attrs: nounwind define i32 @test.helo(double %0, %Bobo* byval(%Bobo) align 8 %1) #0 { entry: - %d = alloca double, align 8 %b = alloca %Bobo, align 4 %de = alloca [3 x i32], align 4 %c = alloca %Bobo, align 4 %indirectarg = alloca %Bobo, align 8 - store double %0, double* %d, align 8 %2 = bitcast %Bobo* %b to i8* %3 = bitcast %Bobo* %1 to i8* call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %2, i8* align 8 %3, i32 20, i1 false) @@ -321,24 +313,20 @@ entry: define i32 @test.test1(i32 %0, i32 %1) #0 { entry: %a = alloca i32, align 4 - %b = alloca i32, align 4 store i32 %0, i32* %a, align 4 - store i32 %1, i32* %b, align 4 %2 = load i32, i32* %a, align 4 - %3 = load i32, i32* %b, align 4 - %ashr = ashr i32 %2, %3 - %4 = freeze i32 %ashr - store i32 %4, i32* %a, align 4 - %5 = load i32, i32* %b, align 4 - %gt = icmp sgt i32 %5, 128 + %ashr = ashr i32 %2, %1 + %3 = freeze i32 %ashr + store i32 %3, i32* %a, align 4 + %gt = icmp sgt i32 %1, 128 br i1 %gt, label %if.then, label %if.exit if.then: ; preds = %entry ret i32 -1 if.exit: ; preds = %entry - %6 = load i32, i32* %a, align 4 - ret i32 %6 + %4 = load i32, i32* %a, align 4 + ret i32 %4 } ; Function Attrs: nounwind @@ -665,11 +653,7 @@ entry: define double @foo.double.check(double %0) entry: - %i = alloca double, align 8 - store double %0, double* %i, align 8 - %1 = load double, double* %i, align 8 - %2 = load double, double* %i, align 8 - %fmul = fmul double %1, %2 + %fmul = fmul double %0, %0 ret double %fmul @@ -678,21 +662,18 @@ entry: %Blob = type { i32 } @test2.int.argh = global i32 234, align 4 -define i32 @test2.int.getMult(i32 %0) +define i32 @test2.int.getMult(i32 %0) #0 { entry: - %a = alloca i32, align 4 - store i32 %0, i32* %a, align 4 - %1 = load i32, i32* %a, align 4 - %2 = load i32, i32* %a, align 4 - %mul = mul i32 %1, %2 + %mul = mul i32 %0, %0 ret i32 %mul +} -define i32 @test2.int.hello() +define i32 @test2.int.hello() #0 { entry: ret i32 1 } -define i32 @test2.int.getValue(i32 %0) +define i32 @test2.int.getValue(i32 %0) #0 { entry: %blob = alloca %Blob, align 4 %1 = getelementptr inbounds %Blob, %Blob* %blob, i32 0, i32 0 @@ -700,7 +681,7 @@ entry: %2 = getelementptr inbounds %Blob, %Blob* %blob, i32 0, i32 0 %3 = load i32, i32* %2, align 4 ret i32 %3 - +} // #expect: test2.double.ll @@ -709,11 +690,7 @@ entry: define double @test2.double.getMult(double %0) entry: - %a = alloca double, align 8 - store double %0, double* %a, align 8 - %1 = load double, double* %a, align 8 - %2 = load double, double* %a, align 8 - %fmul = fmul double %1, %2 + %fmul = fmul double %0, %0 ret double %fmul define i32 @test2.double.hello() diff --git a/test/test_suite/functions/test_regression_mingw.c3t b/test/test_suite/functions/test_regression_mingw.c3t index c8e45800e..40c3ed875 100644 --- a/test/test_suite/functions/test_regression_mingw.c3t +++ b/test/test_suite/functions/test_regression_mingw.c3t @@ -313,26 +313,20 @@ declare void @"std::array::list.int.List__free"(%List*) ; Function Attrs: nounwind define void @test.Foo2__printme(%Foo2* %0) #0 { entry: - %foo = alloca %Foo2*, align 8 - store %Foo2* %0, %Foo2** %foo, align 8 - %1 = load %Foo2*, %Foo2** %foo, align 8 - %2 = getelementptr inbounds %Foo2, %Foo2* %1, i32 0, i32 0 - %3 = load i32, i32* %2, align 8 - %4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.21, i32 0, i32 0), i32 %3) + %1 = getelementptr inbounds %Foo2, %Foo2* %0, i32 0, i32 0 + %2 = load i32, i32* %1, align 8 + %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.21, i32 0, i32 0), i32 %2) ret void } ; Function Attrs: nounwind define i32 @test.Foo2__mutate(%Foo2* %0) #0 { entry: - %foo = alloca %Foo2*, align 8 - store %Foo2* %0, %Foo2** %foo, align 8 %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.22, i32 0, i32 0)) - %2 = load %Foo2*, %Foo2** %foo, align 8 - %3 = getelementptr inbounds %Foo2, %Foo2* %2, i32 0, i32 0 - %4 = load i32, i32* %3, align 8 - %add = add i32 %4, 1 - store i32 %add, i32* %3, align 8 + %2 = getelementptr inbounds %Foo2, %Foo2* %0, i32 0, i32 0 + %3 = load i32, i32* %2, align 8 + %add = add i32 %3, 1 + store i32 %add, i32* %2, align 8 ret i32 %add } @@ -361,12 +355,10 @@ entry: ; Function Attrs: nounwind define i32 @test.helo(double %0, %Bobo* align 4 %1) #0 { entry: - %d = alloca double, align 8 %b = alloca %Bobo, align 4 %de = alloca [3 x i32], align 4 %c = alloca %Bobo, align 4 %indirectarg = alloca %Bobo, align 4 - store double %0, double* %d, align 8 %2 = bitcast %Bobo* %b to i8* %3 = bitcast %Bobo* %1 to i8* call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %2, i8* align 4 %3, i32 20, i1 false) @@ -386,24 +378,20 @@ entry: define i32 @test.test1(i32 %0, i32 %1) #0 { entry: %a = alloca i32, align 4 - %b = alloca i32, align 4 store i32 %0, i32* %a, align 4 - store i32 %1, i32* %b, align 4 %2 = load i32, i32* %a, align 4 - %3 = load i32, i32* %b, align 4 - %ashr = ashr i32 %2, %3 - %4 = freeze i32 %ashr - store i32 %4, i32* %a, align 4 - %5 = load i32, i32* %b, align 4 - %gt = icmp sgt i32 %5, 128 + %ashr = ashr i32 %2, %1 + %3 = freeze i32 %ashr + store i32 %3, i32* %a, align 4 + %gt = icmp sgt i32 %1, 128 br i1 %gt, label %if.then, label %if.exit if.then: ; preds = %entry ret i32 -1 if.exit: ; preds = %entry - %6 = load i32, i32* %a, align 4 - ret i32 %6 + %4 = load i32, i32* %a, align 4 + ret i32 %4 } ; Function Attrs: nounwind @@ -715,11 +703,7 @@ entry: define double @foo.double.check(double %0) entry: - %i = alloca double, align 8 - store double %0, double* %i, align 8 - %1 = load double, double* %i, align 8 - %2 = load double, double* %i, align 8 - %fmul = fmul double %1, %2 + %fmul = fmul double %0, %0 ret double %fmul @@ -730,11 +714,7 @@ entry: define i32 @test2.int.getMult(i32 %0) entry: - %a = alloca i32, align 4 - store i32 %0, i32* %a, align 4 - %1 = load i32, i32* %a, align 4 - %2 = load i32, i32* %a, align 4 - %mul = mul i32 %1, %2 + %mul = mul i32 %0, %0 ret i32 %mul define i32 @test2.int.hello() @@ -759,11 +739,7 @@ entry: define double @test2.double.getMult(double %0) entry: - %a = alloca double, align 8 - store double %0, double* %a, align 8 - %1 = load double, double* %a, align 8 - %2 = load double, double* %a, align 8 - %fmul = fmul double %1, %2 + %fmul = fmul double %0, %0 ret double %fmul diff --git a/test/test_suite/generic/generic_idents.c3t b/test/test_suite/generic/generic_idents.c3t index 3ca15b100..9da9497a6 100644 --- a/test/test_suite/generic/generic_idents.c3t +++ b/test/test_suite/generic/generic_idents.c3t @@ -28,64 +28,43 @@ fn double getIt2(double i) // #expect: gen.int.ll -define i32 @gen.int.mult(i32 %0) - %x = alloca i32, align 4 - store i32 %0, i32* %x, align 4 - %1 = load i32, i32* %x, align 4 - %2 = load i32, i32* %x, align 4 - %mul = mul i32 %1, %2 +define i32 @gen.int.mult(i32 %0) #0 { +entry: + %mul = mul i32 %0, %0 ret i32 %mul +} -; Function Attrs: nounwind -define i32 @gen.int.addMult(i32 %0, i32 %1, i32 %2) - %x = alloca i32, align 4 - %a = alloca i32, align 4 - %b = alloca i32, align 4 - store i32 %0, i32* %x, align 4 - store i32 %1, i32* %a, align 4 - store i32 %2, i32* %b, align 4 - %3 = load i32, i32* %x, align 4 - %4 = load i32, i32* %a, align 4 - %mul = mul i32 %3, %4 - %5 = load i32, i32* %b, align 4 - %add = add i32 %mul, %5 +define i32 @gen.int.addMult(i32 %0, i32 %1, i32 %2) #0 { +entry: + %mul = mul i32 %0, %1 + %add = add i32 %mul, %2 ret i32 %add +} + // #expect: test.ll declare i32 @gen.int.mult(i32) + declare double @gen.double.addMult(double, double, double) -define i32 @test.getIt(i32 %0) - - %i = alloca i32, align 4 - store i32 %0, i32* %i, align 4 - %1 = load i32, i32* %i, align 4 - %2 = call i32 @gen.int.mult(i32 %1) - %add = add i32 %2, 1 +define i32 @test.getIt(i32 %0) #0 { +entry: + %1 = call i32 @gen.int.mult(i32 %0) + %add = add i32 %1, 1 ret i32 %add - -define double @test.getIt2(double %0) - - %i = alloca double, align 8 - store double %0, double* %i, align 8 - %1 = load double, double* %i, align 8 - %2 = call double @gen.double.addMult(double %1, double 2.000000e+00, double 3.000000e+00) - ret double %2 } +define double @test.getIt2(double %0) #0 { +entry: + %1 = call double @gen.double.addMult(double %0, double 2.000000e+00, double 3.000000e+00) + ret double %1 +} + + // #expect: gen.double.ll define double @gen.double.addMult(double %0, double %1, double %2) - %x = alloca double, align 8 - %a = alloca double, align 8 - %b = alloca double, align 8 - store double %0, double* %x, align 8 - store double %1, double* %a, align 8 - store double %2, double* %b, align 8 - %3 = load double, double* %x, align 8 - %4 = load double, double* %a, align 8 - %fmul = fmul double %3, %4 - %5 = load double, double* %b, align 8 - %fadd = fadd double %fmul, %5 + %fmul = fmul double %0, %1 + %fadd = fadd double %fmul, %2 ret double %fadd diff --git a/test/test_suite/initializer_lists/fasta.c3t b/test/test_suite/initializer_lists/fasta.c3t index c785af137..0e4111f58 100644 --- a/test/test_suite/initializer_lists/fasta.c3t +++ b/test/test_suite/initializer_lists/fasta.c3t @@ -133,17 +133,14 @@ fn void main(int argc, char **argv) ; Function Attrs: nounwind define float @fasta.fasta_rand(float %0) #0 { entry: - %max = alloca float, align 4 - store float %0, float* %max, align 4 %1 = load i32, i32* @fasta.seed, align 4 %mul = mul i32 %1, 3877 %add = add i32 %mul, 29573 %umod = urem i32 %add, 139968 store i32 %umod, i32* @fasta.seed, align 4 - %2 = load float, float* %max, align 4 - %3 = load i32, i32* @fasta.seed, align 4 - %uifp = uitofp i32 %3 to float - %fmul = fmul float %2, %uifp + %2 = load i32, i32* @fasta.seed, align 4 + %uifp = uitofp i32 %2 to float + %fmul = fmul float %0, %uifp %fdiv = fdiv float %fmul, 1.399680e+05 ret float %fdiv } @@ -161,7 +158,6 @@ declare void @putchar(i32) #0 define void @fasta.repeat_fasta(i8* %0, i64 %1, i32 %2) #0 { entry: %seq = alloca %"char[]", align 8 - %n = alloca i32, align 4 %len = alloca i64, align 8 %i = alloca i32, align 4 %pair = bitcast %"char[]"* %seq to { i8*, i64 }* @@ -169,7 +165,6 @@ entry: store i8* %0, i8** %3, align 8 %4 = getelementptr inbounds { i8*, i64 }, { i8*, i64 }* %pair, i32 0, i32 1 store i64 %1, i64* %4, align 8 - store i32 %2, i32* %n, align 4 %5 = getelementptr inbounds %"char[]", %"char[]"* %seq, i32 0, i32 1 %6 = load i64, i64* %5, align 8 store i64 %6, i64* %len, align 8 @@ -178,23 +173,22 @@ entry: loop.cond: ; preds = %if.exit, %entry %7 = load i32, i32* %i, align 4 - %8 = load i32, i32* %n, align 4 - %lt = icmp slt i32 %7, %8 + %lt = icmp slt i32 %7, %2 br i1 %lt, label %loop.body, label %loop.exit loop.body: ; preds = %loop.cond - %9 = getelementptr inbounds %"char[]", %"char[]"* %seq, i32 0, i32 0 - %10 = load i8*, i8** %9, align 8 - %11 = load i32, i32* %i, align 4 - %sisiext = sext i32 %11 to i64 - %12 = load i64, i64* %len, align 8 - %smod = srem i64 %sisiext, %12 - %ptroffset = getelementptr inbounds i8, i8* %10, i64 %smod - %13 = load i8, i8* %ptroffset, align 1 - %uisiext = zext i8 %13 to i32 + %8 = getelementptr inbounds %"char[]", %"char[]"* %seq, i32 0, i32 0 + %9 = load i8*, i8** %8, align 8 + %10 = load i32, i32* %i, align 4 + %sisiext = sext i32 %10 to i64 + %11 = load i64, i64* %len, align 8 + %smod = srem i64 %sisiext, %11 + %ptroffset = getelementptr inbounds i8, i8* %9, i64 %smod + %12 = load i8, i8* %ptroffset, align 1 + %uisiext = zext i8 %12 to i32 call void @putchar(i32 %uisiext) - %14 = load i32, i32* %i, align 4 - %smod1 = srem i32 %14, 60 + %13 = load i32, i32* %i, align 4 + %smod1 = srem i32 %13, 60 %eq = icmp eq i32 %smod1, 59 br i1 %eq, label %if.then, label %if.exit @@ -203,14 +197,14 @@ if.then: ; preds = %loop.body br label %if.exit if.exit: ; preds = %if.then, %loop.body - %15 = load i32, i32* %i, align 4 - %add = add i32 %15, 1 + %14 = load i32, i32* %i, align 4 + %add = add i32 %14, 1 store i32 %add, i32* %i, align 4 br label %loop.cond loop.exit: ; preds = %loop.cond - %16 = load i32, i32* %i, align 4 - %smod2 = srem i32 %16, 60 + %15 = load i32, i32* %i, align 4 + %smod2 = srem i32 %15, 60 %neq = icmp ne i32 %smod2, 0 br i1 %neq, label %if.then3, label %if.exit4 @@ -227,7 +221,6 @@ define void @fasta.random_fasta(i8* %0, i64 %1, i8* %2, i64 %3, i32 %4) #0 { entry: %symb = alloca %"char[]", align 8 %probability = alloca %"double[]", align 8 - %n = alloca i32, align 4 %len = alloca i32, align 4 %i = alloca i32, align 4 %v = alloca double, align 8 @@ -242,7 +235,6 @@ entry: store i8* %2, i8** %7, align 8 %8 = getelementptr inbounds { i8*, i64 }, { i8*, i64 }* %pair1, i32 0, i32 1 store i64 %3, i64* %8, align 8 - store i32 %4, i32* %n, align 4 %9 = getelementptr inbounds %"char[]", %"char[]"* %symb, i32 0, i32 1 %10 = load i64, i64* %9, align 8 %11 = getelementptr inbounds %"double[]", %"double[]"* %probability, i32 0, i32 1 @@ -258,58 +250,57 @@ entry: loop.cond: ; preds = %if.exit10, %entry %15 = load i32, i32* %i, align 4 - %16 = load i32, i32* %n, align 4 - %lt = icmp slt i32 %15, %16 + %lt = icmp slt i32 %15, %4 br i1 %lt, label %loop.body, label %loop.exit12 loop.body: ; preds = %loop.cond - %17 = call float @fasta.fasta_rand(float 1.000000e+00) - %fpfpext = fpext float %17 to double + %16 = call float @fasta.fasta_rand(float 1.000000e+00) + %fpfpext = fpext float %16 to double store double %fpfpext, double* %v, align 8 store i32 0, i32* %j, align 4 br label %loop.cond2 loop.cond2: ; preds = %if.exit, %loop.body - %18 = load i32, i32* %j, align 4 - %19 = load i32, i32* %len, align 4 - %sub = sub i32 %19, 1 - %lt3 = icmp slt i32 %18, %sub + %17 = load i32, i32* %j, align 4 + %18 = load i32, i32* %len, align 4 + %sub = sub i32 %18, 1 + %lt3 = icmp slt i32 %17, %sub br i1 %lt3, label %loop.body4, label %loop.exit loop.body4: ; preds = %loop.cond2 - %20 = load double, double* %v, align 8 - %21 = getelementptr inbounds %"double[]", %"double[]"* %probability, i32 0, i32 0 - %22 = load double*, double** %21, align 8 - %23 = load i32, i32* %j, align 4 - %sisiext = sext i32 %23 to i64 - %ptroffset = getelementptr inbounds double, double* %22, i64 %sisiext - %24 = load double, double* %ptroffset, align 8 - %fsub = fsub double %20, %24 + %19 = load double, double* %v, align 8 + %20 = getelementptr inbounds %"double[]", %"double[]"* %probability, i32 0, i32 0 + %21 = load double*, double** %20, align 8 + %22 = load i32, i32* %j, align 4 + %sisiext = sext i32 %22 to i64 + %ptroffset = getelementptr inbounds double, double* %21, i64 %sisiext + %23 = load double, double* %ptroffset, align 8 + %fsub = fsub double %19, %23 store double %fsub, double* %v, align 8 - %25 = load double, double* %v, align 8 - %lt5 = fcmp olt double %25, 0.000000e+00 + %24 = load double, double* %v, align 8 + %lt5 = fcmp olt double %24, 0.000000e+00 br i1 %lt5, label %if.then, label %if.exit if.then: ; preds = %loop.body4 br label %loop.exit if.exit: ; preds = %loop.body4 - %26 = load i32, i32* %j, align 4 - %add = add i32 %26, 1 + %25 = load i32, i32* %j, align 4 + %add = add i32 %25, 1 store i32 %add, i32* %j, align 4 br label %loop.cond2 loop.exit: ; preds = %if.then, %loop.cond2 - %27 = getelementptr inbounds %"char[]", %"char[]"* %symb, i32 0, i32 0 - %28 = load i8*, i8** %27, align 8 - %29 = load i32, i32* %j, align 4 - %sisiext6 = sext i32 %29 to i64 - %ptroffset7 = getelementptr inbounds i8, i8* %28, i64 %sisiext6 - %30 = load i8, i8* %ptroffset7, align 1 - %uisiext = zext i8 %30 to i32 + %26 = getelementptr inbounds %"char[]", %"char[]"* %symb, i32 0, i32 0 + %27 = load i8*, i8** %26, align 8 + %28 = load i32, i32* %j, align 4 + %sisiext6 = sext i32 %28 to i64 + %ptroffset7 = getelementptr inbounds i8, i8* %27, i64 %sisiext6 + %29 = load i8, i8* %ptroffset7, align 1 + %uisiext = zext i8 %29 to i32 call void @putchar(i32 %uisiext) - %31 = load i32, i32* %i, align 4 - %smod = srem i32 %31, 60 + %30 = load i32, i32* %i, align 4 + %smod = srem i32 %30, 60 %eq8 = icmp eq i32 %smod, 59 br i1 %eq8, label %if.then9, label %if.exit10 @@ -318,14 +309,14 @@ if.then9: ; preds = %loop.exit br label %if.exit10 if.exit10: ; preds = %if.then9, %loop.exit - %32 = load i32, i32* %i, align 4 - %add11 = add i32 %32, 1 + %31 = load i32, i32* %i, align 4 + %add11 = add i32 %31, 1 store i32 %add11, i32* %i, align 4 br label %loop.cond loop.exit12: ; preds = %loop.cond - %33 = load i32, i32* %i, align 4 - %smod13 = srem i32 %33, 60 + %32 = load i32, i32* %i, align 4 + %smod13 = srem i32 %32, 60 %neq = icmp ne i32 %smod13, 0 br i1 %neq, label %if.then14, label %if.exit15 @@ -340,58 +331,46 @@ if.exit15: ; preds = %if.then14, %loop.ex ; Function Attrs: nounwind define void @fasta.main(i32 %0, i8** %1) #0 { entry: - %argc = alloca i32, align 4 - %argv = alloca i8**, align 8 %n = alloca i32, align 4 - store i32 %0, i32* %argc, align 4 - store i8** %1, i8*** %argv, align 8 store i32 1000, i32* %n, align 4 - %2 = load i32, i32* %argc, align 4 - %gt = icmp sgt i32 %2, 1 + %gt = icmp sgt i32 %0, 1 br i1 %gt, label %if.then, label %if.exit if.then: ; preds = %entry - %3 = load i8**, i8*** %argv, align 8 - %ptroffset = getelementptr inbounds i8*, i8** %3, i64 1 - %4 = load i8*, i8** %ptroffset, align 8 - %5 = call i32 @atoi(i8* %4) - store i32 %5, i32* %n, align 4 + %ptroffset = getelementptr inbounds i8*, i8** %1, i64 1 + %2 = load i8*, i8** %ptroffset, align 8 + %3 = call i32 @atoi(i8* %2) + store i32 %3, i32* %n, align 4 br label %if.exit if.exit: ; preds = %if.then, %entry - %6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i32 0, i32 0)) + %4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i32 0, i32 0)) %lo = load i8*, i8** getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* bitcast (%"char[]"* @fasta.alu to { i8*, i64 }*), i32 0, i32 0), align 8 %hi = load i64, i64* getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* bitcast (%"char[]"* @fasta.alu to { i8*, i64 }*), i32 0, i32 1), align 8 - %7 = load i32, i32* %n, align 4 - %mul = mul i32 %7, 2 + %5 = load i32, i32* %n, align 4 + %mul = mul i32 %5, 2 call void @fasta.repeat_fasta(i8* %lo, i64 %hi, i32 %mul) - %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.15, i32 0, i32 0)) + %6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.15, i32 0, i32 0)) %lo1 = load i8*, i8** getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* bitcast (%"char[]"* @fasta.iub to { i8*, i64 }*), i32 0, i32 0), align 8 %hi2 = load i64, i64* getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* bitcast (%"char[]"* @fasta.iub to { i8*, i64 }*), i32 0, i32 1), align 8 %lo3 = load i8*, i8** getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* bitcast (%"double[]"* @fasta.iub_p to { i8*, i64 }*), i32 0, i32 0), align 8 %hi4 = load i64, i64* getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* bitcast (%"double[]"* @fasta.iub_p to { i8*, i64 }*), i32 0, i32 1), align 8 - %9 = load i32, i32* %n, align 4 - %mul5 = mul i32 %9, 3 + %7 = load i32, i32* %n, align 4 + %mul5 = mul i32 %7, 3 call void @fasta.random_fasta(i8* %lo1, i64 %hi2, i8* %lo3, i64 %hi4, i32 %mul5) - %10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.16, i32 0, i32 0)) + %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.16, i32 0, i32 0)) %lo6 = load i8*, i8** getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* bitcast (%"char[]"* @fasta.homosapiens to { i8*, i64 }*), i32 0, i32 0), align 8 %hi7 = load i64, i64* getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* bitcast (%"char[]"* @fasta.homosapiens to { i8*, i64 }*), i32 0, i32 1), align 8 %lo8 = load i8*, i8** getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* bitcast (%"double[]"* @fasta.homosapiens_p to { i8*, i64 }*), i32 0, i32 0), align 8 %hi9 = load i64, i64* getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* bitcast (%"double[]"* @fasta.homosapiens_p to { i8*, i64 }*), i32 0, i32 1), align 8 - %11 = load i32, i32* %n, align 4 - %mul10 = mul i32 %11, 5 + %9 = load i32, i32* %n, align 4 + %mul10 = mul i32 %9, 5 call void @fasta.random_fasta(i8* %lo6, i64 %hi7, i8* %lo8, i64 %hi9, i32 %mul10) ret void } define i32 @main(i32 %0, i8** %1) #0 { entry: - %"_$argv" = alloca i32, align 4 - %"_$argc" = alloca i8**, align 8 - store i32 %0, i32* %"_$argv", align 4 - store i8** %1, i8*** %"_$argc", align 8 - %2 = load i32, i32* %"_$argv", align 4 - %3 = load i8**, i8*** %"_$argc", align 8 - call void @fasta.main(i32 %2, i8** %3) + call void @fasta.main(i32 %0, i8** %1) ret i32 0 } \ No newline at end of file diff --git a/test/test_suite/initializer_lists/ranges_to_dynamic.c3t b/test/test_suite/initializer_lists/ranges_to_dynamic.c3t index 01e2227f8..c2087a1b3 100644 --- a/test/test_suite/initializer_lists/ranges_to_dynamic.c3t +++ b/test/test_suite/initializer_lists/ranges_to_dynamic.c3t @@ -21,11 +21,9 @@ fn void main() define void @test.test(i32 %0) #0 { entry: - %x = alloca i32, align 4 %y = alloca [10 x i32], align 16 %"__idx$" = alloca i64, align 8 %v = alloca i32, align 4 - store i32 %0, i32* %x, align 4 %1 = bitcast [10 x i32]* %y to i8* call void @llvm.memset.p0i8.i64(i8* align 16 %1, i8 0, i64 40, i1 false) %2 = getelementptr inbounds [10 x i32], [10 x i32]* %y, i64 0, i64 0 @@ -37,29 +35,28 @@ entry: %5 = getelementptr inbounds [10 x i32], [10 x i32]* %y, i64 0, i64 3 store i32 4, i32* %5, align 4 %6 = getelementptr inbounds [10 x i32], [10 x i32]* %y, i64 0, i64 6 - %7 = load i32, i32* %x, align 4 - store i32 %7, i32* %6, align 4 - %8 = getelementptr inbounds [10 x i32], [10 x i32]* %y, i64 0, i64 7 - store i32 %7, i32* %8, align 4 - %9 = getelementptr inbounds [10 x i32], [10 x i32]* %y, i64 0, i64 8 - store i32 %7, i32* %9, align 4 + store i32 %0, i32* %6, align 4 + %7 = getelementptr inbounds [10 x i32], [10 x i32]* %y, i64 0, i64 7 + store i32 %0, i32* %7, align 4 + %8 = getelementptr inbounds [10 x i32], [10 x i32]* %y, i64 0, i64 8 + store i32 %0, i32* %8, align 4 store i64 0, i64* %"__idx$", align 8 br label %loop.cond loop.cond: ; preds = %loop.body, %entry - %10 = load i64, i64* %"__idx$", align 8 - %gt = icmp ugt i64 10, %10 + %9 = load i64, i64* %"__idx$", align 8 + %gt = icmp ugt i64 10, %9 br i1 %gt, label %loop.body, label %loop.exit loop.body: ; preds = %loop.cond - %11 = load i64, i64* %"__idx$", align 8 - %12 = getelementptr inbounds [10 x i32], [10 x i32]* %y, i64 0, i64 %11 - %13 = load i32, i32* %12, align 4 - store i32 %13, i32* %v, align 4 - %14 = load i32, i32* %v, align 4 - call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %14) - %15 = load i64, i64* %"__idx$", align 8 - %add = add i64 %15, 1 + %10 = load i64, i64* %"__idx$", align 8 + %11 = getelementptr inbounds [10 x i32], [10 x i32]* %y, i64 0, i64 %10 + %12 = load i32, i32* %11, align 4 + store i32 %12, i32* %v, align 4 + %13 = load i32, i32* %v, align 4 + call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %13) + %14 = load i64, i64* %"__idx$", align 8 + %add = add i64 %14, 1 store i64 %add, i64* %"__idx$", align 8 br label %loop.cond diff --git a/test/test_suite/macros/macro_with_body.c3t b/test/test_suite/macros/macro_with_body.c3t index cc39729ff..5cf223b6a 100644 --- a/test/test_suite/macros/macro_with_body.c3t +++ b/test/test_suite/macros/macro_with_body.c3t @@ -48,14 +48,11 @@ fn void main() define i32 @withbody.Foo__mutate(%Foo* %0) #0 { entry: - %foo = alloca %Foo*, align 8 - store %Foo* %0, %Foo** %foo, align 8 %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0)) - %2 = load %Foo*, %Foo** %foo, align 8 - %3 = getelementptr inbounds %Foo, %Foo* %2, i32 0, i32 0 - %4 = load i32, i32* %3, align 8 - %add = add i32 %4, 1 - store i32 %add, i32* %3, align 8 + %2 = getelementptr inbounds %Foo, %Foo* %0, i32 0, i32 0 + %3 = load i32, i32* %2, align 8 + %add = add i32 %3, 1 + store i32 %add, i32* %2, align 8 %mul = mul i32 10, %add ret i32 %mul } diff --git a/test/test_suite/macros/userland_bitcast.c3t b/test/test_suite/macros/userland_bitcast.c3t index f26d9ee80..5bb217e88 100644 --- a/test/test_suite/macros/userland_bitcast.c3t +++ b/test/test_suite/macros/userland_bitcast.c3t @@ -84,14 +84,12 @@ fn void main() ; Function Attrs: nounwind define i64 @userland_bitcast.testFoo(i16 signext %0) #0 { entry: - %x = alloca i16, align 2 %z = alloca %Foo, align 2 %expr = alloca %Foo, align 2 - %x1 = alloca i64, align 8 + %x = alloca i64, align 8 %b = alloca i16*, align 8 %to = alloca i16*, align 8 %i = alloca i64, align 8 - store i16 %0, i16* %x, align 2 %1 = getelementptr inbounds %Foo, %Foo* %z, i32 0, i32 0 store i16 0, i16* %1, align 2 %2 = getelementptr inbounds %Foo, %Foo* %z, i32 0, i32 1 @@ -103,89 +101,83 @@ entry: %5 = getelementptr inbounds %Foo, %Foo* %z, i32 0, i32 4 store i16 0, i16* %5, align 2 %6 = getelementptr inbounds %Foo, %Foo* %z, i32 0, i32 0 - %7 = load i16, i16* %x, align 2 - store i16 %7, i16* %6, align 2 - %8 = load %Foo, %Foo* %z, align 2 - store %Foo %8, %Foo* %expr, align 2 + store i16 %0, i16* %6, align 2 + %7 = load %Foo, %Foo* %z, align 2 + store %Foo %7, %Foo* %expr, align 2 %ptrptr = bitcast %Foo* %expr to i16* store i16* %ptrptr, i16** %b, align 8 - %ptrptr2 = bitcast i64* %x1 to i16* - store i16* %ptrptr2, i16** %to, align 8 + %ptrptr1 = bitcast i64* %x to i16* + store i16* %ptrptr1, i16** %to, align 8 store i64 0, i64* %i, align 8 br label %loop.cond loop.cond: ; preds = %loop.body, %entry - %9 = load i64, i64* %i, align 8 - %lt = icmp ult i64 %9, 8 + %8 = load i64, i64* %i, align 8 + %lt = icmp ult i64 %8, 8 br i1 %lt, label %loop.body, label %loop.exit loop.body: ; preds = %loop.cond - %10 = load i16*, i16** %to, align 8 - %11 = load i64, i64* %i, align 8 - %ptroffset = getelementptr inbounds i16, i16* %10, i64 %11 - %12 = load i16*, i16** %b, align 8 - %13 = load i64, i64* %i, align 8 - %ptroffset3 = getelementptr inbounds i16, i16* %12, i64 %13 - %14 = load i16, i16* %ptroffset3, align 2 - store i16 %14, i16* %ptroffset, align 2 - %15 = load i64, i64* %i, align 8 - %add = add i64 %15, 2 + %9 = load i16*, i16** %to, align 8 + %10 = load i64, i64* %i, align 8 + %ptroffset = getelementptr inbounds i16, i16* %9, i64 %10 + %11 = load i16*, i16** %b, align 8 + %12 = load i64, i64* %i, align 8 + %ptroffset2 = getelementptr inbounds i16, i16* %11, i64 %12 + %13 = load i16, i16* %ptroffset2, align 2 + store i16 %13, i16* %ptroffset, align 2 + %14 = load i64, i64* %i, align 8 + %add = add i64 %14, 2 store i64 %add, i64* %i, align 8 br label %loop.cond loop.exit: ; preds = %loop.cond - %16 = load i64, i64* %x1, align 8 - ret i64 %16 + %15 = load i64, i64* %x, align 8 + ret i64 %15 } -; Function Attrs: nounwind define i32 @userland_bitcast.test(float %0) #0 { entry: - %x = alloca float, align 4 %expr = alloca float, align 4 - %x1 = alloca [4 x i8], align 1 + %x = alloca [4 x i8], align 1 %b = alloca i8*, align 8 %to = alloca i8*, align 8 %i = alloca i64, align 8 %tempcoerce = alloca i32, align 4 - store float %0, float* %x, align 4 - %1 = load float, float* %x, align 4 - store float %1, float* %expr, align 4 + store float %0, float* %expr, align 4 %ptrptr = bitcast float* %expr to i8* store i8* %ptrptr, i8** %b, align 8 - %ptrptr2 = bitcast [4 x i8]* %x1 to i8* - store i8* %ptrptr2, i8** %to, align 8 + %ptrptr1 = bitcast [4 x i8]* %x to i8* + store i8* %ptrptr1, i8** %to, align 8 store i64 0, i64* %i, align 8 br label %loop.cond loop.cond: ; preds = %loop.body, %entry - %2 = load i64, i64* %i, align 8 - %lt = icmp ult i64 %2, 4 + %1 = load i64, i64* %i, align 8 + %lt = icmp ult i64 %1, 4 br i1 %lt, label %loop.body, label %loop.exit loop.body: ; preds = %loop.cond - %3 = load i8*, i8** %to, align 8 - %4 = load i64, i64* %i, align 8 - %ptroffset = getelementptr inbounds i8, i8* %3, i64 %4 - %5 = load i8*, i8** %b, align 8 - %6 = load i64, i64* %i, align 8 - %ptroffset3 = getelementptr inbounds i8, i8* %5, i64 %6 - %7 = load i8, i8* %ptroffset3, align 1 - store i8 %7, i8* %ptroffset, align 1 - %8 = load i64, i64* %i, align 8 - %add = add i64 %8, 1 + %2 = load i8*, i8** %to, align 8 + %3 = load i64, i64* %i, align 8 + %ptroffset = getelementptr inbounds i8, i8* %2, i64 %3 + %4 = load i8*, i8** %b, align 8 + %5 = load i64, i64* %i, align 8 + %ptroffset2 = getelementptr inbounds i8, i8* %4, i64 %5 + %6 = load i8, i8* %ptroffset2, align 1 + store i8 %6, i8* %ptroffset, align 1 + %7 = load i64, i64* %i, align 8 + %add = add i64 %7, 1 store i64 %add, i64* %i, align 8 br label %loop.cond loop.exit: ; preds = %loop.cond - %9 = bitcast i32* %tempcoerce to i8* - %10 = bitcast [4 x i8]* %x1 to i8* - call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %9, i8* align 1 %10, i32 4, i1 false) - %11 = load i32, i32* %tempcoerce, align 4 - ret i32 %11 + %8 = bitcast i32* %tempcoerce to i8* + %9 = bitcast [4 x i8]* %x to i8* + call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %8, i8* align 1 %9, i32 4, i1 false) + %10 = load i32, i32* %tempcoerce, align 4 + ret i32 %10 } -; Function Attrs: nounwind define void @userland_bitcast.main() #0 { entry: %f = alloca float, align 4 diff --git a/test/test_suite/methods/enum_distinct_err_methods.c3t b/test/test_suite/methods/enum_distinct_err_methods.c3t index 5a0cf22c6..43d171c38 100644 --- a/test/test_suite/methods/enum_distinct_err_methods.c3t +++ b/test/test_suite/methods/enum_distinct_err_methods.c3t @@ -43,25 +43,25 @@ fn int main() // #expect: foo.ll -define void @foo.Foo__hello(i64* %0) - %f = alloca i64*, align 8 - store i64* %0, i64** %f, align 8 - %1 = call i32 @"std::io.println"(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0)) +define void @foo.Foo__hello(i64* %0) #0 { +entry: + %1 = call i32 @"std::io.println"(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0)) #1 ret void +} -define void @foo.Bar__hello(i32* %0) - %b = alloca i32*, align 8 - store i32* %0, i32** %b, align 8 - %1 = call i32 @"std::io.println"(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i32 0, i32 0)) +define void @foo.Bar__hello(i32* %0) #0 { +entry: + %1 = call i32 @"std::io.println"(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i32 0, i32 0)) #1 ret void +} -define void @foo.MyEnum__hello(i32* %0) - %myenum = alloca i32*, align 8 - store i32* %0, i32** %myenum, align 8 - %1 = call i32 @"std::io.println"(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i32 0, i32 0)) +define void @foo.MyEnum__hello(i32* %0) #0 { +entry: + %1 = call i32 @"std::io.println"(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i32 0, i32 0)) #1 ret void +} -define i32 @main() +define i32 @main() #0 { entry: %f = alloca i64, align 8 %b = alloca i32, align 4 @@ -73,3 +73,4 @@ entry: call void @foo.Bar__hello(i32* %b) call void @foo.MyEnum__hello(i32* %a) ret i32 0 +} diff --git a/test/test_suite/pointers/pointer_index.c3t b/test/test_suite/pointers/pointer_index.c3t index 97ab79e61..6526fef1e 100644 --- a/test/test_suite/pointers/pointer_index.c3t +++ b/test/test_suite/pointers/pointer_index.c3t @@ -26,69 +26,53 @@ fn void test3(long* x) define void @pointer_index.test1(i32* %0) #0 { entry: - %x = alloca i32*, align 8 %a = alloca i32, align 4 %b = alloca i32, align 4 %c = alloca i32, align 4 %d = alloca i32, align 4 - store i32* %0, i32** %x, align 8 - %1 = load i32*, i32** %x, align 8 - %ptroffset = getelementptr inbounds i32, i32* %1, i64 0 - %2 = load i32, i32* %ptroffset, align 4 - store i32 %2, i32* %a, align 4 - %3 = load i32*, i32** %x, align 8 - %4 = load i32, i32* %3, align 8 - store i32 %4, i32* %b, align 4 - %5 = load i32*, i32** %x, align 8 - %ptroffset1 = getelementptr inbounds i32, i32* %5, i64 1 - %6 = load i32, i32* %ptroffset1, align 4 - store i32 %6, i32* %c, align 4 - %7 = load i32*, i32** %x, align 8 - %ptroffset2 = getelementptr inbounds i32, i32* %7, i64 -1 - %8 = load i32, i32* %ptroffset2, align 4 - store i32 %8, i32* %d, align 4 + %ptroffset = getelementptr inbounds i32, i32* %0, i64 0 + %1 = load i32, i32* %ptroffset, align 4 + store i32 %1, i32* %a, align 4 + %2 = load i32, i32* %0, align 8 + store i32 %2, i32* %b, align 4 + %ptroffset1 = getelementptr inbounds i32, i32* %0, i64 1 + %3 = load i32, i32* %ptroffset1, align 4 + store i32 %3, i32* %c, align 4 + %ptroffset2 = getelementptr inbounds i32, i32* %0, i64 -1 + %4 = load i32, i32* %ptroffset2, align 4 + store i32 %4, i32* %d, align 4 ret void } ; Function Attrs: nounwind define void @pointer_index.test2(i8* %0) #0 { entry: - %x = alloca i8*, align 8 %a = alloca i8, align 1 %b = alloca i8, align 1 %c = alloca i8, align 1 - store i8* %0, i8** %x, align 8 - %1 = load i8*, i8** %x, align 8 - %ptroffset = getelementptr inbounds i8, i8* %1, i64 0 - %2 = load i8, i8* %ptroffset, align 1 - store i8 %2, i8* %a, align 1 - %3 = load i8*, i8** %x, align 8 - %4 = load i8, i8* %3, align 8 - store i8 %4, i8* %b, align 1 - %5 = load i8*, i8** %x, align 8 - %ptroffset1 = getelementptr inbounds i8, i8* %5, i64 1 - %6 = load i8, i8* %ptroffset1, align 1 - store i8 %6, i8* %c, align 1 + %ptroffset = getelementptr inbounds i8, i8* %0, i64 0 + %1 = load i8, i8* %ptroffset, align 1 + store i8 %1, i8* %a, align 1 + %2 = load i8, i8* %0, align 8 + store i8 %2, i8* %b, align 1 + %ptroffset1 = getelementptr inbounds i8, i8* %0, i64 1 + %3 = load i8, i8* %ptroffset1, align 1 + store i8 %3, i8* %c, align 1 ret void } define void @pointer_index.test3(i64* %0) #0 { entry: - %x = alloca i64*, align 8 %a = alloca i64, align 8 %b = alloca i64, align 8 %c = alloca i64, align 8 - store i64* %0, i64** %x, align 8 - %1 = load i64*, i64** %x, align 8 - %ptroffset = getelementptr inbounds i64, i64* %1, i64 0 - %2 = load i64, i64* %ptroffset, align 8 - store i64 %2, i64* %a, align 8 - %3 = load i64*, i64** %x, align 8 - %4 = load i64, i64* %3, align 8 - store i64 %4, i64* %b, align 8 - %5 = load i64*, i64** %x, align 8 - %ptroffset1 = getelementptr inbounds i64, i64* %5, i64 1 - %6 = load i64, i64* %ptroffset1, align 8 - store i64 %6, i64* %c, align 8 + %ptroffset = getelementptr inbounds i64, i64* %0, i64 0 + %1 = load i64, i64* %ptroffset, align 8 + store i64 %1, i64* %a, align 8 + %2 = load i64, i64* %0, align 8 + store i64 %2, i64* %b, align 8 + %ptroffset1 = getelementptr inbounds i64, i64* %0, i64 1 + %3 = load i64, i64* %ptroffset1, align 8 + store i64 %3, i64* %c, align 8 ret void } diff --git a/test/test_suite/slices/slice_assign.c3t b/test/test_suite/slices/slice_assign.c3t index 037d565d1..c2607dc6b 100644 --- a/test/test_suite/slices/slice_assign.c3t +++ b/test/test_suite/slices/slice_assign.c3t @@ -83,10 +83,6 @@ exit: ; preds = %cond define i32 @main(i32 %0, i8** %1) #0 { entry: - %"_$argv" = alloca i32, align 4 - %"_$argc" = alloca i8**, align 8 - store i32 %0, i32* %"_$argv", align 4 - store i8** %1, i8*** %"_$argc", align 8 call void @test.main() ret i32 0 } diff --git a/test/test_suite/statements/custom_foreach_with_ref.c3t b/test/test_suite/statements/custom_foreach_with_ref.c3t index 767608598..0319b6f92 100644 --- a/test/test_suite/statements/custom_foreach_with_ref.c3t +++ b/test/test_suite/statements/custom_foreach_with_ref.c3t @@ -85,6 +85,7 @@ fn void main() %Foo = type { [3 x i32] } + @Foo = linkonce_odr constant i8 1 @.str = private constant [11 x i8] c"getFields\0A\00", align 1 @.str.1 = private constant [11 x i8] c"Call made\0A\00", align 1 @@ -101,9 +102,7 @@ fn void main() @.str.11 = private constant [27 x i8] c"Pull value tempptr %d: %d\0A\00", align 1 @.str.12 = private constant [7 x i8] c"%d %d\0A\00", align 1 @.str.13 = private constant [7 x i8] c"%d %d\0A\00", align 1 -; Function Attrs: nounwind -declare void @printf(i8*, ...) #0 -; Function Attrs: nounwind + define void @foo.getFields([5 x i32]* noalias sret([5 x i32]) align 4 %0) #0 { entry: %literal = alloca [5 x i32], align 16 @@ -125,11 +124,8 @@ entry: } define %Foo* @foo.call(%Foo* %0) #0 { entry: - %f = alloca %Foo*, align 8 - store %Foo* %0, %Foo** %f, align 8 call void (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0)) - %1 = load %Foo*, %Foo** %f, align 8 - ret %Foo* %1 + ret %Foo* %0 } define void @foo.main() #0 { entry: @@ -209,11 +205,13 @@ entry: store %Foo* %13, %Foo** %"__enum$", align 8 store i32 3, i32* %"__len$", align 4 br label %loop.cond + loop.cond: ; preds = %loop.body, %entry %14 = load i32, i32* %"__idx$", align 4 %15 = load i32, i32* %"__len$", align 4 %lt = icmp slt i32 %14, %15 br i1 %lt, label %loop.body, label %loop.exit + loop.body: ; preds = %loop.cond %16 = load i32, i32* %"__idx$", align 4 store i32 %16, i32* %i, align 4 diff --git a/test/test_suite/statements/defer_break.c3t b/test/test_suite/statements/defer_break.c3t index 347c0bd73..1e66213f2 100644 --- a/test/test_suite/statements/defer_break.c3t +++ b/test/test_suite/statements/defer_break.c3t @@ -50,11 +50,7 @@ fn int main(int argc, char** argv) define i32 @main(i32 %0, i8** %1) #0 { entry: - %argc = alloca i32, align 4 - %argv = alloca i8**, align 8 %a = alloca i32, align 4 - store i32 %0, i32* %argc, align 4 - store i8** %1, i8*** %argv, align 8 store i32 0, i32* %a, align 4 call void @foo.defer2() %2 = load i32, i32* %a, align 4 @@ -77,8 +73,7 @@ loop.cond: ; preds = %exit6, %exit br i1 %intbool, label %loop.body, label %loop.exit loop.body: ; preds = %loop.cond - %4 = load i32, i32* %argc, align 4 - %eq1 = icmp eq i32 %4, 1 + %eq1 = icmp eq i32 %0, 1 br i1 %eq1, label %if.then2, label %if.exit4 if.then2: ; preds = %loop.body @@ -104,13 +99,12 @@ loop.exit: ; preds = %exit3, %loop.cond br label %loop.cond7 loop.cond7: ; preds = %loop.exit - %5 = load i32, i32* %a, align 4 - %intbool8 = icmp ne i32 %5, 0 + %4 = load i32, i32* %a, align 4 + %intbool8 = icmp ne i32 %4, 0 br i1 %intbool8, label %loop.body9, label %loop.exit18 loop.body9: ; preds = %loop.cond7 - %6 = load i32, i32* %argc, align 4 - %eq10 = icmp eq i32 %6, 1 + %eq10 = icmp eq i32 %0, 1 br i1 %eq10, label %if.then11, label %if.exit13 if.then11: ; preds = %loop.body9 diff --git a/test/test_suite/statements/defer_break_simple.c3t b/test/test_suite/statements/defer_break_simple.c3t index 67f0102d8..e9d971445 100644 --- a/test/test_suite/statements/defer_break_simple.c3t +++ b/test/test_suite/statements/defer_break_simple.c3t @@ -28,40 +28,44 @@ fn int main(int argc, char** argv) define i32 @main(i32 %0, i8** %1) #0 { entry: - %argc = alloca i32, align 4 - %argv = alloca i8**, align 8 %a = alloca i32, align 4 - store i32 %0, i32* %argc, align 4 - store i8** %1, i8*** %argv, align 8 store i32 0, i32* %a, align 4 br label %loop.cond + loop.cond: ; preds = %exit3, %entry %2 = load i32, i32* %a, align 4 %intbool = icmp ne i32 %2, 0 br i1 %intbool, label %loop.body, label %loop.exit + loop.body: ; preds = %loop.cond - %3 = load i32, i32* %argc, align 4 - %eq = icmp eq i32 %3, 1 + %eq = icmp eq i32 %0, 1 br i1 %eq, label %if.then, label %if.exit + if.then: ; preds = %loop.body call void @test.testA() call void @test.testB() br label %exit + exit: ; preds = %if.then call void @test.test2() br label %exit1 + exit1: ; preds = %exit br label %loop.exit + if.exit: ; preds = %loop.body call void @test.test3() call void @test.testA() call void @test.testB() br label %exit2 + exit2: ; preds = %if.exit call void @test.test2() br label %exit3 + exit3: ; preds = %exit2 br label %loop.cond + loop.exit: ; preds = %exit1, %loop.cond ret i32 0 } diff --git a/test/test_suite/statements/defer_break_switch.c3t b/test/test_suite/statements/defer_break_switch.c3t index 1a21917ac..de74c2eba 100644 --- a/test/test_suite/statements/defer_break_switch.c3t +++ b/test/test_suite/statements/defer_break_switch.c3t @@ -21,30 +21,45 @@ fn void test(int i) // #expect: defer_break_switch.ll -switch.case: - %3 = load i8, i8* %b, align 1 - %4 = trunc i8 %3 to i1 - br i1 %4, label %if.then, label %if.exit +define void @defer_break_switch.test(i32 %0) #0 { +entry: + %b = alloca i8, align 1 + %switch = alloca i32, align 4 + store i8 1, i8* %b, align 1 + store i32 %0, i32* %switch, align 4 + br label %switch.entry -if.then: +switch.entry: ; preds = %entry + %1 = load i32, i32* %switch, align 4 + switch i32 %1, label %switch.exit [ + i32 1, label %switch.case + i32 2, label %switch.case2 + ] + +switch.case: ; preds = %switch.entry + %2 = load i8, i8* %b, align 1 + %3 = trunc i8 %2 to i1 + br i1 %3, label %if.then, label %if.exit + +if.then: ; preds = %switch.case call void @defer_break_switch.test2() br label %exit -exit: +exit: ; preds = %if.then br label %switch.exit -if.exit: +if.exit: ; preds = %switch.case call void @defer_break_switch.test1() call void @defer_break_switch.test2() br label %exit1 -exit1: +exit1: ; preds = %if.exit br label %switch.exit -switch.case2: +switch.case2: ; preds = %switch.entry call void @defer_break_switch.test1() br label %switch.exit -switch.exit: +switch.exit: ; preds = %switch.case2, %exit1, %exit, %switch.entry ret void } diff --git a/test/test_suite/statements/defer_next_switch.c3t b/test/test_suite/statements/defer_next_switch.c3t index ad638d907..20b8ee167 100644 --- a/test/test_suite/statements/defer_next_switch.c3t +++ b/test/test_suite/statements/defer_next_switch.c3t @@ -21,30 +21,45 @@ fn void test(int i) // #expect: defer_next_switch.ll -switch.case: - %3 = load i8, i8* %b, align 1 - %4 = trunc i8 %3 to i1 - br i1 %4, label %if.then, label %if.exit +define void @defer_next_switch.test(i32 %0) #0 { +entry: + %b = alloca i8, align 1 + %switch = alloca i32, align 4 + store i8 1, i8* %b, align 1 + store i32 %0, i32* %switch, align 4 + br label %switch.entry -if.then: +switch.entry: ; preds = %entry + %1 = load i32, i32* %switch, align 4 + switch i32 %1, label %switch.exit [ + i32 1, label %switch.case + i32 2, label %switch.case2 + ] + +switch.case: ; preds = %switch.entry + %2 = load i8, i8* %b, align 1 + %3 = trunc i8 %2 to i1 + br i1 %3, label %if.then, label %if.exit + +if.then: ; preds = %switch.case call void @defer_next_switch.test2() br label %exit -exit: +exit: ; preds = %if.then br label %switch.case2 -if.exit: +if.exit: ; preds = %switch.case call void @defer_next_switch.test1() call void @defer_next_switch.test2() br label %exit1 -exit1: +exit1: ; preds = %if.exit br label %switch.exit -switch.case2: +switch.case2: ; preds = %switch.entry, %exit call void @defer_next_switch.test1() br label %switch.exit -switch.exit: +switch.exit: ; preds = %switch.case2, %exit1, %switch.entry ret void } diff --git a/test/test_suite/statements/defer_return.c3t b/test/test_suite/statements/defer_return.c3t index 44adb4d60..5494a5a2f 100644 --- a/test/test_suite/statements/defer_return.c3t +++ b/test/test_suite/statements/defer_return.c3t @@ -38,11 +38,7 @@ fn int main(int argc, char **argv) define i32 @main(i32 %0, i8** %1) #0 { entry: - %argc = alloca i32, align 4 - %argv = alloca i8**, align 8 %a = alloca i32, align 4 - store i32 %0, i32* %argc, align 4 - store i8** %1, i8*** %argv, align 8 store i32 0, i32* %a, align 4 br label %loop.cond @@ -52,14 +48,12 @@ loop.cond: ; preds = %exit3, %entry br i1 %intbool, label %loop.body, label %loop.exit loop.body: ; preds = %loop.cond - %3 = load i32, i32* %argc, align 4 - %eq = icmp eq i32 %3, 1 + %eq = icmp eq i32 %0, 1 br i1 %eq, label %if.then, label %if.exit if.then: ; preds = %loop.body - %4 = load i32, i32* %a, align 4 - %5 = load i32, i32* %argc, align 4 - %add = add i32 %4, %5 + %3 = load i32, i32* %a, align 4 + %add = add i32 %3, %0 call void @test.test2() br label %exit @@ -86,18 +80,17 @@ loop.exit: ; preds = %loop.cond br label %loop.cond4 loop.cond4: ; preds = %loop.exit - %6 = load i32, i32* %a, align 4 - %intbool5 = icmp ne i32 %6, 0 + %4 = load i32, i32* %a, align 4 + %intbool5 = icmp ne i32 %4, 0 br i1 %intbool5, label %loop.body6, label %loop.exit21 loop.body6: ; preds = %loop.cond4 - %7 = load i32, i32* %argc, align 4 - %eq7 = icmp eq i32 %7, 1 + %eq7 = icmp eq i32 %0, 1 br i1 %eq7, label %if.then8, label %if.exit13 if.then8: ; preds = %loop.body6 - %8 = load i32, i32* %a, align 4 - %add9 = add i32 %8, 2 + %5 = load i32, i32* %a, align 4 + %add9 = add i32 %5, 2 call void @test.test6() br label %exit10 @@ -133,8 +126,7 @@ exit17: ; preds = %exit16 ret i32 4 loop.exit21: ; preds = %loop.cond4 - %9 = load i32, i32* %argc, align 4 - %add22 = add i32 0, %9 + %add22 = add i32 0, %0 call void @test.test5() br label %exit23 diff --git a/test/test_suite/statements/if_tests.c3t b/test/test_suite/statements/if_tests.c3t index 3268fc682..2ff7a0b03 100644 --- a/test/test_suite/statements/if_tests.c3t +++ b/test/test_suite/statements/if_tests.c3t @@ -28,38 +28,47 @@ fn void test3(int x) // #expect: iftest.ll +define void @iftest.test1(i32 %0) #0 { +entry: %x = alloca i32, align 4 store i32 %0, i32* %x, align 4 %1 = load i32, i32* %x, align 4 %gt = icmp sgt i32 %1, 0 br i1 %gt, label %if.then, label %if.exit -if.then: + +if.then: ; preds = %entry %2 = load i32, i32* %x, align 4 %add = add i32 %2, 1 store i32 %add, i32* %x, align 4 br label %exit -exit: + +exit: ; preds = %if.then br label %if.exit -if.exit: - ret void -define void @iftest.test2(i32 %0) - %x = alloca i32, align 4 - store i32 %0, i32* %x, align 4 - %1 = load i32, i32* %x, align 4 - %gt = icmp sgt i32 %1, 0 +if.exit: ; preds = %exit, %entry ret void +} -define void @iftest.test3(i32 %0) +define void @iftest.test2(i32 %0) #0 { +entry: + %gt = icmp sgt i32 %0, 0 + ret void +} + +define void @iftest.test3(i32 %0) #0 { +entry: %x = alloca i32, align 4 store i32 %0, i32* %x, align 4 %1 = load i32, i32* %x, align 4 %gt = icmp sgt i32 %1, 0 br i1 %gt, label %if.exit, label %if.else -if.else: + +if.else: ; preds = %entry %2 = load i32, i32* %x, align 4 %add = add i32 %2, 1 store i32 %add, i32* %x, align 4 br label %if.exit -if.exit: + +if.exit: ; preds = %if.else, %entry ret void +} \ No newline at end of file diff --git a/test/test_suite/strings/string_escape.c3t b/test/test_suite/strings/string_escape.c3t index 12a5b9337..e3b76bd65 100644 --- a/test/test_suite/strings/string_escape.c3t +++ b/test/test_suite/strings/string_escape.c3t @@ -1,9 +1,10 @@ +// #target: x64-darwin fn void main() { char *s = "Hello\0 world!" " now"; } -// #expect: string_escape.ll +/* #expect: string_escape.ll @.str = private constant [18 x i8] c"Hello\00 world! now\00", align 1 @@ -16,10 +17,6 @@ entry: define i32 @main(i32 %0, i8** %1) #0 { entry: - %"_$argv" = alloca i32, align 4 - %"_$argc" = alloca i8**, align 8 - store i32 %0, i32* %"_$argv", align 4 - store i8** %1, i8*** %"_$argc", align 8 call void @string_escape.main() ret i32 0 } \ No newline at end of file diff --git a/test/test_suite/struct/struct_as_value.c3t b/test/test_suite/struct/struct_as_value.c3t index de6f348b7..9cb3ce59c 100644 --- a/test/test_suite/struct/struct_as_value.c3t +++ b/test/test_suite/struct/struct_as_value.c3t @@ -15,38 +15,35 @@ fn Event test(int x) // #expect: test.ll - @Event = linkonce_odr constant i8 1 - @.__const = private constant %Event { i32 1 }, align 4 - @.__const.1 = private constant %Event { i32 2 }, align 4 +@Event = linkonce_odr constant i8 1 +@.__const = private constant %Event { i32 1 }, align 4 +@.__const.1 = private constant %Event { i32 2 }, align 4 - ; Function Attrs: nounwind - define i32 @test.test(i32 %0) #0 { - entry: - %x = alloca i32, align 4 - %foo = alloca %Event, align 4 - %bar = alloca %Event, align 4 - %taddr = alloca %Event, align 4 - store i32 %0, i32* %x, align 4 - %1 = bitcast %Event* %foo to i8* - call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %1, i8* align 4 bitcast (%Event* @.__const to i8*), i32 4, i1 false) - %2 = bitcast %Event* %bar to i8* - call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %2, i8* align 4 bitcast (%Event* @.__const.1 to i8*), i32 4, i1 false) - %3 = load i32, i32* %x, align 4 - %intbool = icmp ne i32 %3, 0 - br i1 %intbool, label %cond.lhs, label %cond.rhs +; Function Attrs: nounwind +define i32 @test.test(i32 %0) #0 { +entry: + %foo = alloca %Event, align 4 + %bar = alloca %Event, align 4 + %taddr = alloca %Event, align 4 + %1 = bitcast %Event* %foo to i8* + call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %1, i8* align 4 bitcast (%Event* @.__const to i8*), i32 4, i1 false) + %2 = bitcast %Event* %bar to i8* + call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %2, i8* align 4 bitcast (%Event* @.__const.1 to i8*), i32 4, i1 false) + %intbool = icmp ne i32 %0, 0 + br i1 %intbool, label %cond.lhs, label %cond.rhs - cond.lhs: ; preds = %entry - %4 = load %Event, %Event* %foo, align 4 - br label %cond.phi +cond.lhs: ; preds = %entry + %3 = load %Event, %Event* %foo, align 4 + br label %cond.phi - cond.rhs: ; preds = %entry - %5 = load %Event, %Event* %bar, align 4 - br label %cond.phi +cond.rhs: ; preds = %entry + %4 = load %Event, %Event* %bar, align 4 + br label %cond.phi - cond.phi: ; preds = %cond.rhs, %cond.lhs - %val = phi %Event [ %4, %cond.lhs ], [ %5, %cond.rhs ] - store %Event %val, %Event* %taddr, align 4 - %6 = getelementptr inbounds %Event, %Event* %taddr, i32 0, i32 0 - %7 = load i32, i32* %6, align 4 - ret i32 %7 - } \ No newline at end of file +cond.phi: ; preds = %cond.rhs, %cond.lhs + %val = phi %Event [ %3, %cond.lhs ], [ %4, %cond.rhs ] + store %Event %val, %Event* %taddr, align 4 + %5 = getelementptr inbounds %Event, %Event* %taddr, i32 0, i32 0 + %6 = load i32, i32* %5, align 4 + ret i32 %6 +} \ No newline at end of file diff --git a/test/test_suite/struct/struct_as_value_aarch64.c3t b/test/test_suite/struct/struct_as_value_aarch64.c3t index fe026b63b..e3c6ab4af 100644 --- a/test/test_suite/struct/struct_as_value_aarch64.c3t +++ b/test/test_suite/struct/struct_as_value_aarch64.c3t @@ -15,32 +15,31 @@ fn Event test(int x) // #expect: test.ll - %x = alloca i32, align 4 +define i64 @test.test(i32 %0) #0 { +entry: %foo = alloca %Event, align 4 %bar = alloca %Event, align 4 %taddr = alloca %Event, align 4 - store i32 %0, i32* %x, align 4 %1 = bitcast %Event* %foo to i8* call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %1, i8* align 4 bitcast (%Event* @.__const to i8*), i32 4, i1 false) %2 = bitcast %Event* %bar to i8* call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %2, i8* align 4 bitcast (%Event* @.__const.1 to i8*), i32 4, i1 false) - %3 = load i32, i32* %x, align 4 - %intbool = icmp ne i32 %3, 0 + %intbool = icmp ne i32 %0, 0 br i1 %intbool, label %cond.lhs, label %cond.rhs cond.lhs: ; preds = %entry - %4 = load %Event, %Event* %foo, align 4 + %3 = load %Event, %Event* %foo, align 4 br label %cond.phi cond.rhs: ; preds = %entry - %5 = load %Event, %Event* %bar, align 4 + %4 = load %Event, %Event* %bar, align 4 br label %cond.phi cond.phi: ; preds = %cond.rhs, %cond.lhs - %val = phi %Event [ %4, %cond.lhs ], [ %5, %cond.rhs ] + %val = phi %Event [ %3, %cond.lhs ], [ %4, %cond.rhs ] store %Event %val, %Event* %taddr, align 4 - %6 = getelementptr inbounds %Event, %Event* %taddr, i32 0, i32 0 - %7 = load i32, i32* %6, align 4 - %8 = zext i32 %7 to i64 - ret i64 %8 + %5 = getelementptr inbounds %Event, %Event* %taddr, i32 0, i32 0 + %6 = load i32, i32* %5, align 4 + %7 = zext i32 %6 to i64 + ret i64 %7 } diff --git a/test/test_suite/struct/struct_pack_and_align.c3t b/test/test_suite/struct/struct_pack_and_align.c3t index 4983205e4..33c707700 100644 --- a/test/test_suite/struct/struct_pack_and_align.c3t +++ b/test/test_suite/struct/struct_pack_and_align.c3t @@ -85,18 +85,15 @@ Foo6 foo6 = { 1, 2, 3 }; @struct2.test5 entry: - %x = alloca i8, align 1 %y = alloca %Foo5, align 16 - store i8 %0, i8* %x, align 1 %1 = bitcast %Foo5* %y to i8* call void @llvm.memset.p0i8.i64(i8* align 16 %1, i8 0, i64 32, i1 false) %2 = getelementptr inbounds %Foo5, %Foo5* %y, i32 0, i32 2 - %3 = load i8, i8* %x, align 1 - store i8 %3, i8* %2, align 16 - %4 = getelementptr inbounds %Foo5, %Foo5* %y, i32 0, i32 2 - %5 = load i8, i8* %4, align 16 - %sisiext = sext i8 %5 to i32 - %6 = getelementptr inbounds %Foo5, %Foo5* %y, i32 0, i32 0 - %7 = load i32, i32* %6, align 16 - %add = add i32 %sisiext, %7 + store i8 %0, i8* %2, align 16 + %3 = getelementptr inbounds %Foo5, %Foo5* %y, i32 0, i32 2 + %4 = load i8, i8* %3, align 16 + %sisiext = sext i8 %4 to i32 + %5 = getelementptr inbounds %Foo5, %Foo5* %y, i32 0, i32 0 + %6 = load i32, i32* %5, align 16 + %add = add i32 %sisiext, %6 ret i32 %add