|
| 1 | +; RUN: llvm-as %s -o %t.bc |
| 2 | +; RUN: llvm-spirv %t.bc -spirv-text |
| 3 | +; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV |
| 4 | +; RUN: llvm-spirv %t.bc -o %t.spv |
| 5 | +; RUN: llvm-spirv -r %t.spv -o %t.rev.bc |
| 6 | +; RUN: llvm-dis %t.rev.bc |
| 7 | +; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM |
| 8 | + |
| 9 | +target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" |
| 10 | +target triple = "spir64-unknown-unknown" |
| 11 | + |
| 12 | +; CHECK-SPIRV: ExtInstImport [[#ExtInstSetId:]] "OpenCL.std" |
| 13 | + |
| 14 | +; CHECK-SPIRV: TypeInt [[#TypeInt:]] 32 |
| 15 | +; CHECK-SPIRV: TypeFloat [[#TypeFloat:]] 32 |
| 16 | +; CHECK-SPIRV: TypeStruct [[#TypeStrFloatInt:]] [[#TypeFloat]] [[#TypeInt]] |
| 17 | +; CHECK-SPIRV: TypePointer [[#TypeIntPtr:]] 7 [[#TypeInt]] |
| 18 | + |
| 19 | +; CHECK-SPIRV: TypeFloat [[#TypeDouble:]] 64 |
| 20 | +; CHECK-SPIRV: TypeStruct [[#TypeStrDoubleInt:]] [[#TypeDouble]] [[#TypeInt]] |
| 21 | + |
| 22 | +; CHECK-SPIRV: TypeVector [[#VecFloat2:]] [[#TypeFloat]] 2 |
| 23 | +; CHECK-SPIRV: TypeVector [[#VecInt2:]] [[#TypeInt]] 2 |
| 24 | +; CHECK-SPIRV: TypeStruct [[#TypeStrFloatIntVec2:]] [[#VecFloat2]] [[#VecInt2]] |
| 25 | + |
| 26 | +; CHECK-SPIRV: TypeVector [[#VecFloat4:]] [[#TypeFloat]] 4 |
| 27 | +; CHECK-SPIRV: TypeVector [[#VecInt4:]] [[#TypeInt]] 4 |
| 28 | +; CHECK-SPIRV: TypeStruct [[#TypeStrFloatIntVec4:]] [[#VecFloat4]] [[#VecInt4]] |
| 29 | + |
| 30 | +; CHECK-SPIRV: TypeVector [[#VecDouble2:]] [[#TypeDouble]] 2 |
| 31 | +; CHECK-SPIRV: TypeStruct [[#TypeStrDoubleIntVec2:]] [[#VecDouble2]] [[#VecInt2]] |
| 32 | + |
| 33 | +; CHECK-SPIRV: Constant [[#TypeFloat]] [[#NegatedZeroConst:]] 2147483648 |
| 34 | +; CHECK-SPIRV: Undef [[#TypeDouble]] [[#UndefDouble:]] |
| 35 | +; CHECK-SPIRV: ConstantNull [[#VecFloat2]] [[#NullVecFloat2:]] |
| 36 | +; CHECK-SPIRV: Constant [[#TypeFloat]] [[#ZeroConstFloat:]] 0 |
| 37 | +; CHECK-SPIRV: ConstantComposite [[#VecFloat2]] [[#ZeroesCompositeFloat:]] [[#ZeroConstFloat]] [[#NegatedZeroConst]] |
| 38 | + |
| 39 | +; CHECK-LLVM: %[[StrTypeFloatInt:[a-z0-9.]+]] = type { float, i32 } |
| 40 | +; CHECK-LLVM: %[[StrTypeDoubleInt:[a-z0-9.]+]] = type { double, i32 } |
| 41 | +; CHECK-LLVM: %[[StrTypeFloatIntVec2:[a-z0-9.]+]] = type { <2 x float>, <2 x i32> } |
| 42 | +; CHECK-LLVM: %[[StrTypeFloatIntVec4:[a-z0-9.]+]] = type { <4 x float>, <4 x i32> } |
| 43 | +; CHECK-LLVM: %[[StrTypeDoubleIntVec2:[a-z0-9.]+]] = type { <2 x double>, <2 x i32> } |
| 44 | + |
| 45 | +declare { float, i32 } @llvm.frexp.f32.i32(float) |
| 46 | +declare { double, i32 } @llvm.frexp.f64.i32(double) |
| 47 | +declare { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float>) |
| 48 | +declare { <4 x float>, <4 x i32> } @llvm.frexp.v4f32.v4i32(<4 x float>) |
| 49 | +declare { <2 x double>, <2 x i32> } @llvm.frexp.v2f64.v2i32(<2 x double>) |
| 50 | + |
| 51 | +; CHECK-SPIRV: Function [[#TypeStrFloatInt:]] |
| 52 | +; CHECK-SPIRV: Variable [[#TypeIntPtr]] [[#IntVar:]] 7 |
| 53 | +; CHECK-SPIRV: ExtInst [[#TypeFloat]] [[#FrexpId:]] [[#ExtInstSetId]] frexp [[#NegatedZeroConst]] [[#IntVar]] |
| 54 | +; CHECK-SPIRV: Load [[#]] [[#LoadId:]] [[#]] |
| 55 | +; CHECK-SPIRV: CompositeConstruct [[#TypeStrFloatInt]] [[#ComposConstr:]] [[#FrexpId]] [[#LoadId]] |
| 56 | +; CHECK-SPIRV: ReturnValue [[#ComposConstr]] |
| 57 | + |
| 58 | +; CHECK-LLVM: %[[#IntVar:]] = alloca i32 |
| 59 | +; CHECK-LLVM: %[[Frexp:[a-z0-9]+]] = call spir_func float @_Z5frexpfPi(float -0.000000e+00, ptr %[[#IntVar]]) |
| 60 | +; CHECK-LLVM: %[[#LoadIntVar:]] = load i32, ptr %[[#IntVar]] |
| 61 | +; CHECK-LLVM: %[[#AllocaStrFloatInt:]] = alloca %[[StrTypeFloatInt]] |
| 62 | +; CHECK-LLVM: %[[GEPFloat:[a-z0-9]+]] = getelementptr inbounds %structtype, ptr %[[#AllocaStrFloatInt]], i32 0, i32 0 |
| 63 | +; CHECK-LLVM: store float %[[Frexp]], ptr %[[GEPFloat]] |
| 64 | +; CHECK-LLVM: %[[GEPInt:[a-z0-9]+]] = getelementptr inbounds %structtype, ptr %[[#AllocaStrFloatInt]], i32 0, i32 1 |
| 65 | +; CHECK-LLVM: store i32 %[[#LoadIntVar]], ptr %[[GEPInt]] |
| 66 | +; CHECK-LLVM: %[[LoadStrFloatInt:[a-z0-9]+]] = load %[[StrTypeFloatInt]], ptr %[[#AllocaStrFloatInt]] |
| 67 | +; CHECK-LLVM: ret %[[StrTypeFloatInt]] %[[LoadStrFloatInt]] |
| 68 | +define { float, i32 } @frexp_negzero() { |
| 69 | + %ret = call { float, i32 } @llvm.frexp.f32.i32(float -0.0) |
| 70 | + ret { float, i32 } %ret |
| 71 | +} |
| 72 | + |
| 73 | +; CHECK-SPIRV: ExtInst [[#TypeDouble]] [[#]] [[#ExtInstSetId]] frexp [[#UndefDouble]] [[#]] |
| 74 | +; CHECK-LLVM: call spir_func double @_Z5frexpdPi(double undef, ptr %[[#]]) |
| 75 | +; CHECK-LLVM: ret %[[StrTypeDoubleInt]] |
| 76 | +define { double, i32 } @frexp_undef() { |
| 77 | + %ret = call { double, i32 } @llvm.frexp.f64.i32(double undef) |
| 78 | + ret { double, i32 } %ret |
| 79 | +} |
| 80 | + |
| 81 | +; CHECK-SPIRV: ExtInst [[#VecFloat2]] [[#]] [[#ExtInstSetId]] frexp [[#NullVecFloat2]] [[#]] |
| 82 | +; CHECK-LLVM: call spir_func <2 x float> @_Z5frexpDv2_fPDv2_i(<2 x float> zeroinitializer, ptr %[[#]]) |
| 83 | +; CHECK-LLVM: ret %[[StrTypeFloatIntVec2]] |
| 84 | +define { <2 x float>, <2 x i32> } @frexp_zero_vector() { |
| 85 | + %ret = call { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float> zeroinitializer) |
| 86 | + ret { <2 x float>, <2 x i32> } %ret |
| 87 | +} |
| 88 | + |
| 89 | +; CHECK-SPIRV: ExtInst [[#VecFloat2]] [[#]] [[#ExtInstSetId]] frexp [[#ZeroesCompositeFloat]] [[#]] |
| 90 | +; CHECK-LLVM: call spir_func <2 x float> @_Z5frexpDv2_fPDv2_i(<2 x float> <float 0.000000e+00, float -0.000000e+00>, ptr %[[#]]) |
| 91 | +; CHECK-LLVM: ret %[[StrTypeFloatIntVec2]] |
| 92 | +define { <2 x float>, <2 x i32> } @frexp_zero_negzero_vector() { |
| 93 | + %ret = call { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float> <float 0.0, float -0.0>) |
| 94 | + ret { <2 x float>, <2 x i32> } %ret |
| 95 | +} |
| 96 | + |
| 97 | +; CHECK-SPIRV: ExtInst [[#VecFloat4]] [[#]] [[#ExtInstSetId]] frexp [[#]] [[#]] |
| 98 | +; CHECK-LLVM: call spir_func <4 x float> @_Z5frexpDv4_fPDv4_i(<4 x float> <float 1.600000e+01, float -3.200000e+01, float undef, float 9.999000e+03>, ptr %[[#]]) |
| 99 | +; CHECK-LLVM: ret %[[StrTypeFloatIntVec4]] |
| 100 | +define { <4 x float>, <4 x i32> } @frexp_nonsplat_vector() { |
| 101 | + %ret = call { <4 x float>, <4 x i32> } @llvm.frexp.v4f32.v4i32(<4 x float> <float 16.0, float -32.0, float undef, float 9999.0>) |
| 102 | + ret { <4 x float>, <4 x i32> } %ret |
| 103 | +} |
| 104 | + |
| 105 | +; CHECK-SPIRV: ExtInst [[#TypeFloat]] [[#]] [[#ExtInstSetId]] frexp [[#]] [[#]] |
| 106 | +; CHECK-SPIRV: ExtInst [[#TypeFloat]] [[#]] [[#ExtInstSetId]] frexp [[#]] [[#]] |
| 107 | +; CHECK-LLVM: %[[#IntVar1:]] = alloca i32 |
| 108 | +; CHECK-LLVM: %[[Frexp0:[a-z0-9.]+]] = call spir_func float @_Z5frexpfPi(float %x, ptr %[[#IntVar1]]) |
| 109 | +; CHECK-LLVM: %[[#IntVar2:]] = alloca i32 |
| 110 | +; CHECK-LLVM: %[[Frexp1:[a-z0-9.]+]] = call spir_func float @_Z5frexpfPi(float %[[Frexp0]], ptr %[[#IntVar2]]) |
| 111 | +; CHECK-LLVM: %[[#LoadIntVar:]] = load i32, ptr %[[#IntVar2]] |
| 112 | +; CHECK-LLVM: %[[#AllocaStrFloatInt:]] = alloca %[[StrTypeFloatInt]] |
| 113 | +; CHECK-LLVM: %[[GEPFloat:[a-z0-9]+]] = getelementptr inbounds %structtype, ptr %[[#AllocaStrFloatInt]], i32 0, i32 0 |
| 114 | +; CHECK-LLVM: store float %[[Frexp1]], ptr %[[GEPFloat]] |
| 115 | +; CHECK-LLVM: %[[GEPInt:[a-z0-9]+]] = getelementptr inbounds %structtype, ptr %[[#AllocaStrFloatInt]], i32 0, i32 1 |
| 116 | +; CHECK-LLVM: store i32 %[[#LoadIntVar]], ptr %[[GEPInt]] |
| 117 | +; CHECK-LLVM: %[[LoadStrFloatInt:[a-z0-9]+]] = load %[[StrTypeFloatInt]], ptr %[[#AllocaStrFloatInt]] |
| 118 | +; CHECK-LLVM: ret %[[StrTypeFloatInt]] %[[LoadStrFloatInt]] |
| 119 | +define { float, i32 } @frexp_frexp(float %x) { |
| 120 | + %frexp0 = call { float, i32 } @llvm.frexp.f32.i32(float %x) |
| 121 | + %frexp0.0 = extractvalue { float, i32 } %frexp0, 0 |
| 122 | + %frexp1 = call { float, i32 } @llvm.frexp.f32.i32(float %frexp0.0) |
| 123 | + ret { float, i32 } %frexp1 |
| 124 | +} |
| 125 | + |
| 126 | +; CHECK-SPIRV: ExtInst [[#VecDouble2]] [[#]] [[#ExtInstSetId]] frexp [[#]] [[#]] |
| 127 | +; CHECK-SPIRV: ExtInst [[#VecDouble2]] [[#]] [[#ExtInstSetId]] frexp [[#]] [[#]] |
| 128 | +; CHECK-LLVM: %[[Frexp0:[a-z0-9.]+]] = call spir_func <2 x double> @_Z5frexpDv2_dPDv2_i(<2 x double> %x, ptr %[[#]]) |
| 129 | +; CHECK-LLVM: call spir_func <2 x double> @_Z5frexpDv2_dPDv2_i(<2 x double> %[[Frexp0]], ptr %[[#]]) |
| 130 | +; CHECK-LLVM: ret %[[StrTypeDoubleIntVec2]] |
| 131 | +define { <2 x double>, <2 x i32> } @frexp_frexp_vector(<2 x double> %x) { |
| 132 | + %frexp0 = call { <2 x double>, <2 x i32> } @llvm.frexp.v2f64.v2i32(<2 x double> %x) |
| 133 | + %frexp0.0 = extractvalue { <2 x double>, <2 x i32> } %frexp0, 0 |
| 134 | + %frexp1 = call { <2 x double>, <2 x i32> } @llvm.frexp.v2f64.v2i32(<2 x double> %frexp0.0) |
| 135 | + ret { <2 x double>, <2 x i32> } %frexp1 |
| 136 | +} |
| 137 | + |
| 138 | +; CHECK-SPIRV: ExtInst [[#TypeFloat]] [[#]] [[#ExtInstSetId]] frexp [[#]] [[#]] |
| 139 | +; CHECK-LLVM: %[[#IntVar:]] = alloca i32 |
| 140 | +; CHECK-LLVM: %[[Frexp:[a-z0-9.]+]] = call spir_func float @_Z5frexpfPi(float %x, ptr %[[#IntVar]]) |
| 141 | +; CHECK-LLVM: %[[LoadVar:[a-z0-9.]+]] = load i32, ptr %[[#IntVar]] |
| 142 | +; CHECK-LLVM: ret i32 %[[LoadVar]] |
| 143 | +define i32 @frexp_frexp_get_int(float %x) { |
| 144 | + %frexp0 = call { float, i32 } @llvm.frexp.f32.i32(float %x) |
| 145 | + %frexp0.0 = extractvalue { float, i32 } %frexp0, 1 |
| 146 | + ret i32 %frexp0.0 |
| 147 | +} |
0 commit comments