Element-wise exp(log) can be canonicalized as no-op.
Reviewed By: eric-k256
Differential Revision: https://reviews.llvm.org/D150342
let results = (outs
Tosa_Tensor:$output
);
+
+ let hasFolder = 1;
}
//===----------------------------------------------------------------------===//
return {};
}
+
+OpFoldResult tosa::ExpOp::fold(FoldAdaptor adaptor) {
+ auto input = getInput1();
+ // Element-wise exp(log(x)) = x
+ if (auto op = input.getDefiningOp<tosa::LogOp>()) {
+ return op.getInput1();
+ }
+
+ return {};
+}
%1 = "tosa.log"(%0) : (tensor<?x1xf32>) -> tensor<?x1xf32>
return %1 : tensor<?x1xf32>
}
+
+// -----
+
+// CHECK-LABEL: @fold_exp_log
+func.func @fold_exp_log(%arg0: tensor<?x1xf32>) -> tensor<?x1xf32> {
+ // CHECK: return %arg{{.*}} : tensor<?x1xf32>
+ %0 = "tosa.log"(%arg0) : (tensor<?x1xf32>) -> tensor<?x1xf32>
+ %1 = "tosa.exp"(%0) : (tensor<?x1xf32>) -> tensor<?x1xf32>
+ return %1 : tensor<?x1xf32>
+}