1// RUN: tco --target=i386-unknown-linux-gnu %s | FileCheck %s --check-prefix=I32 2// RUN: tco --target=x86_64-unknown-linux-gnu %s | FileCheck %s --check-prefix=X64 3// RUN: tco --target=aarch64-unknown-linux-gnu %s | FileCheck %s --check-prefix=AARCH64 4// RUN: tco --target=powerpc64le-unknown-linux-gnu %s | FileCheck %s --check-prefix=PPC 5 6// I32-LABEL: define i64 @gen4() 7// X64-LABEL: define <2 x float> @gen4() 8// AARCH64-LABEL: define { float, float } @gen4() 9// PPC-LABEL: define { float, float } @gen4() 10func.func @gen4() -> !fir.complex<4> { 11 %1 = fir.undefined !fir.complex<4> 12 %2 = arith.constant 2.0 : f32 13 %3 = fir.convert %2 : (f32) -> !fir.real<4> 14 %c0 = arith.constant 0 : i32 15 %4 = fir.insert_value %1, %3, [0 : index] : (!fir.complex<4>, !fir.real<4>) -> !fir.complex<4> 16 %c1 = arith.constant 1 : i32 17 %5 = arith.constant -42.0 : f32 18 %6 = fir.insert_value %4, %5, [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4> 19 // I32: store { float, float } { float 2.000000e+00, float -4.200000e+01 } 20 // I32: %[[load:.*]] = load i64, ptr 21 // I32: ret i64 %[[load]] 22 // X64: store { float, float } { float 2.000000e+00, float -4.200000e+01 } 23 // X64: %[[load:.*]] = load <2 x float>, ptr 24 // X64: ret <2 x float> %[[load]] 25 // AARCH64: ret { float, float } 26 // PPC: ret { float, float } 27 return %6 : !fir.complex<4> 28} 29 30// I32-LABEL: define void @gen8(ptr sret({ double, double }) align 4 % 31// X64-LABEL: define { double, double } @gen8() 32// AARCH64-LABEL: define { double, double } @gen8() 33// PPC-LABEL: define { double, double } @gen8() 34func.func @gen8() -> !fir.complex<8> { 35 %1 = fir.undefined !fir.complex<8> 36 %2 = arith.constant 1.0 : f64 37 %3 = arith.constant -4.0 : f64 38 %c0 = arith.constant 0 : i32 39 %4 = fir.insert_value %1, %3, [0 : index] : (!fir.complex<8>, f64) -> !fir.complex<8> 40 %c1 = arith.constant 1 : i32 41 %5 = fir.insert_value %4, %2, [1 : index] : (!fir.complex<8>, f64) -> !fir.complex<8> 42 // I32: store { double, double } { double -4.000000e+00, double 1.000000e+00 } 43 // I64: store { double, double } { double -4.000000e+00, double 1.000000e+00 } 44 // I64: %[[load:.*]] = load { double, double } 45 // I64: ret { double, double } %[[load]] 46 // AARCH64: ret { double, double } 47 // PPC: ret { double, double } 48 return %5 : !fir.complex<8> 49} 50 51// I32: declare void @sink4(ptr) 52// X64: declare void @sink4(<2 x float>) 53// AARCH64: declare void @sink4([2 x float]) 54// PPC: declare void @sink4(float, float) 55func.func private @sink4(!fir.complex<4>) -> () 56 57// I32: declare void @sink8(ptr) 58// X64: declare void @sink8(double, double) 59// AARCH64: declare void @sink8([2 x double]) 60// PPC: declare void @sink8(double, double) 61func.func private @sink8(!fir.complex<8>) -> () 62 63// I32-LABEL: define void @call4() 64// X64-LABEL: define void @call4() 65// AARCH64-LABEL: define void @call4() 66func.func @call4() { 67 // I32: = call i64 @gen4() 68 // X64: = call <2 x float> @gen4() 69 // AARCH64: = call { float, float } @gen4() 70 // PPC: = call { float, float } @gen4() 71 %1 = fir.call @gen4() : () -> !fir.complex<4> 72 // I32: call void @sink4(ptr % 73 // X64: call void @sink4(<2 x float> % 74 // AARCH64: call void @sink4([2 x float] % 75 // PPC: call void @sink4(float %{{.*}}, float %{{.*}}) 76 fir.call @sink4(%1) : (!fir.complex<4>) -> () 77 return 78} 79 80// I32-LABEL: define void @call8() 81// X64-LABEL: define void @call8() 82// AARCH64-LABEL: define void @call8() 83func.func @call8() { 84 // I32: call void @gen8(ptr % 85 // X64: = call { double, double } @gen8() 86 // AARCH64: = call { double, double } @gen8() 87 // PPC: = call { double, double } @gen8() 88 %1 = fir.call @gen8() : () -> !fir.complex<8> 89 // I32: call void @sink8(ptr % 90 // X64: call void @sink8(double %4, double %5) 91 // AARCH64: call void @sink8([2 x double] % 92 // PPC: call void @sink8(double %{{.*}}, double %{{.*}}) 93 fir.call @sink8(%1) : (!fir.complex<8>) -> () 94 return 95} 96 97// I32-LABEL: define i64 @char1lensum(ptr %0, ptr %1, i32 %2, i32 %3) 98// X64-LABEL: define i64 @char1lensum(ptr %0, ptr %1, i64 %2, i64 %3) 99// PPC-LABEL: define i64 @char1lensum(ptr %0, ptr %1, i64 %2, i64 %3) 100func.func @char1lensum(%arg0 : !fir.boxchar<1>, %arg1 : !fir.boxchar<1>) -> i64 { 101 // X64-DAG: %[[p0:.*]] = insertvalue { ptr, i64 } undef, ptr %1, 0 102 // X64-DAG: = insertvalue { ptr, i64 } %[[p0]], i64 %3, 1 103 // X64-DAG: %[[p1:.*]] = insertvalue { ptr, i64 } undef, ptr %0, 0 104 // X64-DAG: = insertvalue { ptr, i64 } %[[p1]], i64 %2, 1 105 %1:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i64) 106 %2:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i64) 107 // I32: %[[add:.*]] = add i64 % 108 // X64: %[[add:.*]] = add i64 % 109 %3 = arith.addi %1#1, %2#1 : i64 110 // I32: ret i64 %[[add]] 111 // X64: ret i64 %[[add]] 112 return %3 : i64 113} 114 115// I32-LABEL: define void @char1copy(ptr sret(i8) %0, i32 %1, ptr %2, i32 %3) 116// I64-LABEL: define void @char1copy(ptr sret(i8) %0, i64 %1, ptr %2, i64 %3) 117// PPC-LABEL: define void @char1copy(ptr sret(i8) %0, i64 %1, ptr %2, i64 %3) 118func.func @char1copy(%arg0 : !fir.boxchar<1> {llvm.sret}, %arg1 : !fir.boxchar<1>) { 119 // I32-DAG: %[[p0:.*]] = insertvalue { ptr, i32 } undef, ptr %2, 0 120 // I32-DAG: = insertvalue { ptr, i32 } %[[p0]], i32 %3, 1 121 // I32-DAG: %[[p1:.*]] = insertvalue { ptr, i32 } undef, ptr %0, 0 122 // I32-DAG: = insertvalue { ptr, i32 } %[[p1]], i32 %1, 1 123 // X64-DAG: %[[p0:.*]] = insertvalue { ptr, i64 } undef, ptr %2, 0 124 // X64-DAG: = insertvalue { ptr, i64 } %[[p0]], i64 %3, 1 125 // X64-DAG: %[[p1:.*]] = insertvalue { ptr, i64 } undef, ptr %0, 0 126 // X64-DAG: = insertvalue { ptr, i64 } %[[p1]], i64 %1, 1 127 %1:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.array<?x!fir.char<1>>>, i64) 128 %2:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref<!fir.array<?x!fir.char<1>>>, i64) 129 %c0 = arith.constant 0 : index 130 %c1 = arith.constant 1 : index 131 %3 = fir.convert %1#1 : (i64) -> index 132 %last = arith.subi %3, %c1 : index 133 fir.do_loop %i = %c0 to %last step %c1 { 134 %in_pos = fir.coordinate_of %2#0, %i : (!fir.ref<!fir.array<?x!fir.char<1>>>, index) -> !fir.ref<!fir.char<1>> 135 %out_pos = fir.coordinate_of %1#0, %i : (!fir.ref<!fir.array<?x!fir.char<1>>>, index) -> !fir.ref<!fir.char<1>> 136 %ch = fir.load %in_pos : !fir.ref<!fir.char<1>> 137 fir.store %ch to %out_pos : !fir.ref<!fir.char<1>> 138 } 139 // I32: ret void 140 // X64: ret void 141 return 142} 143