Skip to content

Commit 2ab1d7b

Browse files
committed
Reject reciprocals that use constant non-TOSA tensors
1 parent 7c7a68b commit 2ab1d7b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

mlir/lib/Dialect/Tosa/Transforms/TosaFoldConstantReciprocal.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,17 @@ struct TosaFoldConstantReciprocal : public OpRewritePattern<ReciprocalOp> {
9898
return success();
9999
}
100100

101+
if (!isa<ConstOp>(inputTensor.getDefiningOp())) {
102+
return rewriter.notifyMatchFailure(recip,
103+
"The reciprocal can only be folded if "
104+
"it operates on a TOSA constant");
105+
}
106+
auto definingConstOp = cast<ConstOp>(inputTensor.getDefiningOp());
107+
101108
// Our transformation replaces the input tensor with the transformed tensor.
102109
// If the input has several users we need to keep the input. This can
103110
// result in a significantly increased memory usage, such that we currently
104111
// refrain from applying the transformation in that case.
105-
auto definingConstOp = cast<ConstOp>(inputTensor.getDefiningOp());
106112
if (!definingConstOp->hasOneUse()) {
107113
return rewriter.notifyMatchFailure(
108114
recip, "Currently, reciprocals will only be folded if the input "

0 commit comments

Comments
 (0)