Skip to content

Commit 14a126b

Browse files
authored
[mlir][tosa] Remove log(exp(x)) and exp(log(x)) folders (llvm#156434)
Both of the folders would reduce to `x`. These folders were vulnerable to overflow / underflow issues, resulting in a difference in numerical behaviour when running or not running the folders. For now they have been removed. We can consider restoring these as part of an optional and separate "fast-math" style of transformation in the future.
1 parent 4b99547 commit 14a126b

File tree

3 files changed

+0
-44
lines changed

3 files changed

+0
-44
lines changed

mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,8 +1331,6 @@ def Tosa_ExpOp : Tosa_ElementwiseUnaryOp<"exp"> {
13311331
Extension<[Tosa_EXT_BF16]>,
13321332
];
13331333

1334-
let hasFolder = 1;
1335-
13361334
let assemblyFormat = "operands attr-dict `:` functional-type(operands, results)";
13371335
}
13381336

@@ -1385,8 +1383,6 @@ def Tosa_LogOp : Tosa_ElementwiseUnaryOp<"log"> {
13851383
Extension<[Tosa_EXT_BF16]>,
13861384
];
13871385

1388-
let hasFolder = 1;
1389-
13901386
let assemblyFormat = "operands attr-dict `:` functional-type(operands, results)";
13911387
}
13921388

mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,26 +1562,6 @@ OpFoldResult TransposeOp::fold(FoldAdaptor adaptor) {
15621562
return getInput1();
15631563
}
15641564

1565-
OpFoldResult tosa::LogOp::fold(FoldAdaptor adaptor) {
1566-
auto input = getInput1();
1567-
// Element-wise log(exp(x)) = x
1568-
if (auto op = input.getDefiningOp<tosa::ExpOp>()) {
1569-
return op.getInput1();
1570-
}
1571-
1572-
return {};
1573-
}
1574-
1575-
OpFoldResult tosa::ExpOp::fold(FoldAdaptor adaptor) {
1576-
auto input = getInput1();
1577-
// Element-wise exp(log(x)) = x
1578-
if (auto op = input.getDefiningOp<tosa::LogOp>()) {
1579-
return op.getInput1();
1580-
}
1581-
1582-
return {};
1583-
}
1584-
15851565
OpFoldResult tosa::NegateOp::fold(FoldAdaptor adaptor) {
15861566
// Element-wise negate(negate(x)) = x
15871567
// iff all zero points are constant 0

mlir/test/Dialect/Tosa/canonicalize.mlir

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,26 +1104,6 @@ func.func @canonicalize_pad_slice_dynamic_noupdate(%arg0: tensor<1x16x?x3xf32>)
11041104

11051105
// -----
11061106

1107-
// CHECK-LABEL: @fold_log_exp
1108-
func.func @fold_log_exp(%arg0: tensor<?x1xf32>) -> tensor<?x1xf32> {
1109-
// CHECK: return %arg{{.*}} : tensor<?x1xf32>
1110-
%0 = tosa.exp %arg0 : (tensor<?x1xf32>) -> tensor<?x1xf32>
1111-
%1 = tosa.log %0 : (tensor<?x1xf32>) -> tensor<?x1xf32>
1112-
return %1 : tensor<?x1xf32>
1113-
}
1114-
1115-
// -----
1116-
1117-
// CHECK-LABEL: @fold_exp_log
1118-
func.func @fold_exp_log(%arg0: tensor<?x1xf32>) -> tensor<?x1xf32> {
1119-
// CHECK: return %arg{{.*}} : tensor<?x1xf32>
1120-
%0 = tosa.log %arg0 : (tensor<?x1xf32>) -> tensor<?x1xf32>
1121-
%1 = tosa.exp %0 : (tensor<?x1xf32>) -> tensor<?x1xf32>
1122-
return %1 : tensor<?x1xf32>
1123-
}
1124-
1125-
// -----
1126-
11271107
// CHECK-LABEL: @fold_negate_negate
11281108
func.func @fold_negate_negate(%arg0: tensor<?x1xf32>) -> tensor<?x1xf32> {
11291109
// CHECK: return %arg{{.*}} : tensor<?x1xf32>

0 commit comments

Comments
 (0)