Skip to content

Commit dd51a30

Browse files
V-FEXrtfschlimb
authored andcommitted
[HLSL] Use ExtVector for firstbit intrinsics (llvm#142679)
Fixes llvm#142430 firstbit intrinsics were using the wrong vector type which causes some conversions to fail. This PR switches them to ExtVector which resolves the issue
1 parent 576806a commit dd51a30

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,8 +2231,9 @@ static void SetElementTypeAsReturnType(Sema *S, CallExpr *TheCall,
22312231
QualType ReturnType) {
22322232
auto *VecTyA = TheCall->getArg(0)->getType()->getAs<VectorType>();
22332233
if (VecTyA)
2234-
ReturnType = S->Context.getVectorType(ReturnType, VecTyA->getNumElements(),
2235-
VectorKind::Generic);
2234+
ReturnType =
2235+
S->Context.getExtVectorType(ReturnType, VecTyA->getNumElements());
2236+
22362237
TheCall->setType(ReturnType);
22372238
}
22382239

@@ -2545,8 +2546,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
25452546

25462547
if (auto *VecTy = EltTy->getAs<VectorType>()) {
25472548
EltTy = VecTy->getElementType();
2548-
ResTy = SemaRef.Context.getVectorType(ResTy, VecTy->getNumElements(),
2549-
VecTy->getVectorKind());
2549+
ResTy = SemaRef.Context.getExtVectorType(ResTy, VecTy->getNumElements());
25502550
}
25512551

25522552
if (!EltTy->isIntegerType()) {

clang/test/CodeGenHLSL/builtins/firstbithigh.hlsl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,11 @@ uint3 test_firstbithigh_long3(int64_t3 p0) {
151151
uint4 test_firstbithigh_long4(int64_t4 p0) {
152152
return firstbithigh(p0);
153153
}
154+
155+
// CHECK-LABEL: test_firstbithigh_upcast
156+
// CHECK: [[FBH:%.*]] = call <4 x i32> @llvm.[[TARGET]].firstbituhigh.v4i32(<4 x i32> %{{.*}})
157+
// CHECK: [[CONV:%.*]] = zext <4 x i32> [[FBH]] to <4 x i64>
158+
// CHECK: ret <4 x i64> [[CONV]]
159+
uint64_t4 test_firstbithigh_upcast(uint4 p0) {
160+
return firstbithigh(p0);
161+
}

clang/test/CodeGenHLSL/builtins/firstbitlow.hlsl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,11 @@ uint3 test_firstbitlow_long3(int64_t3 p0) {
151151
uint4 test_firstbitlow_long4(int64_t4 p0) {
152152
return firstbitlow(p0);
153153
}
154+
155+
// CHECK-LABEL: test_firstbitlow_upcast
156+
// CHECK: [[FBL:%.*]] = call <4 x i32> @llvm.[[TARGET]].firstbitlow.v4i32(<4 x i32> %{{.*}})
157+
// CHECK: [[CONV:%.*]] = zext <4 x i32> [[FBL]] to <4 x i64>
158+
// CHECK: ret <4 x i64> [[CONV]]
159+
uint64_t4 test_firstbitlow_upcast(uint4 p0) {
160+
return firstbitlow(p0);
161+
}

0 commit comments

Comments
 (0)