Skip to content

Commit 12a6dd0

Browse files
igorban-inteligcbot
authored andcommitted
Support lowering llvm.powi with scalar power
.
1 parent 185115e commit 12a6dd0

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXLowering.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4491,11 +4491,20 @@ bool GenXLowering::lowerFMulAdd(CallInst *CI) {
44914491
bool GenXLowering::lowerPowI(CallInst *CI) {
44924492
IGC_ASSERT(CI);
44934493
IRBuilder<> IRB{CI};
4494-
auto *Decl = Intrinsic::getDeclaration(CI->getModule(), Intrinsic::pow,
4495-
{CI->getType()});
4496-
auto *Cast =
4497-
IRB.CreateCast(Instruction::SIToFP, CI->getOperand(1), CI->getType());
4498-
auto *Pow = IRB.CreateCall(Decl, {CI->getOperand(0), Cast}, CI->getName());
4494+
auto *CITy = CI->getType();
4495+
auto *Decl =
4496+
Intrinsic::getDeclaration(CI->getModule(), Intrinsic::pow, {CITy});
4497+
auto *Operand = CI->getOperand(1);
4498+
// For pow @llvm.powi.v*.i*(< x > , i32 ) cases
4499+
if (auto *CIVTy = dyn_cast<IGCLLVM::FixedVectorType>(CITy);
4500+
CIVTy && !Operand->getType()->isVectorTy()) {
4501+
auto *ElTy = CIVTy->getElementType();
4502+
Operand = IRB.CreateSIToFP(Operand, ElTy);
4503+
Operand = IRB.CreateVectorSplat(CIVTy->getNumElements(), Operand);
4504+
} else {
4505+
Operand = IRB.CreateCast(Instruction::SIToFP, Operand, CITy);
4506+
}
4507+
auto *Pow = IRB.CreateCall(Decl, {CI->getOperand(0), Operand}, CI->getName());
44994508
Pow->setHasApproxFunc(true);
45004509
CI->replaceAllUsesWith(Pow);
45014510
ToErase.push_back(CI);

IGC/VectorCompiler/lib/GenXCodeGen/GenXUtil.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2593,7 +2593,6 @@ bool genx::isSafeToMove_CheckAVLoadKill(const Instruction *const I,
25932593
return !getAVLoadKillOrNull(I, To, true, false, DT);
25942594
for (auto *LI : getSrcVLoads(I)) {
25952595
const bool LIDomTo = !DT || DT->dominates(LI, To);
2596-
IGC_ASSERT(LIDomTo);
25972596
if (!LIDomTo || getAVLoadKillOrNull(LI, To))
25982597
return false;
25992598
}

IGC/VectorCompiler/test/Lowering/powi.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,12 @@ define spir_func <64 x bfloat> @powi_bfloat_i8(<64 x i8> %src, <64 x bfloat> %sr
5656
ret <64 x bfloat> %res
5757
}
5858

59+
declare <64 x float> @llvm.powi.v64f32.i32(<64 x float>, i32)
60+
; CHECK-LABEL: powi_float_i32
61+
define spir_func <64 x float> @powi_float_i32(<64 x float> %src) {
62+
; CHECK: {{.*}} = call afn <64 x float> @llvm.pow.v64f32(<64 x float> %src, <64 x float> <float -4.000000e+00,
63+
%res = tail call afn <64 x float> @llvm.powi.v64f32.i32(<64 x float> %src, i32 -4)
64+
ret <64 x float> %res
65+
}
66+
5967
attributes #2 = { nofree nosync nounwind readnone speculatable willreturn }

0 commit comments

Comments
 (0)