Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/BuiltinsX86.td
Original file line number Diff line number Diff line change
Expand Up @@ -4104,7 +4104,7 @@ let Features = "avx512bf16", Attributes = [NoThrow, Const, RequiredVectorWidth<1
def selectsbf_128 : X86Builtin<"_Vector<8, __bf16>(unsigned char, _Vector<8, __bf16>, _Vector<8, __bf16>)">;
}

let Features = "avx512f", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in {
let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<128>] in {
def selectss_128 : X86Builtin<"_Vector<4, float>(unsigned char, _Vector<4, float>, _Vector<4, float>)">;
def selectsd_128 : X86Builtin<"_Vector<2, double>(unsigned char, _Vector<2, double>, _Vector<2, double>)">;
}
Expand Down
21 changes: 21 additions & 0 deletions clang/lib/AST/ByteCode/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3598,6 +3598,27 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
return APInt::getAllOnes(DstBits);
});

case clang::X86::BI__builtin_ia32_selectss_128:
case clang::X86::BI__builtin_ia32_selectsd_128: {
const unsigned N =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const unsigned N =
unsigned N =

Call->getArg(1)->getType()->getAs<VectorType>()->getNumElements();

const Pointer &W = S.Stk.pop<Pointer>();
const Pointer &A = S.Stk.pop<Pointer>();
APSInt U = popToAPSInt(S, Call->getArg(0));
const Pointer &Dst = S.Stk.peek<Pointer>();

const bool TakeA0 = U.getZExtValue() & 1ULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const bool TakeA0 = U.getZExtValue() & 1ULL;
bool TakeA0 = U.getZExtValue() & 1ULL;


for (unsigned i = 0; i < N; ++i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (unsigned i = 0; i < N; ++i)
for (unsigned I = 0; I != N; ++I)

Dst.elem<Floating>(i) = W.elem<Floating>(i);
if (TakeA0)
Dst.elem<Floating>(0) = A.elem<Floating>(0);

Dst.initializeAllElements();
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a function for this.


case clang::X86::BI__builtin_ia32_vprotbi:
case clang::X86::BI__builtin_ia32_vprotdi:
case clang::X86::BI__builtin_ia32_vprotqi:
Expand Down
27 changes: 27 additions & 0 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11705,6 +11705,23 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
return Success(APValue(ResultElements.data(), SourceLen), E);
};

auto EvalSelectScalar = [&](unsigned Len) -> std::optional<APValue> {
APSInt Mask;
APValue AVal, WVal;
if (!EvaluateInteger(E->getArg(0), Mask, Info) ||
!EvaluateAsRValue(Info, E->getArg(1), AVal) ||
!EvaluateAsRValue(Info, E->getArg(2), WVal))
return std::nullopt;

const bool TakeA0 = (Mask.getZExtValue() & 1u) != 0;
SmallVector<APValue, 4> Res;
Res.reserve(Len);
Res.push_back(TakeA0 ? AVal.getVectorElt(0) : WVal.getVectorElt(0));
for (unsigned i = 1; i < Len; ++i)
Res.push_back(WVal.getVectorElt(i));
return APValue(Res.data(), Res.size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just return Success / false?

};

switch (E->getBuiltinCallee()) {
default:
return false;
Expand Down Expand Up @@ -11933,6 +11950,16 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
return APInt((Src).trunc(DstBits));
return APInt::getAllOnes(DstBits);
});
case clang::X86::BI__builtin_ia32_selectss_128: {
if (auto V = EvalSelectScalar(4))
return Success(*V, E);
return false;
}
case clang::X86::BI__builtin_ia32_selectsd_128: {
if (auto V = EvalSelectScalar(2))
return Success(*V, E);
return false;
}
case clang::X86::BI__builtin_ia32_pmuldq128:
case clang::X86::BI__builtin_ia32_pmuldq256:
case clang::X86::BI__builtin_ia32_pmuldq512:
Expand Down
Loading