Skip to content

Commit e0b78c2

Browse files
RKSimonclingfei
authored andcommitted
[clang][bytecode][x86] Merge interp__builtin_ia32_pmul/interp__builtin_ia32_pmadd implementations (llvm#162504)
The interp__builtin_ia32_pmadd implementation can be correctly used for PMULDQ/PMULUDQ evaluation as well as we're ignoring the "hi" integers in each pair I've replaced the PMULDQ/PMULUDQ evaluation with callbacks and renamed interp__builtin_ia32_pmadd to interp__builtin_ia32_pmul for consistency
1 parent cca7eb5 commit e0b78c2

File tree

1 file changed

+16
-52
lines changed

1 file changed

+16
-52
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,7 +2551,7 @@ static bool interp__builtin_elementwise_maxmin(InterpState &S, CodePtr OpPC,
25512551
return true;
25522552
}
25532553

2554-
static bool interp__builtin_ia32_pmadd(
2554+
static bool interp__builtin_ia32_pmul(
25552555
InterpState &S, CodePtr OpPC, const CallExpr *Call,
25562556
llvm::function_ref<APInt(const APSInt &, const APSInt &, const APSInt &,
25572557
const APSInt &)>
@@ -2589,54 +2589,6 @@ static bool interp__builtin_ia32_pmadd(
25892589
return true;
25902590
}
25912591

2592-
static bool interp__builtin_ia32_pmul(InterpState &S, CodePtr OpPC,
2593-
const CallExpr *Call,
2594-
unsigned BuiltinID) {
2595-
assert(Call->getArg(0)->getType()->isVectorType() &&
2596-
Call->getArg(1)->getType()->isVectorType());
2597-
const Pointer &RHS = S.Stk.pop<Pointer>();
2598-
const Pointer &LHS = S.Stk.pop<Pointer>();
2599-
const Pointer &Dst = S.Stk.peek<Pointer>();
2600-
2601-
const auto *VT = Call->getArg(0)->getType()->castAs<VectorType>();
2602-
PrimType ElemT = *S.getContext().classify(VT->getElementType());
2603-
unsigned SourceLen = VT->getNumElements();
2604-
2605-
PrimType DstElemT = *S.getContext().classify(
2606-
Call->getType()->castAs<VectorType>()->getElementType());
2607-
unsigned DstElem = 0;
2608-
for (unsigned I = 0; I != SourceLen; I += 2) {
2609-
APSInt Elem1;
2610-
APSInt Elem2;
2611-
INT_TYPE_SWITCH_NO_BOOL(ElemT, {
2612-
Elem1 = LHS.elem<T>(I).toAPSInt();
2613-
Elem2 = RHS.elem<T>(I).toAPSInt();
2614-
});
2615-
2616-
APSInt Result;
2617-
switch (BuiltinID) {
2618-
case clang::X86::BI__builtin_ia32_pmuludq128:
2619-
case clang::X86::BI__builtin_ia32_pmuludq256:
2620-
case clang::X86::BI__builtin_ia32_pmuludq512:
2621-
Result = APSInt(llvm::APIntOps::muluExtended(Elem1, Elem2),
2622-
/*IsUnsigned=*/true);
2623-
break;
2624-
case clang::X86::BI__builtin_ia32_pmuldq128:
2625-
case clang::X86::BI__builtin_ia32_pmuldq256:
2626-
case clang::X86::BI__builtin_ia32_pmuldq512:
2627-
Result = APSInt(llvm::APIntOps::mulsExtended(Elem1, Elem2),
2628-
/*IsUnsigned=*/false);
2629-
break;
2630-
}
2631-
INT_TYPE_SWITCH_NO_BOOL(DstElemT,
2632-
{ Dst.elem<T>(DstElem) = static_cast<T>(Result); });
2633-
++DstElem;
2634-
}
2635-
2636-
Dst.initializeAllElements();
2637-
return true;
2638-
}
2639-
26402592
static bool interp__builtin_elementwise_triop_fp(
26412593
InterpState &S, CodePtr OpPC, const CallExpr *Call,
26422594
llvm::function_ref<APFloat(const APFloat &, const APFloat &,
@@ -3514,7 +3466,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
35143466
case clang::X86::BI__builtin_ia32_pmaddubsw128:
35153467
case clang::X86::BI__builtin_ia32_pmaddubsw256:
35163468
case clang::X86::BI__builtin_ia32_pmaddubsw512:
3517-
return interp__builtin_ia32_pmadd(
3469+
return interp__builtin_ia32_pmul(
35183470
S, OpPC, Call,
35193471
[](const APSInt &LoLHS, const APSInt &HiLHS, const APSInt &LoRHS,
35203472
const APSInt &HiRHS) {
@@ -3526,7 +3478,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
35263478
case clang::X86::BI__builtin_ia32_pmaddwd128:
35273479
case clang::X86::BI__builtin_ia32_pmaddwd256:
35283480
case clang::X86::BI__builtin_ia32_pmaddwd512:
3529-
return interp__builtin_ia32_pmadd(
3481+
return interp__builtin_ia32_pmul(
35303482
S, OpPC, Call,
35313483
[](const APSInt &LoLHS, const APSInt &HiLHS, const APSInt &LoRHS,
35323484
const APSInt &HiRHS) {
@@ -3679,10 +3631,22 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
36793631
case clang::X86::BI__builtin_ia32_pmuldq128:
36803632
case clang::X86::BI__builtin_ia32_pmuldq256:
36813633
case clang::X86::BI__builtin_ia32_pmuldq512:
3634+
return interp__builtin_ia32_pmul(
3635+
S, OpPC, Call,
3636+
[](const APSInt &LoLHS, const APSInt &HiLHS, const APSInt &LoRHS,
3637+
const APSInt &HiRHS) {
3638+
return llvm::APIntOps::mulsExtended(LoLHS, LoRHS);
3639+
});
3640+
36823641
case clang::X86::BI__builtin_ia32_pmuludq128:
36833642
case clang::X86::BI__builtin_ia32_pmuludq256:
36843643
case clang::X86::BI__builtin_ia32_pmuludq512:
3685-
return interp__builtin_ia32_pmul(S, OpPC, Call, BuiltinID);
3644+
return interp__builtin_ia32_pmul(
3645+
S, OpPC, Call,
3646+
[](const APSInt &LoLHS, const APSInt &HiLHS, const APSInt &LoRHS,
3647+
const APSInt &HiRHS) {
3648+
return llvm::APIntOps::muluExtended(LoLHS, LoRHS);
3649+
});
36863650

36873651
case Builtin::BI__builtin_elementwise_fma:
36883652
return interp__builtin_elementwise_triop_fp(

0 commit comments

Comments
 (0)