@@ -31,7 +31,6 @@ struct TosaFoldConstantReciprocal : public OpRewritePattern<ReciprocalOp> {
31
31
APFloat::rmNearestTiesToEven;
32
32
33
33
APFloat computeReciprocal (const APFloat &floatVal, Type floatTy) const {
34
-
35
34
auto recipAttr = FloatAttr::get (floatTy, 1.0 );
36
35
APFloat recip = recipAttr.getValue ();
37
36
recip.divide (floatVal, reciprocalRoundingMode);
@@ -46,7 +45,10 @@ struct TosaFoldConstantReciprocal : public OpRewritePattern<ReciprocalOp> {
46
45
// TODO it would be nicer to do this in-place
47
46
48
47
// Compute the reciprocal for each tensor element
49
- llvm::SmallVector<APFloat, 10 > transformedValues;
48
+ llvm::SmallVector<APFloat, 1 > transformedValues;
49
+ // We already know the amount of values we will insert, reserver space for
50
+ // all of them to avoid dynamic resizing
51
+ transformedValues.reserve (inputValues.getNumElements ());
50
52
for (auto it = inputValues.value_begin <APFloat>();
51
53
it != inputValues.value_end <APFloat>(); it++) {
52
54
auto val = *it;
@@ -64,7 +66,6 @@ struct TosaFoldConstantReciprocal : public OpRewritePattern<ReciprocalOp> {
64
66
65
67
LogicalResult matchAndRewrite (ReciprocalOp recip,
66
68
PatternRewriter &rewriter) const override {
67
-
68
69
auto inputTensor = recip.getInput1 ();
69
70
auto elemType = inputTensor.getType ().getElementType ();
70
71
// TOSA only allows for floats as inputs to the reciprocal operation, so
@@ -85,7 +86,6 @@ struct TosaFoldConstantReciprocal : public OpRewritePattern<ReciprocalOp> {
85
86
// In case we have a splat, we only need to calculate the reciprocal once
86
87
// and update the tensor to the transformed splat value.
87
88
if (auto splatAttrs = dyn_cast<SplatElementsAttr>(inputValues)) {
88
-
89
89
// Transform the splat value
90
90
auto splatVal = splatAttrs.getSplatValue <APFloat>();
91
91
auto newSplatRecipAttr = computeReciprocal (splatVal, elemType);
0 commit comments