@@ -978,6 +978,39 @@ static Instruction *generateGenXCall(ExtractElementInst *EEI,
978
978
return Inst;
979
979
}
980
980
981
+ // Translates the following intrinsics:
982
+ // %res = call float @llvm.fmuladd.f32(float %a, float %b, float %c)
983
+ // %res = call double @llvm.fmuladd.f64(double %a, double %b, double %c)
984
+ // To
985
+ // %mul = fmul <type> %a, <type> %b
986
+ // %res = fadd <type> %mul, <type> %c
987
+ void translateFmuladd (CallInst *CI) {
988
+ assert (CI->getIntrinsicID () == Intrinsic::fmuladd);
989
+ IRBuilder<> Bld (CI);
990
+ auto *Mul = Bld.CreateFMul (CI->getOperand (0 ), CI->getOperand (1 ));
991
+ auto *Res = Bld.CreateFAdd (Mul, CI->getOperand (2 ));
992
+ CI->replaceAllUsesWith (Res);
993
+ }
994
+
995
+ // Translates an LLVM intrinsic to a form, digestable by the BE.
996
+ bool translateLLVMIntrinsic (CallInst *CI) {
997
+ Function *F = CI->getCalledFunction () ? CI->getCalledFunction () : nullptr ;
998
+ assert (F && F->isIntrinsic ());
999
+
1000
+ switch (F->getIntrinsicID ()) {
1001
+ case Intrinsic::assume:
1002
+ // no translation - it will be simply removed.
1003
+ // TODO: make use of 'assume' info in the BE
1004
+ break ;
1005
+ case Intrinsic::fmuladd:
1006
+ translateFmuladd (CI);
1007
+ break ;
1008
+ default :
1009
+ return false ; // "intrinsic wasn't translated, keep the original call"
1010
+ }
1011
+ return true ; // "intrinsic has been translated, erase the original call"
1012
+ }
1013
+
981
1014
// / Replaces the load \p LI of SPIRV global with corresponding call(s) of GenX
982
1015
// / intrinsic(s). The users of \p LI may also be transformed if needed for
983
1016
// / def/use type correctness.
@@ -1469,8 +1502,10 @@ size_t SYCLLowerESIMDPass::runOnFunction(Function &F,
1469
1502
Function *Callee = nullptr ;
1470
1503
if (CI && (Callee = CI->getCalledFunction ())) {
1471
1504
// TODO workaround for ESIMD BE until it starts supporting @llvm.assume
1472
- if (match (&I, PatternMatch::m_Intrinsic<Intrinsic::assume>())) {
1473
- ToErase.push_back (CI);
1505
+ if (Callee->isIntrinsic ()) {
1506
+ if (translateLLVMIntrinsic (CI)) {
1507
+ ToErase.push_back (CI);
1508
+ }
1474
1509
continue ;
1475
1510
}
1476
1511
StringRef Name = Callee->getName ();
0 commit comments