Files
c3c/test/test_suite/vector/vector_init_regression.c3t

416 lines
18 KiB
C

// #target: macos-x64
// #opt: --fp-math=relaxed
module test;
extern fn int printf(char* format, ...);
fn void main() {
float radians = 3.1415 / 4;
float[<3>] axis = {0.0, 0.0, 1.0};
float cosr = (float) $$cos(radians);
float sinr = (float) $$sin(radians);
float x = axis[0];
float y = axis[1];
float z = axis[2];
float[<4>][4] a = {};
a[0] = {
cosr + (x * x) * (float) (1.0 - cosr),
(x * y) * (float) (1.0 - cosr) - (z * sinr),
(x * z) * (float) (1.0 - cosr) + (y * sinr),
0.0
};
a[1] = {
(y * x) * (float) (1.0 - cosr) + (z * sinr),
cosr + (y * y) * (float) (1.0 - cosr),
(y * z) * (float) (1.0 - cosr) - (x * sinr),
0.0
};
a[2] = {
(z * x) * (float) (1.0 - cosr) - (y * sinr),
(z * y) * (float) (1.0 - cosr) + (x * sinr),
cosr + (z * z) * (float) (1.0 - cosr),
0.0
};
a[3] = {
0.0,
0.0,
0.0,
1.0
};
float[<4>][4] b = {
{
cosr + (x * x) * (float) (1.0 - cosr),
(x * y) * (float) (1.0 - cosr) - (z * sinr),
(x * z) * (float) (1.0 - cosr) + (y * sinr),
0.0
},
{
(y * x) * (float) (1.0 - cosr) + (z * sinr),
cosr + (y * y) * (float) (1.0 - cosr),
(y * z) * (float) (1.0 - cosr) - (x * sinr),
0.0
},
{
(z * x) * (float) (1.0 - cosr) - (y * sinr),
(z * y) * (float) (1.0 - cosr) + (x * sinr),
cosr + (z * z) * (float) (1.0 - cosr),
0.0
},
{
0.0,
0.0,
0.0,
1.0
}
};
foreach(v : a) {
printf("A: %f %f %f %f\n", v[0], v[1], v[2], v[3]);
}
printf("\n");
foreach(v : b) {
printf("B: %f %f %f %f\n", v[0], v[1], v[2], v[3]);
}
}
/* #expect: test.ll
define void @test.main() #0 {
entry:
%radians = alloca float, align 4
%axis = alloca <3 x float>, align 16
%cosr = alloca float, align 4
%sinr = alloca float, align 4
%x = alloca float, align 4
%y = alloca float, align 4
%z = alloca float, align 4
%a = alloca [4 x <4 x float>], align 16
%b = alloca [4 x <4 x float>], align 16
%.anon = alloca i64, align 8
%v = alloca <4 x float>, align 16
%.anon85 = alloca i64, align 8
%v89 = alloca <4 x float>, align 16
store float 0x3FE921CAC0000000, ptr %radians, align 4
store <3 x float> <float 0.000000e+00, float 0.000000e+00, float 1.000000e+00>, ptr %axis, align 16
%0 = load float, ptr %radians, align 4
%1 = call reassoc arcp contract float @llvm.cos.f32(float %0)
store float %1, ptr %cosr, align 4
%2 = load float, ptr %radians, align 4
%3 = call reassoc arcp contract float @llvm.sin.f32(float %2)
store float %3, ptr %sinr, align 4
%4 = load <3 x float>, ptr %axis, align 16
%5 = extractelement <3 x float> %4, i64 0
store float %5, ptr %x, align 4
%6 = load <3 x float>, ptr %axis, align 16
%7 = extractelement <3 x float> %6, i64 1
store float %7, ptr %y, align 4
%8 = load <3 x float>, ptr %axis, align 16
%9 = extractelement <3 x float> %8, i64 2
store float %9, ptr %z, align 4
call void @llvm.memset.p0.i64(ptr align 16 %a, i8 0, i64 64, i1 false)
%10 = getelementptr inbounds [4 x <4 x float>], ptr %a, i64 0, i64 0
%11 = load float, ptr %cosr, align 4
%12 = load float, ptr %x, align 4
%13 = load float, ptr %x, align 4
%fmul = fmul reassoc arcp contract float %12, %13
%14 = load float, ptr %cosr, align 4
%fpfpext = fpext float %14 to double
%fsub = fsub reassoc arcp contract double 1.000000e+00, %fpfpext
%fpfptrunc = fptrunc double %fsub to float
%15 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul, float %fpfptrunc, float %11)
%16 = insertelement <4 x float> undef, float %15, i64 0
%17 = load float, ptr %x, align 4
%18 = load float, ptr %y, align 4
%fmul1 = fmul reassoc arcp contract float %17, %18
%19 = load float, ptr %cosr, align 4
%fpfpext2 = fpext float %19 to double
%fsub3 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext2
%fpfptrunc4 = fptrunc double %fsub3 to float
%20 = load float, ptr %z, align 4
%21 = load float, ptr %sinr, align 4
%fmul5 = fmul reassoc arcp contract float %20, %21
%22 = fneg reassoc arcp contract float %fmul5
%23 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul1, float %fpfptrunc4, float %22)
%24 = insertelement <4 x float> %16, float %23, i64 1
%25 = load float, ptr %x, align 4
%26 = load float, ptr %z, align 4
%fmul6 = fmul reassoc arcp contract float %25, %26
%27 = load float, ptr %cosr, align 4
%fpfpext7 = fpext float %27 to double
%fsub8 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext7
%fpfptrunc9 = fptrunc double %fsub8 to float
%28 = load float, ptr %y, align 4
%29 = load float, ptr %sinr, align 4
%fmul10 = fmul reassoc arcp contract float %28, %29
%30 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul6, float %fpfptrunc9, float %fmul10)
%31 = insertelement <4 x float> %24, float %30, i64 2
%32 = insertelement <4 x float> %31, float 0.000000e+00, i64 3
store <4 x float> %32, ptr %10, align 16
%33 = getelementptr inbounds [4 x <4 x float>], ptr %a, i64 0, i64 1
%34 = load float, ptr %y, align 4
%35 = load float, ptr %x, align 4
%fmul11 = fmul reassoc arcp contract float %34, %35
%36 = load float, ptr %cosr, align 4
%fpfpext12 = fpext float %36 to double
%fsub13 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext12
%fpfptrunc14 = fptrunc double %fsub13 to float
%37 = load float, ptr %z, align 4
%38 = load float, ptr %sinr, align 4
%fmul15 = fmul reassoc arcp contract float %37, %38
%39 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul11, float %fpfptrunc14, float %fmul15)
%40 = insertelement <4 x float> undef, float %39, i64 0
%41 = load float, ptr %cosr, align 4
%42 = load float, ptr %y, align 4
%43 = load float, ptr %y, align 4
%fmul16 = fmul reassoc arcp contract float %42, %43
%44 = load float, ptr %cosr, align 4
%fpfpext17 = fpext float %44 to double
%fsub18 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext17
%fpfptrunc19 = fptrunc double %fsub18 to float
%45 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul16, float %fpfptrunc19, float %41)
%46 = insertelement <4 x float> %40, float %45, i64 1
%47 = load float, ptr %y, align 4
%48 = load float, ptr %z, align 4
%fmul20 = fmul reassoc arcp contract float %47, %48
%49 = load float, ptr %cosr, align 4
%fpfpext21 = fpext float %49 to double
%fsub22 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext21
%fpfptrunc23 = fptrunc double %fsub22 to float
%50 = load float, ptr %x, align 4
%51 = load float, ptr %sinr, align 4
%fmul24 = fmul reassoc arcp contract float %50, %51
%52 = fneg reassoc arcp contract float %fmul24
%53 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul20, float %fpfptrunc23, float %52)
%54 = insertelement <4 x float> %46, float %53, i64 2
%55 = insertelement <4 x float> %54, float 0.000000e+00, i64 3
store <4 x float> %55, ptr %33, align 16
%56 = getelementptr inbounds [4 x <4 x float>], ptr %a, i64 0, i64 2
%57 = load float, ptr %z, align 4
%58 = load float, ptr %x, align 4
%fmul25 = fmul reassoc arcp contract float %57, %58
%59 = load float, ptr %cosr, align 4
%fpfpext26 = fpext float %59 to double
%fsub27 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext26
%fpfptrunc28 = fptrunc double %fsub27 to float
%60 = load float, ptr %y, align 4
%61 = load float, ptr %sinr, align 4
%fmul29 = fmul reassoc arcp contract float %60, %61
%62 = fneg reassoc arcp contract float %fmul29
%63 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul25, float %fpfptrunc28, float %62)
%64 = insertelement <4 x float> undef, float %63, i64 0
%65 = load float, ptr %z, align 4
%66 = load float, ptr %y, align 4
%fmul30 = fmul reassoc arcp contract float %65, %66
%67 = load float, ptr %cosr, align 4
%fpfpext31 = fpext float %67 to double
%fsub32 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext31
%fpfptrunc33 = fptrunc double %fsub32 to float
%68 = load float, ptr %x, align 4
%69 = load float, ptr %sinr, align 4
%fmul34 = fmul reassoc arcp contract float %68, %69
%70 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul30, float %fpfptrunc33, float %fmul34)
%71 = insertelement <4 x float> %64, float %70, i64 1
%72 = load float, ptr %cosr, align 4
%73 = load float, ptr %z, align 4
%74 = load float, ptr %z, align 4
%fmul35 = fmul reassoc arcp contract float %73, %74
%75 = load float, ptr %cosr, align 4
%fpfpext36 = fpext float %75 to double
%fsub37 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext36
%fpfptrunc38 = fptrunc double %fsub37 to float
%76 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul35, float %fpfptrunc38, float %72)
%77 = insertelement <4 x float> %71, float %76, i64 2
%78 = insertelement <4 x float> %77, float 0.000000e+00, i64 3
store <4 x float> %78, ptr %56, align 16
%79 = getelementptr inbounds [4 x <4 x float>], ptr %a, i64 0, i64 3
store <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.000000e+00>, ptr %79, align 16
%80 = getelementptr inbounds [4 x <4 x float>], ptr %b, i64 0, i64 0
%81 = load float, ptr %cosr, align 4
%82 = load float, ptr %x, align 4
%83 = load float, ptr %x, align 4
%fmul39 = fmul reassoc arcp contract float %82, %83
%84 = load float, ptr %cosr, align 4
%fpfpext40 = fpext float %84 to double
%fsub41 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext40
%fpfptrunc42 = fptrunc double %fsub41 to float
%85 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul39, float %fpfptrunc42, float %81)
%86 = insertelement <4 x float> undef, float %85, i64 0
%87 = load float, ptr %x, align 4
%88 = load float, ptr %y, align 4
%fmul43 = fmul reassoc arcp contract float %87, %88
%89 = load float, ptr %cosr, align 4
%fpfpext44 = fpext float %89 to double
%fsub45 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext44
%fpfptrunc46 = fptrunc double %fsub45 to float
%90 = load float, ptr %z, align 4
%91 = load float, ptr %sinr, align 4
%fmul47 = fmul reassoc arcp contract float %90, %91
%92 = fneg reassoc arcp contract float %fmul47
%93 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul43, float %fpfptrunc46, float %92)
%94 = insertelement <4 x float> %86, float %93, i64 1
%95 = load float, ptr %x, align 4
%96 = load float, ptr %z, align 4
%fmul48 = fmul reassoc arcp contract float %95, %96
%97 = load float, ptr %cosr, align 4
%fpfpext49 = fpext float %97 to double
%fsub50 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext49
%fpfptrunc51 = fptrunc double %fsub50 to float
%98 = load float, ptr %y, align 4
%99 = load float, ptr %sinr, align 4
%fmul52 = fmul reassoc arcp contract float %98, %99
%100 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul48, float %fpfptrunc51, float %fmul52)
%101 = insertelement <4 x float> %94, float %100, i64 2
%102 = insertelement <4 x float> %101, float 0.000000e+00, i64 3
store <4 x float> %102, ptr %80, align 16
%103 = getelementptr inbounds [4 x <4 x float>], ptr %b, i64 0, i64 1
%104 = load float, ptr %y, align 4
%105 = load float, ptr %x, align 4
%fmul53 = fmul reassoc arcp contract float %104, %105
%106 = load float, ptr %cosr, align 4
%fpfpext54 = fpext float %106 to double
%fsub55 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext54
%fpfptrunc56 = fptrunc double %fsub55 to float
%107 = load float, ptr %z, align 4
%108 = load float, ptr %sinr, align 4
%fmul57 = fmul reassoc arcp contract float %107, %108
%109 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul53, float %fpfptrunc56, float %fmul57)
%110 = insertelement <4 x float> undef, float %109, i64 0
%111 = load float, ptr %cosr, align 4
%112 = load float, ptr %y, align 4
%113 = load float, ptr %y, align 4
%fmul58 = fmul reassoc arcp contract float %112, %113
%114 = load float, ptr %cosr, align 4
%fpfpext59 = fpext float %114 to double
%fsub60 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext59
%fpfptrunc61 = fptrunc double %fsub60 to float
%115 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul58, float %fpfptrunc61, float %111)
%116 = insertelement <4 x float> %110, float %115, i64 1
%117 = load float, ptr %y, align 4
%118 = load float, ptr %z, align 4
%fmul62 = fmul reassoc arcp contract float %117, %118
%119 = load float, ptr %cosr, align 4
%fpfpext63 = fpext float %119 to double
%fsub64 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext63
%fpfptrunc65 = fptrunc double %fsub64 to float
%120 = load float, ptr %x, align 4
%121 = load float, ptr %sinr, align 4
%fmul66 = fmul reassoc arcp contract float %120, %121
%122 = fneg reassoc arcp contract float %fmul66
%123 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul62, float %fpfptrunc65, float %122)
%124 = insertelement <4 x float> %116, float %123, i64 2
%125 = insertelement <4 x float> %124, float 0.000000e+00, i64 3
store <4 x float> %125, ptr %103, align 16
%126 = getelementptr inbounds [4 x <4 x float>], ptr %b, i64 0, i64 2
%127 = load float, ptr %z, align 4
%128 = load float, ptr %x, align 4
%fmul67 = fmul reassoc arcp contract float %127, %128
%129 = load float, ptr %cosr, align 4
%fpfpext68 = fpext float %129 to double
%fsub69 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext68
%fpfptrunc70 = fptrunc double %fsub69 to float
%130 = load float, ptr %y, align 4
%131 = load float, ptr %sinr, align 4
%fmul71 = fmul reassoc arcp contract float %130, %131
%132 = fneg reassoc arcp contract float %fmul71
%133 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul67, float %fpfptrunc70, float %132)
%134 = insertelement <4 x float> undef, float %133, i64 0
%135 = load float, ptr %z, align 4
%136 = load float, ptr %y, align 4
%fmul72 = fmul reassoc arcp contract float %135, %136
%137 = load float, ptr %cosr, align 4
%fpfpext73 = fpext float %137 to double
%fsub74 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext73
%fpfptrunc75 = fptrunc double %fsub74 to float
%138 = load float, ptr %x, align 4
%139 = load float, ptr %sinr, align 4
%fmul76 = fmul reassoc arcp contract float %138, %139
%140 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul72, float %fpfptrunc75, float %fmul76)
%141 = insertelement <4 x float> %134, float %140, i64 1
%142 = load float, ptr %cosr, align 4
%143 = load float, ptr %z, align 4
%144 = load float, ptr %z, align 4
%fmul77 = fmul reassoc arcp contract float %143, %144
%145 = load float, ptr %cosr, align 4
%fpfpext78 = fpext float %145 to double
%fsub79 = fsub reassoc arcp contract double 1.000000e+00, %fpfpext78
%fpfptrunc80 = fptrunc double %fsub79 to float
%146 = call reassoc arcp contract float @llvm.fmuladd.f32(float %fmul77, float %fpfptrunc80, float %142)
%147 = insertelement <4 x float> %141, float %146, i64 2
%148 = insertelement <4 x float> %147, float 0.000000e+00, i64 3
store <4 x float> %148, ptr %126, align 16
%149 = getelementptr inbounds [4 x <4 x float>], ptr %b, i64 0, i64 3
store <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.000000e+00>, ptr %149, align 16
store i64 0, ptr %.anon, align 8
br label %loop.cond
loop.cond: ; preds = %loop.body, %entry
%150 = load i64, ptr %.anon, align 8
%gt = icmp ugt i64 4, %150
br i1 %gt, label %loop.body, label %loop.exit
loop.body: ; preds = %loop.cond
%151 = load i64, ptr %.anon, align 8
%152 = getelementptr inbounds [4 x <4 x float>], ptr %a, i64 0, i64 %151
%153 = load <4 x float>, ptr %152, align 16
store <4 x float> %153, ptr %v, align 16
%154 = load <4 x float>, ptr %v, align 16
%155 = extractelement <4 x float> %154, i64 0
%fpfpext81 = fpext float %155 to double
%156 = load <4 x float>, ptr %v, align 16
%157 = extractelement <4 x float> %156, i64 1
%fpfpext82 = fpext float %157 to double
%158 = load <4 x float>, ptr %v, align 16
%159 = extractelement <4 x float> %158, i64 2
%fpfpext83 = fpext float %159 to double
%160 = load <4 x float>, ptr %v, align 16
%161 = extractelement <4 x float> %160, i64 3
%fpfpext84 = fpext float %161 to double
%162 = call i32 (ptr, ...) @printf(ptr @.str, double %fpfpext81, double %fpfpext82, double %fpfpext83, double %fpfpext84)
%163 = load i64, ptr %.anon, align 8
%add = add i64 %163, 1
store i64 %add, ptr %.anon, align 8
br label %loop.cond
loop.exit: ; preds = %loop.cond
%164 = call i32 (ptr, ...) @printf(ptr @.str.1)
store i64 0, ptr %.anon85, align 8
br label %loop.cond86
loop.cond86: ; preds = %loop.body88, %loop.exit
%165 = load i64, ptr %.anon85, align 8
%gt87 = icmp ugt i64 4, %165
br i1 %gt87, label %loop.body88, label %loop.exit95
loop.body88: ; preds = %loop.cond86
%166 = load i64, ptr %.anon85, align 8
%167 = getelementptr inbounds [4 x <4 x float>], ptr %b, i64 0, i64 %166
%168 = load <4 x float>, ptr %167, align 16
store <4 x float> %168, ptr %v89, align 16
%169 = load <4 x float>, ptr %v89, align 16
%170 = extractelement <4 x float> %169, i64 0
%fpfpext90 = fpext float %170 to double
%171 = load <4 x float>, ptr %v89, align 16
%172 = extractelement <4 x float> %171, i64 1
%fpfpext91 = fpext float %172 to double
%173 = load <4 x float>, ptr %v89, align 16
%174 = extractelement <4 x float> %173, i64 2
%fpfpext92 = fpext float %174 to double
%175 = load <4 x float>, ptr %v89, align 16
%176 = extractelement <4 x float> %175, i64 3
%fpfpext93 = fpext float %176 to double
%177 = call i32 (ptr, ...) @printf(ptr @.str.2, double %fpfpext90, double %fpfpext91, double %fpfpext92, double %fpfpext93)
%178 = load i64, ptr %.anon85, align 8
%add94 = add i64 %178, 1
store i64 %add94, ptr %.anon85, align 8
br label %loop.cond86
loop.exit95: ; preds = %loop.cond86
ret void
}