-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[X86][Clang] Add AVX512 Integer Comparison Intrinsics for constexpr Evaluation #164026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
dbcb924
fec68e4
ee703e0
3b6e186
c3cdc21
151e23b
e96b79b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3101,6 +3101,62 @@ static bool interp__builtin_vec_set(InterpState &S, CodePtr OpPC, | |||||
return true; | ||||||
} | ||||||
|
||||||
static bool interp__builtin_cmp_mask(InterpState &S, CodePtr OpPC, | ||||||
const CallExpr *Call, unsigned ID, | ||||||
bool IsUnsigned) { | ||||||
assert(Call->getNumArgs() == 4); | ||||||
|
||||||
APSInt Mask = popToAPSInt(S, Call->getArg(3)); | ||||||
APSInt Opcode = popToAPSInt(S, Call->getArg(2)); | ||||||
const Pointer &RHS = S.Stk.pop<Pointer>(); | ||||||
const Pointer &LHS = S.Stk.pop<Pointer>(); | ||||||
|
||||||
assert(LHS.getNumElems() == RHS.getNumElems()); | ||||||
|
||||||
APInt RetMask = APInt::getZero(LHS.getNumElems()); | ||||||
unsigned VectorLen = LHS.getNumElems(); | ||||||
PrimType ElemT = LHS.getFieldDesc()->getPrimType(); | ||||||
|
||||||
INT_TYPE_SWITCH_NO_BOOL(ElemT, { | ||||||
for (unsigned ElemNum = 0; ElemNum < VectorLen; ++ElemNum) { | ||||||
APSInt A = LHS.elem<T>(ElemNum).toAPSInt(); | ||||||
APSInt B = RHS.elem<T>(ElemNum).toAPSInt(); | ||||||
bool result = false; | ||||||
|
||||||
switch (Opcode.getExtValue() & 0x7) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of the code in the |
||||||
case 0x00: // _MM_CMPINT_EQ | ||||||
result = (A == B); | ||||||
break; | ||||||
case 0x01: // _MM_CMPINT_LT | ||||||
result = IsUnsigned ? A.ult(B) : A.slt(B); | ||||||
break; | ||||||
case 0x02: // _MM_CMPINT_LE | ||||||
result = IsUnsigned ? A.ule(B) : A.sle(B); | ||||||
break; | ||||||
case 0x03: // _MM_CMPINT_FALSE | ||||||
result = false; | ||||||
break; | ||||||
case 0x04: // _MM_CMPINT_NE | ||||||
result = (A != B); | ||||||
break; | ||||||
case 0x05: // _MM_CMPINT_NLT (>=) | ||||||
result = IsUnsigned ? A.uge(B) : A.sge(B); | ||||||
break; | ||||||
case 0x06: // _MM_CMPINT_NLE (>) | ||||||
result = IsUnsigned ? A.ugt(B) : A.sgt(B); | ||||||
break; | ||||||
case 0x07: // _MM_CMPINT_TRUE | ||||||
result = true; | ||||||
break; | ||||||
} | ||||||
|
||||||
RetMask.setBitVal(ElemNum, Mask[ElemNum] && result); | ||||||
} | ||||||
}); | ||||||
|
||||||
pushInteger(S, RetMask, Call->getType()); | ||||||
return true; | ||||||
} | ||||||
|
||||||
static bool interp__builtin_ia32_vpconflict(InterpState &S, CodePtr OpPC, | ||||||
const CallExpr *Call) { | ||||||
assert(Call->getNumArgs() == 1); | ||||||
|
@@ -4141,6 +4197,36 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, | |||||
case X86::BI__builtin_ia32_vec_set_v4di: | ||||||
return interp__builtin_vec_set(S, OpPC, Call, BuiltinID); | ||||||
|
||||||
case X86::BI__builtin_ia32_cmpb128_mask: | ||||||
case X86::BI__builtin_ia32_cmpw128_mask: | ||||||
case X86::BI__builtin_ia32_cmpd128_mask: | ||||||
case X86::BI__builtin_ia32_cmpq128_mask: | ||||||
case X86::BI__builtin_ia32_cmpb256_mask: | ||||||
case X86::BI__builtin_ia32_cmpw256_mask: | ||||||
case X86::BI__builtin_ia32_cmpd256_mask: | ||||||
case X86::BI__builtin_ia32_cmpq256_mask: | ||||||
case X86::BI__builtin_ia32_cmpb512_mask: | ||||||
case X86::BI__builtin_ia32_cmpw512_mask: | ||||||
case X86::BI__builtin_ia32_cmpd512_mask: | ||||||
case X86::BI__builtin_ia32_cmpq512_mask: | ||||||
return interp__builtin_cmp_mask(S, OpPC, Call, BuiltinID, | ||||||
/*IsUnsigned*/ false); | ||||||
|
/*IsUnsigned*/ false); | |
/*IsUnsigned=*/ false); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/*IsUnsigned*/ true); | |
/*IsUnsigned=*/ true); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15449,6 +15449,91 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, | |
unsigned Idx = static_cast<unsigned>(IdxAPS.getZExtValue() & (N - 1)); | ||
return Success(Vec.getVectorElt(Idx).getInt(), E); | ||
} | ||
|
||
case clang::X86::BI__builtin_ia32_cmpb128_mask: | ||
case clang::X86::BI__builtin_ia32_cmpw128_mask: | ||
case clang::X86::BI__builtin_ia32_cmpd128_mask: | ||
case clang::X86::BI__builtin_ia32_cmpq128_mask: | ||
case clang::X86::BI__builtin_ia32_cmpb256_mask: | ||
case clang::X86::BI__builtin_ia32_cmpw256_mask: | ||
case clang::X86::BI__builtin_ia32_cmpd256_mask: | ||
case clang::X86::BI__builtin_ia32_cmpq256_mask: | ||
case clang::X86::BI__builtin_ia32_cmpb512_mask: | ||
case clang::X86::BI__builtin_ia32_cmpw512_mask: | ||
case clang::X86::BI__builtin_ia32_cmpd512_mask: | ||
case clang::X86::BI__builtin_ia32_cmpq512_mask: | ||
case clang::X86::BI__builtin_ia32_ucmpb128_mask: | ||
case clang::X86::BI__builtin_ia32_ucmpw128_mask: | ||
case clang::X86::BI__builtin_ia32_ucmpd128_mask: | ||
case clang::X86::BI__builtin_ia32_ucmpq128_mask: | ||
case clang::X86::BI__builtin_ia32_ucmpb256_mask: | ||
case clang::X86::BI__builtin_ia32_ucmpw256_mask: | ||
case clang::X86::BI__builtin_ia32_ucmpd256_mask: | ||
case clang::X86::BI__builtin_ia32_ucmpq256_mask: | ||
case clang::X86::BI__builtin_ia32_ucmpb512_mask: | ||
case clang::X86::BI__builtin_ia32_ucmpw512_mask: | ||
case clang::X86::BI__builtin_ia32_ucmpd512_mask: | ||
case clang::X86::BI__builtin_ia32_ucmpq512_mask: { | ||
assert(E->getNumArgs() == 4); | ||
|
||
bool IsUnsigned = | ||
(BuiltinOp >= clang::X86::BI__builtin_ia32_ucmpb128_mask && | ||
BuiltinOp <= clang::X86::BI__builtin_ia32_ucmpq512_mask); | ||
|
||
APValue LHS, RHS; | ||
APSInt Mask, Opcode; | ||
if (!EvaluateVector(E->getArg(0), LHS, Info) || | ||
!EvaluateVector(E->getArg(1), RHS, Info) || | ||
!EvaluateInteger(E->getArg(2), Opcode, Info) || | ||
!EvaluateInteger(E->getArg(3), Mask, Info)) | ||
return false; | ||
|
||
assert(LHS.getVectorLength() == RHS.getVectorLength()); | ||
|
||
unsigned VectorLen = LHS.getVectorLength(); | ||
unsigned RetWidth = VectorLen ? VectorLen : 1; | ||
if (Mask.getBitWidth() > RetWidth) | ||
RetWidth = Mask.getBitWidth(); | ||
|
||
APSInt RetMask(llvm::APInt(RetWidth, 0), /*isUnsigned=*/true); | ||
for (unsigned ElemNum = 0; ElemNum < VectorLen; ++ElemNum) { | ||
APSInt A = LHS.getVectorElt(ElemNum).getInt(); | ||
APSInt B = RHS.getVectorElt(ElemNum).getInt(); | ||
|
||
bool result = false; | ||
|
||
switch (Opcode.getExtValue() & 0x7) { | ||
case 0: // _MM_CMPINT_EQ | ||
result = (A == B); | ||
break; | ||
case 1: // _MM_CMPINT_LT | ||
result = IsUnsigned ? A.ult(B) : A.slt(B); | ||
break; | ||
case 2: // _MM_CMPINT_LE | ||
result = IsUnsigned ? A.ule(B) : A.sle(B); | ||
break; | ||
case 3: // _MM_CMPINT_FALSE | ||
result = false; | ||
break; | ||
case 4: // _MM_CMPINT_NE | ||
result = (A != B); | ||
break; | ||
case 5: // _MM_CMPINT_NLT (>=) | ||
result = IsUnsigned ? A.uge(B) : A.sge(B); | ||
break; | ||
case 6: // _MM_CMPINT_NLE (>) | ||
result = IsUnsigned ? A.ugt(B) : A.sgt(B); | ||
break; | ||
case 7: // _MM_CMPINT_TRUE | ||
result = true; | ||
break; | ||
} | ||
|
||
RetMask.setBitVal(ElemNum, Mask[ElemNum] && result); | ||
} | ||
|
||
RetMask.setIsUnsigned(true); | ||
return Success(APValue(RetMask), E); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the type switch into the loop body and only do the
elem<>()
calls in the type switch body. The macro expands to a lot of code otherwise.