forked from OSchip/llvm-project
[mlir][tosa] Revert add-0 canonicalization for floating-point
Floating point optimization can produce incorrect numerical resutls for -0.0 + 0.0 optimization as result needs to be -0.0. Reviewed By: eric-k256 Differential Revision: https://reviews.llvm.org/D114127
This commit is contained in:
parent
c4dba47196
commit
6e41a06911
|
@ -301,12 +301,6 @@ struct AddZeroOptimization : public OpRewritePattern<tosa::AddOp> {
|
|||
DenseElementsAttr input1Attr;
|
||||
if (matchPattern(input1, m_Constant(&input1Attr)) && input1Attr.isSplat() &&
|
||||
input2.getType() == op.getType()) {
|
||||
if (input1Attr.getType().getElementType().isa<FloatType>() &&
|
||||
input1Attr.getSplatValue<APFloat>().isZero()) {
|
||||
rewriter.replaceOp(op, op.input2());
|
||||
return success();
|
||||
}
|
||||
|
||||
if (input1Attr.getType().getElementType().isa<IntegerType>() &&
|
||||
input1Attr.getSplatValue<APInt>().isZero()) {
|
||||
rewriter.replaceOp(op, op.input2());
|
||||
|
@ -317,12 +311,6 @@ struct AddZeroOptimization : public OpRewritePattern<tosa::AddOp> {
|
|||
DenseElementsAttr input2Attr;
|
||||
if (matchPattern(input2, m_Constant(&input2Attr)) && input2Attr.isSplat() &&
|
||||
input1.getType() == op.getType()) {
|
||||
if (input2Attr.getType().getElementType().isa<FloatType>() &&
|
||||
input2Attr.getSplatValue<APFloat>().isZero()) {
|
||||
rewriter.replaceOp(op, op.input1());
|
||||
return success();
|
||||
}
|
||||
|
||||
if (input2Attr.getType().getElementType().isa<IntegerType>() &&
|
||||
input2Attr.getSplatValue<APInt>().isZero()) {
|
||||
rewriter.replaceOp(op, op.input1());
|
||||
|
|
|
@ -10,23 +10,13 @@ func @argmax_nofold(%arg0: tensor<?x1xf32>) -> tensor<?x1xf32> {
|
|||
// -----
|
||||
|
||||
// CHECK-LABEL: @add_zero_different_shape
|
||||
func @add_zero_different_shape(%arg0: tensor<2x3xf32>) -> tensor<4x2x3xf32> {
|
||||
func @add_zero_different_shape(%arg0: tensor<2x3xi32>) -> tensor<4x2x3xi32> {
|
||||
// CHECK: tosa.add
|
||||
%zeros = "tosa.const"() {value = dense<0.0> : tensor<4x2x3xf32>} : () -> tensor<4x2x3xf32>
|
||||
%1 = "tosa.add"(%arg0, %zeros) : (tensor<2x3xf32>, tensor<4x2x3xf32>) -> tensor<4x2x3xf32>
|
||||
return %1 : tensor<4x2x3xf32>
|
||||
%zeros = "tosa.const"() {value = dense<0> : tensor<4x2x3xi32>} : () -> tensor<4x2x3xi32>
|
||||
%1 = "tosa.add"(%arg0, %zeros) : (tensor<2x3xi32>, tensor<4x2x3xi32>) -> tensor<4x2x3xi32>
|
||||
return %1 : tensor<4x2x3xi32>
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// CHECK-LABEL: @add_zero_float
|
||||
func @add_zero_float(%arg0: tensor<2x3xf32>) -> tensor<2x3xf32> {
|
||||
// CHECK: return %arg0
|
||||
// CHECK-NOT: tosa.add
|
||||
%zeros = "tosa.const"() {value = dense<0.0> : tensor<2x3xf32>} : () -> tensor<2x3xf32>
|
||||
%1 = "tosa.add"(%arg0, %zeros) : (tensor<2x3xf32>, tensor<2x3xf32>) -> tensor<2x3xf32>
|
||||
return %1 : tensor<2x3xf32>
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
|
|
Loading…
Reference in New Issue