Skip to content

Commit 4fadd46

Browse files
committed
fix bugs revealed during testing
1 parent befd7fe commit 4fadd46

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -18703,13 +18703,13 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1870318703

1870418704
// if cond is a bool emit a select instruction
1870518705
if (TCond->isIntegerTy(1))
18706-
return Builder.CreateSelect(OpCond, OpTrue, OpFalse);
18706+
return Builder.CreateSelect(OpCond, OpTrue, OpFalse, "hlsl.select");
1870718707

1870818708
// if cond is a vector of bools lower to a shufflevector
1870918709
// todo check if that true and false are vectors
1871018710
// todo check that the size of true and false and cond are the same
1871118711
if (TCond->isVectorTy() &&
18712-
E->getArg(0)->getType()->getAs<VectorType>()->isBooleanType()) {
18712+
E->getArg(0)->getType()->getAs<VectorType>()->getElementType()->isBooleanType()) {
1871318713
assert(OpTrue->getType()->isVectorTy() && OpFalse->getType()->isVectorTy() &&
1871418714
"Select's second and third operands must be vectors if first operand is a vector.");
1871518715

@@ -18723,15 +18723,18 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1872318723
assert(N == VecTyFalse->getNumElements() &&
1872418724
N == E->getArg(0)->getType()->getAs<VectorType>()->getNumElements() &&
1872518725
"Select requires vectors to be of the same size.");
18726-
18727-
llvm::SmallVector<Value *> Mask;
18726+
18727+
llvm::Value *Result = llvm::PoisonValue::get(llvm::FixedVectorType::get(IntTy, N));
1872818728
for (unsigned I = 0; I < N; I++) {
1872918729
Value *Index = ConstantInt::get(IntTy, I);
1873018730
Value *IndexBool = Builder.CreateExtractElement(OpCond, Index);
18731-
Mask.push_back(Builder.CreateSelect(IndexBool, Index, ConstantInt::get(IntTy, I + N)));
18731+
Value *TVal = Builder.CreateExtractElement(OpTrue, Index);
18732+
Value *FVal = Builder.CreateExtractElement(OpFalse, Index);
18733+
Value *IndexSelect = Builder.CreateSelect(IndexBool, TVal, FVal);
18734+
Result = Builder.CreateInsertElement(Result, IndexSelect, Index);
1873218735
}
18733-
18734-
return Builder.CreateShuffleVector(OpTrue, OpFalse, BuildVector(Mask));
18736+
18737+
return Result;
1873518738
}
1873618739

1873718740
llvm_unreachable("Select requires a bool or vector of bools as its first operand.");

clang/lib/Headers/hlsl/hlsl_intrinsics.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1613,8 +1613,8 @@ double4 saturate(double4);
16131613
/// \param TrueVal The Value returned if Cond is true.
16141614
/// \param FalseVal The Value returned if Cond is false.
16151615

1616+
template <typename T>
16161617
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
1617-
template<typename T>
16181618
T select(bool, T, T);
16191619

16201620
/// \fn vector<T,Sz> select(vector<bool,Sz> Conds, vector<T,Sz> TrueVals, vector<T,Sz>, FalseVals)
@@ -1623,8 +1623,8 @@ T select(bool, T, T);
16231623
/// \param TrueVals The vector values are chosen from when conditions are true.
16241624
/// \param FalseVals The vector values are chosen from when conditions are false.
16251625

1626+
template <typename T, int Sz>
16261627
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
1627-
template<typename T, int Sz>
16281628
vector<T,Sz> select(vector<bool,Sz>, vector<T,Sz>, vector<T,Sz>);
16291629

16301630
//===----------------------------------------------------------------------===//

clang/lib/Sema/SemaHLSL.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
11201120
} else { // first operand is not a bool or a vector of bools.
11211121
SemaRef.Diag(TheCall->getArg(0)->getBeginLoc(),
11221122
diag::err_typecheck_convert_incompatible)
1123-
<< TheCall->getArg(0)->getType() << SemaRef.Context.getBOOLType()
1123+
<< TheCall->getArg(0)->getType() << getASTContext().BoolTy
11241124
<< 1 << 0 << 0;
11251125
SemaRef.Diag(TheCall->getArg(0)->getBeginLoc(),
11261126
diag::err_builtin_non_vector_type)

0 commit comments

Comments
 (0)