Skip to content

Commit 1853e3d

Browse files
committed
fix tests
1 parent 83c4f5a commit 1853e3d

File tree

7 files changed

+57
-75
lines changed

7 files changed

+57
-75
lines changed

clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,6 @@ constexpr vector<T, L> refract_vec_impl(vector<T, L> I, vector<T, L> N, T eta) {
9292
#endif
9393
}
9494

95-
/*
96-
template <typename T, typename U> constexpr T refract_impl(T I, T N, U eta) {
97-
return I - 2 * N * I * N;
98-
}
99-
100-
template <typename T, int L>
101-
constexpr vector<T, L> refract_vec_impl(vector<T, L> I, vector<T, L> N) {
102-
#if (__has_builtin(__builtin_spirv_refract))
103-
return __builtin_spirv_refract(I, N);
104-
#else
105-
return I - 2 * N * dot(I, N);
106-
#endif
107-
}
108-
*/
109-
11095
template <typename T> constexpr T fmod_impl(T X, T Y) {
11196
#if !defined(__DIRECTX__)
11297
return __builtin_elementwise_fmod(X, Y);

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -423,24 +423,6 @@ const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
423423
return __detail::refract_impl(I, N, eta);
424424
}
425425

426-
/*
427-
template <typename T, typename U>
428-
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
429-
const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
430-
__detail::is_same<half, T>::value,
431-
T> refract(T I, T N, U eta) {
432-
return __detail::refract_impl(I, N, eta);
433-
}
434-
435-
template <typename T, typename U>
436-
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
437-
const inline __detail::enable_if_t<__detail::is_arithmetic<U>::Value &&
438-
__detail::is_same<half, T>::value,
439-
T> refract(T I, T N, U eta) {
440-
return __detail::refract_impl(I, N, eta);
441-
}
442-
*/
443-
444426
template <typename T>
445427
const inline __detail::enable_if_t<
446428
__detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>

clang/lib/Sema/SemaSPIRV.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(unsigned BuiltinID,
110110
QualType RetTy = ArgTyA;
111111
TheCall->setType(RetTy);
112112
assert(RetTy == ArgTyA);
113-
//assert(ArgTyB == ArgTyA);
114113
break;
115114
}
116115
case SPIRV::BI__builtin_spirv_reflect: {

clang/test/CodeGenSPIRV/Builtins/refract.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,29 @@ typedef float float3 __attribute__((ext_vector_type(3)));
77
typedef float float4 __attribute__((ext_vector_type(4)));
88

99
// CHECK-LABEL: define spir_func <2 x float> @test_refract_float2(
10-
// CHECK-SAME: <2 x float> noundef [[X:%.*]], <2 x float> noundef [[Y:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
10+
// CHECK-SAME: <2 x float> noundef [[I:%.*]], <2 x float> noundef [[N:%.*]], float noundef [[ETA:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
1111
// CHECK-NEXT: [[ENTRY:.*:]]
12-
// CHECK-NEXT: [[SPV_REFRACT:%.*]] = tail call <2 x float> @llvm.spv.refract.v2f32(<2 x float> [[X]], <2 x float> [[Y]])
12+
// CHECK-NEXT: [[CONV:%.*]] = fpext float [[ETA]] to double
13+
// CHECK: [[SPV_REFRACT:%.*]] = tail call <2 x float> @llvm.spv.refract.v2f32.f64(<2 x float> [[I]], <2 x float> [[N]], double [[CONV]])
1314
// CHECK-NEXT: ret <2 x float> [[SPV_REFRACT]]
1415
//
15-
float2 test_refract_float2(float2 X, float2 Y, float eta) { return __builtin_spirv_refract(X, Y, eta); }
16+
float2 test_refract_float2(float2 I, float2 N, float eta) { return __builtin_spirv_refract(I, N, eta); }
1617

1718
// CHECK-LABEL: define spir_func <3 x float> @test_refract_float3(
18-
// CHECK-SAME: <3 x float> noundef [[X:%.*]], <3 x float> noundef [[Y:%.*]]) local_unnamed_addr #[[ATTR0]] {
19+
// CHECK-SAME: <3 x float> noundef [[I:%.*]], <3 x float> noundef [[N:%.*]], float noundef [[ETA:%.*]]) local_unnamed_addr #[[ATTR0]] {
1920
// CHECK-NEXT: [[ENTRY:.*:]]
20-
// CHECK-NEXT: [[SPV_REFRACT:%.*]] = tail call <3 x float> @llvm.spv.refract.v3f32(<3 x float> [[X]], <3 x float> [[Y]])
21+
// CHECK-NEXT: [[CONV:%.*]] = fpext float [[ETA]] to double
22+
// CHECK-NEXT: [[SPV_REFRACT:%.*]] = tail call <3 x float> @llvm.spv.refract.v3f32.f64(<3 x float> [[I]], <3 x float> [[N]], double [[CONV]])
2123
// CHECK-NEXT: ret <3 x float> [[SPV_REFRACT]]
2224
//
23-
float3 test_refract_float3(float3 X, float3 Y, float eta) { return __builtin_spirv_refract(X, Y, eta); }
25+
float3 test_refract_float3(float3 I, float3 N, float eta) { return __builtin_spirv_refract(I, N, eta); }
2426

2527
// CHECK-LABEL: define spir_func <4 x float> @test_refract_float4(
26-
// CHECK-SAME: <4 x float> noundef [[X:%.*]], <4 x float> noundef [[Y:%.*]]) local_unnamed_addr #[[ATTR0]] {
28+
// CHECK-SAME: <4 x float> noundef [[I:%.*]], <4 x float> noundef [[N:%.*]], float noundef [[ETA:%.*]]) local_unnamed_addr #[[ATTR0]] {
2729
// CHECK-NEXT: [[ENTRY:.*:]]
28-
// CHECK-NEXT: [[SPV_REFRACT:%.*]] = tail call <4 x float> @llvm.spv.refract.v4f32(<4 x float> [[X]], <4 x float> [[Y]])
30+
// CHECK-NEXT: [[CONV:%.*]] = fpext float [[ETA]] to double
31+
// CHECK-NEXT: [[SPV_REFRACT:%.*]] = tail call <4 x float> @llvm.spv.refract.v4f32.f64(<4 x float> [[I]], <4 x float> [[N]], double [[CONV]])
2932
// CHECK-NEXT: ret <4 x float> [[SPV_REFRACT]]
3033
//
31-
float4 test_refract_float4(float4 X, float4 Y, float eta) { return __builtin_spirv_refract(X, Y, eta); }
34+
float4 test_refract_float4(float4 I, float4 N, float eta) { return __builtin_spirv_refract(I, N, eta); }
3235

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang_cc1 %s -triple spirv-pc-vulkan-compute -verify
2+
3+
typedef float float2 __attribute__((ext_vector_type(2)));
4+
5+
float2 test_no_second_arg(float2 p0) {
6+
return __builtin_spirv_refract(p0);
7+
// expected-error@-1 {{too few arguments to function call, expected 3, have 1}}
8+
}
9+
10+
float2 test_too_few_arg(float2 p0) {
11+
return __builtin_spirv_refract(p0, p0);
12+
// expected-error@-1 {{too few arguments to function call, expected 3, have 2}}
13+
}
14+
15+
float2 test_too_many_arg(float2 p0, float p1) {
16+
return __builtin_spirv_refract(p0, p0, p1, p1);
17+
// expected-error@-1 {{too many arguments to function call, expected 3, have 4}}
18+
}
19+
20+
float test_double_scalar_inputs(double p0, double p1, double p2) {
21+
return __builtin_spirv_refract(p0, p1, p2);
22+
// expected-error@-1 {{passing 'double' to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(double)))) double' (vector of 2 'double' values)}}
23+
}
24+
25+
float test_int_scalar_inputs(int p0, int p1, int p2) {
26+
return __builtin_spirv_refract(p0, p1, p2);
27+
// expected-error@-1 {{passing 'int' to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(int)))) int' (vector of 2 'int' values)}}
28+
}

llvm/lib/IR/IRBuilder.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -953,27 +953,8 @@ CallInst *IRBuilderBase::CreateIntrinsic(Type *RetTy, Intrinsic::ID ID,
953953

954954
SmallVector<Type *> ArgTys;
955955
ArgTys.reserve(Args.size());
956-
int i =0;
957-
Type * Ity;
958-
Type * Nty;
959-
Type * etaty;
960-
961-
for (auto &I : Args) {
962-
if(i ==0)
963-
Ity = I->getType();
964-
if(i ==1)
965-
Nty = I->getType();
966-
if(i ==2)
967-
etaty = I->getType();
956+
for (auto &I : Args)
968957
ArgTys.push_back(I->getType());
969-
i++;
970-
}
971-
//assert(Ity == RetTy);
972-
//assert(Nty == RetTy);
973-
assert(Nty == Ity);
974-
975-
976-
977958
FunctionType *FTy = FunctionType::get(RetTy, ArgTys, false);
978959
SmallVector<Type *> OverloadTys;
979960
Intrinsic::MatchIntrinsicTypesResult Res =

llvm/test/CodeGen/SPIRV/hlsl-intrinsics/refract.ll

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,31 @@
77
; CHECK-DAG: %[[#float_16:]] = OpTypeFloat 16
88
; CHECK-DAG: %[[#vec4_float_16:]] = OpTypeVector %[[#float_16]] 4
99
; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32
10+
; CHECK-DAG: %[[#float_64:]] = OpTypeFloat 64
1011
; CHECK-DAG: %[[#vec4_float_32:]] = OpTypeVector %[[#float_32]] 4
1112

12-
define noundef <4 x half> @refract_half4(<4 x half> noundef %a, <4 x half> noundef %b, half %eta) {
13+
define noundef <4 x half> @refract_half(<4 x half> noundef %I, <4 x half> noundef %N, half noundef %ETA) {
1314
entry:
1415
; CHECK: %[[#]] = OpFunction %[[#vec4_float_16]] None %[[#]]
1516
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_16]]
1617
; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec4_float_16]]
17-
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_16]] %[[#op_ext_glsl]] refract %[[#arg0]] %[[#arg1]]
18-
%spv.refract = call <4 x half> @llvm.spv.refract.f16(<4 x half> %a, <4 x half> %b)
19-
ret <4 x half> %spv.refract
18+
; CHECK: %[[#arg2_float_16:]] = OpFunctionParameter %[[#float_16:]]
19+
; CHECK: %[[#arg2:]] = OpFConvert %[[#float_64:]] %[[#arg2_float_16:]]
20+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_16]] %[[#op_ext_glsl]] Refract %[[#arg0]] %[[#arg1]] %[[#arg2]]
21+
%conv.i = fpext reassoc nnan ninf nsz arcp afn half %ETA to double
22+
%spv.refract.i = tail call reassoc nnan ninf nsz arcp afn noundef <4 x half> @llvm.spv.refract.v4f16.f64(<4 x half> %I, <4 x half> %N, double %conv.i)
23+
ret <4 x half> %spv.refract.i
2024
}
2125

22-
define noundef <4 x float> @refract_float4(<4 x float> noundef %a, <4 x float> noundef %b, float %eta) {
26+
define noundef <4 x float> @refract_float4(<4 x float> noundef %I, <4 x float> noundef %N, float noundef %ETA) {
2327
entry:
28+
%conv.i = fpext reassoc nnan ninf nsz arcp afn float %ETA to double
2429
; CHECK: %[[#]] = OpFunction %[[#vec4_float_32]] None %[[#]]
2530
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_32]]
2631
; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec4_float_32]]
27-
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] refract %[[#arg0]] %[[#arg1]]
28-
%spv.refract = call <4 x float> @llvm.spv.refract.f32(<4 x float> %a, <4 x float> %b)
29-
ret <4 x float> %spv.refract
30-
}
31-
32-
declare <4 x half> @llvm.spv.refract.f16(<4 x half>, <4 x half>, half)
33-
declare <4 x float> @llvm.spv.refract.f32(<4 x float>, <4 x float>, float)
32+
; CHECK: %[[#arg2_float_32:]] = OpFunctionParameter %[[#float_32:]]
33+
; CHECK: %[[#arg2:]] = OpFConvert %[[#float_64:]] %[[#arg2_float_32:]]
34+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] Refract %[[#arg0]] %[[#arg1]] %[[#arg2]]
35+
%spv.refract.i = tail call reassoc nnan ninf nsz arcp afn noundef <4 x float> @llvm.spv.refract.v4f32.f64(<4 x float> %I, <4 x float> %N, double %conv.i)
36+
ret <4 x float> %spv.refract.i
37+
}

0 commit comments

Comments
 (0)