|
1 | 1 | /*========================== begin_copyright_notice ============================
|
2 | 2 |
|
3 |
| -Copyright (C) 2017-2023 Intel Corporation |
| 3 | +Copyright (C) 2017-2024 Intel Corporation |
4 | 4 |
|
5 | 5 | SPDX-License-Identifier: MIT
|
6 | 6 |
|
@@ -198,6 +198,7 @@ class GenXPatternMatch : public FunctionPass,
|
198 | 198 | bool simplifyCmp(CmpInst *Cmp);
|
199 | 199 | CmpInst *reduceCmpWidth(CmpInst *Cmp);
|
200 | 200 | bool simplifyNullDst(CallInst *Inst);
|
| 201 | + bool simplifyDpasNullSrc(CallInst *Inst); |
201 | 202 | // Transform logic operation with a mask from <N x iM> to <N/(32/M) x i32>
|
202 | 203 | bool extendMask(BinaryOperator *BO);
|
203 | 204 | bool mergeApply(CallInst *CI);
|
@@ -523,11 +524,20 @@ void GenXPatternMatch::visitBinaryOperator(BinaryOperator &I) {
|
523 | 524 | }
|
524 | 525 |
|
525 | 526 | void GenXPatternMatch::visitCallInst(CallInst &I) {
|
526 |
| - if (Kind == PatternMatchKind::PostLegalization) { |
527 |
| - return; |
| 527 | + auto IID = vc::getAnyIntrinsicID(&I); |
| 528 | + |
| 529 | + switch (IID) { |
| 530 | + default: |
| 531 | + break; |
| 532 | + case GenXIntrinsic::genx_dpas: |
| 533 | + case GenXIntrinsic::genx_dpas2: |
| 534 | + Changed |= simplifyDpasNullSrc(&I); |
| 535 | + break; |
528 | 536 | }
|
529 | 537 |
|
530 |
| - auto IID = vc::getAnyIntrinsicID(&I); |
| 538 | + if (Kind == PatternMatchKind::PostLegalization) |
| 539 | + return; |
| 540 | + |
531 | 541 | switch (IID) {
|
532 | 542 | default:
|
533 | 543 | break;
|
@@ -3719,6 +3729,47 @@ bool GenXPatternMatch::simplifyNullDst(CallInst *Inst) {
|
3719 | 3729 | return false;
|
3720 | 3730 | }
|
3721 | 3731 |
|
| 3732 | +bool GenXPatternMatch::simplifyDpasNullSrc(CallInst *Inst) { |
| 3733 | + auto IID = vc::getAnyIntrinsicID(Inst); |
| 3734 | + IGC_ASSERT_EXIT(IID == GenXIntrinsic::genx_dpas || |
| 3735 | + IID == GenXIntrinsic::genx_dpas2); |
| 3736 | + |
| 3737 | + auto *Acc = dyn_cast<Constant>(Inst->getArgOperand(0)); |
| 3738 | + if (!Acc || !Acc->isZeroValue()) |
| 3739 | + return false; |
| 3740 | + |
| 3741 | + IRBuilder<> Builder(Inst); |
| 3742 | + |
| 3743 | + // Accumulator input is constant zero, so we could use dpas_nosrc0 intrinsic |
| 3744 | + auto *Src1 = Inst->getArgOperand(1); |
| 3745 | + auto *Src2 = Inst->getArgOperand(2); |
| 3746 | + |
| 3747 | + Value *Desc = Inst->getArgOperand(3); |
| 3748 | + if (IID == GenXIntrinsic::genx_dpas2) { |
| 3749 | + auto Src1Precision = |
| 3750 | + cast<ConstantInt>(Inst->getArgOperand(3))->getZExtValue() & 0xff; |
| 3751 | + auto Src2Precision = |
| 3752 | + cast<ConstantInt>(Inst->getArgOperand(4))->getZExtValue() & 0xff; |
| 3753 | + auto SystolicDepth = |
| 3754 | + cast<ConstantInt>(Inst->getArgOperand(5))->getZExtValue() & 0xff; |
| 3755 | + auto RepeatCount = |
| 3756 | + cast<ConstantInt>(Inst->getArgOperand(6))->getZExtValue() & 0xff; |
| 3757 | + |
| 3758 | + Desc = Builder.getInt32(Src1Precision | Src2Precision << 8 | |
| 3759 | + SystolicDepth << 16 | RepeatCount << 24); |
| 3760 | + } |
| 3761 | + |
| 3762 | + auto *Func = vc::getAnyDeclaration( |
| 3763 | + Inst->getModule(), GenXIntrinsic::genx_dpas_nosrc0, |
| 3764 | + {Inst->getType(), Src1->getType(), Src2->getType()}); |
| 3765 | + auto *NewCI = Builder.CreateCall(Func, {Src1, Src2, Desc}); |
| 3766 | + NewCI->takeName(Inst); |
| 3767 | + Inst->replaceAllUsesWith(NewCI); |
| 3768 | + Inst->eraseFromParent(); |
| 3769 | + |
| 3770 | + return true; |
| 3771 | +} |
| 3772 | + |
3722 | 3773 | bool canExtendMask(BinaryOperator *BO) {
|
3723 | 3774 | Type *InstTy = BO->getType();
|
3724 | 3775 | auto Op0 = dyn_cast<ConstantDataVector>(BO->getOperand(0));
|
|
0 commit comments