Skip to content

Commit 9a95625

Browse files
aparshin-inteligcbot
authored andcommitted
VC backed can lower lzd64
1 parent cee82c0 commit 9a95625

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXLowering.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class GenXLowering : public FunctionPass {
198198
bool lowerLoadStore(Instruction *Inst);
199199
bool lowerMulSat(CallInst *CI, unsigned IntrinsicID);
200200
bool lowerMul64(Instruction *Inst);
201+
bool lowerLzd(Instruction *Inst);
201202
bool lowerTrap(CallInst *CI);
202203
bool generatePredicatedWrrForNewLoad(CallInst *CI);
203204
};
@@ -1135,6 +1136,8 @@ bool GenXLowering::processInst(Instruction *Inst) {
11351136
case GenXIntrinsic::genx_usmul_sat:
11361137
case GenXIntrinsic::genx_uumul_sat:
11371138
return lowerMulSat(CI, IntrinsicID);
1139+
case GenXIntrinsic::genx_lzd:
1140+
return lowerLzd(Inst);
11381141
case Intrinsic::trap:
11391142
return lowerTrap(CI);
11401143
case Intrinsic::ctpop:
@@ -2568,7 +2571,6 @@ bool GenXLowering::lowerMul64(Instruction *Inst) {
25682571
return false;
25692572

25702573
IRBuilder<> Builder(Inst);
2571-
Builder.SetCurrentDebugLocation(Inst->getDebugLoc());
25722574

25732575
auto Src0 = SplitBuilder.splitOperandLoHi(0);
25742576
auto Src1 = SplitBuilder.splitOperandLoHi(1);
@@ -2596,6 +2598,38 @@ bool GenXLowering::lowerMul64(Instruction *Inst) {
25962598
ToErase.push_back(Inst);
25972599
return true;
25982600
}
2601+
bool GenXLowering::lowerLzd(Instruction *Inst) {
2602+
const unsigned OpIndex = 0;
2603+
IVSplitter SplitBuilder(*Inst, &OpIndex);
2604+
if (!SplitBuilder.IsI64Operation())
2605+
return false;
2606+
2607+
IRBuilder<> Builder(Inst);
2608+
2609+
auto Src = SplitBuilder.splitOperandLoHi(0);
2610+
2611+
auto *VTy32 = cast<VectorType>(Src.Lo->getType());
2612+
IGC_ASSERT(VTy32->getScalarType() == Builder.getInt32Ty());
2613+
auto *Zero = ConstantInt::getNullValue(VTy32);
2614+
auto *K32 = ConstantInt::get(VTy32, 32);
2615+
2616+
auto *LzdF = GenXIntrinsic::getAnyDeclaration(
2617+
Inst->getModule(), GenXIntrinsic::genx_lzd, {Src.Lo->getType()});
2618+
2619+
// Lzd64 is lowered as:
2620+
// LoLzd = lzd(Src.Lo)
2621+
// HiLzd = lzd(Src.Hi)
2622+
// Result = (Src.Hi == 0) ? (LoLzd + 32) : HiLzd
2623+
auto *VlzdLo = Builder.CreateCall(LzdF, Src.Lo, "lower.lzd64.lo.");
2624+
auto *VlzdHi = Builder.CreateCall(LzdF, Src.Hi, "lower.lzd64.hi.");
2625+
auto *FlagHiZero = Builder.CreateICmpEQ(Src.Hi, Zero, "lower.lzd64.hicmp.");
2626+
auto *LoPathResult = Builder.CreateAdd(VlzdLo, K32, "lower.lzd64.lores.");
2627+
auto *Result =
2628+
Builder.CreateSelect(FlagHiZero, LoPathResult, VlzdHi, "lower.lzd64.");
2629+
Inst->replaceAllUsesWith(Result);
2630+
ToErase.push_back(Inst);
2631+
return true;
2632+
}
25992633
/***********************************************************************
26002634
* widenByteOp : widen a vector byte operation to short if that might
26012635
* improve code

IGC/VectorCompiler/lib/GenXCodeGen/GenXUtil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,8 @@ unsigned ShuffleVectorAnalyzer::getSerializeCost(unsigned i) {
10371037
return Cost;
10381038
}
10391039

1040-
1041-
IVSplitter::IVSplitter(Instruction &Inst, unsigned* BaseOpIdx) : Inst(Inst) {
1040+
IVSplitter::IVSplitter(Instruction &Inst, const unsigned *BaseOpIdx)
1041+
: Inst(Inst) {
10421042

10431043
ETy = Inst.getType();
10441044
if (BaseOpIdx)

IGC/VectorCompiler/lib/GenXCodeGen/GenXUtil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class IVSplitter {
331331
// If BaseOpIdx indexes a scalar/vector operand of i64 type, then
332332
// IsI64Operation shall return true, otherwise the value type of an
333333
// instruction is used
334-
IVSplitter(Instruction &Inst, unsigned* BaseOpIdx = nullptr);
334+
IVSplitter(Instruction &Inst, const unsigned *BaseOpIdx = nullptr);
335335

336336
// Splitted Operand is expected to be a scalar/vector of i64 type
337337
LoHiSplit splitOperandLoHi(unsigned SourceIdx);

0 commit comments

Comments
 (0)