Skip to content

Commit

Permalink
Added FMul
Browse files Browse the repository at this point in the history
  • Loading branch information
bwlodarcz committed Nov 10, 2023
1 parent aec34ac commit 4e030ae
Show file tree
Hide file tree
Showing 2 changed files with 451 additions and 20 deletions.
40 changes: 20 additions & 20 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
#include "llvm/Transforms/Utils/LoopSimplify.h"
#include "llvm/Transforms/Utils/Mem2Reg.h"

#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
Expand Down Expand Up @@ -4066,6 +4065,26 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
}
return Extracts[0];
}
case Intrinsic::vector_reduce_fadd:
case Intrinsic::vector_reduce_fmul: {
Op Op = IID == Intrinsic::vector_reduce_fadd ? OpFAdd : OpFMul;
SPIRVValue *VectorVal = transValue(II->getArgOperand(1), BB);
VectorType *VecType = cast<VectorType>(II->getArgOperand(1)->getType());
SPIRVValue *StartingVal = transValue(II->getArgOperand(0), BB);
SPIRVTypeInt *I32 = BM->addIntegerType(32);
unsigned ArrSize = VecType->getElementCount().getFixedValue();
SmallVector<SPIRVValue *, 16> Extracts(ArrSize);
for (unsigned Idx = 0; Idx < ArrSize; ++Idx) {
Extracts[Idx] = BM->addVectorExtractDynamicInst(
VectorVal, BM->addIntegerConstant(I32, Idx), BB);
}
SPIRVValue *V = BM->addBinaryInst(Op, StartingVal->getType(), StartingVal,
Extracts[0], BB);
for (unsigned Idx = 1; Idx < ArrSize; ++Idx) {
V = BM->addBinaryInst(Op, StartingVal->getType(), V, Extracts[Idx], BB);
}
return V;
}
case Intrinsic::vector_reduce_smax:
case Intrinsic::vector_reduce_smin:
case Intrinsic::vector_reduce_umax:
Expand Down Expand Up @@ -4108,25 +4127,6 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
}
return Extracts[0];
}
case Intrinsic::vector_reduce_fadd: {
SPIRVValue *VectorVal = transValue(II->getArgOperand(1), BB);
VectorType *VecType = cast<VectorType>(II->getArgOperand(1)->getType());
SPIRVValue *StartingVal = transValue(II->getArgOperand(0), BB);
SPIRVTypeInt *I32 = BM->addIntegerType(32);
unsigned ArrSize = VecType->getElementCount().getFixedValue();
SmallVector<SPIRVValue *, 16> Extracts(ArrSize);
for (unsigned Idx = 0; Idx < ArrSize; ++Idx) {
Extracts[Idx] = BM->addVectorExtractDynamicInst(
VectorVal, BM->addIntegerConstant(I32, Idx), BB);
}
SPIRVValue *V = BM->addBinaryInst(OpFAdd, StartingVal->getType(),
StartingVal, Extracts[0], BB);
for (unsigned Idx = 1; Idx < ArrSize; ++Idx) {
V = BM->addBinaryInst(OpFAdd, StartingVal->getType(), V, Extracts[Idx],
BB);
}
return V;
}
case Intrinsic::memset: {
// Generally there is no direct mapping of memset to SPIR-V. But it turns
// out that memset is emitted by Clang for initialization in default
Expand Down
Loading

0 comments on commit 4e030ae

Please sign in to comment.