From ca214995266267271153482fceb09c32abfb3707 Mon Sep 17 00:00:00 2001 From: Robert Walker Date: Wed, 4 Jan 2023 11:26:12 -0800 Subject: [PATCH] [mlir][tosa] Fix floating point offset for tosa.resize Offset is a signed value, so use `arith.sitofp` See also https://github.com/llvm/llvm-project/issues/59585 Reviewed By: NatashaKnk, jpienaar Differential Revision: https://reviews.llvm.org/D140958 --- mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp | 2 +- mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-resize.mlir | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp index 199d81d..5f982e9 100644 --- a/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp +++ b/mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp @@ -1614,7 +1614,7 @@ public: Value val = b.create(b.getF32Type(), in); scaleN = b.create(b.getF32Type(), scaleN); scaleD = b.create(b.getF32Type(), scaleD); - offset = b.create(b.getF32Type(), offset); + offset = b.create(b.getF32Type(), offset); val = b.create(val, scaleD); val = b.create(val, offset); val = b.create(val, scaleN); diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-resize.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-resize.mlir index 9a6067f..cac74d0 100644 --- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-resize.mlir +++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-resize.mlir @@ -310,7 +310,7 @@ func.func @resize_nearest_fp(%input: tensor<1x50x48x1xf32>) -> () { // CHECK: %[[Y0:.+]] = arith.uitofp %[[Y]] // CHECK: %[[SCALE_Y_N:.*]] = arith.uitofp %[[ISCALE_Y_N]] // CHECK: %[[SCALE_Y_D:.*]] = arith.uitofp %[[ISCALE_Y_D]] - // CHECK: %[[OFFSET_Y:.*]] = arith.uitofp %[[IOFFSET_Y]] + // CHECK: %[[OFFSET_Y:.*]] = arith.sitofp %[[IOFFSET_Y]] // CHECK: %[[VAL_29:.*]] = arith.mulf %[[Y0]], %[[SCALE_Y_D]] // CHECK: %[[VAL_31:.*]] = arith.addf %[[VAL_29]], %[[OFFSET_Y]] // CHECK: %[[VAL_33:.*]] = arith.divf %[[VAL_31]], %[[SCALE_Y_N]] @@ -321,7 +321,7 @@ func.func @resize_nearest_fp(%input: tensor<1x50x48x1xf32>) -> () { // CHECK: %[[X0:.+]] = arith.uitofp %[[X]] // CHECK: %[[SCALE_X_N:.*]] = arith.uitofp %[[ISCALE_X_N]] // CHECK: %[[SCALE_X_D:.*]] = arith.uitofp %[[ISCALE_X_D]] - // CHECK: %[[OFFSET_X:.*]] = arith.uitofp %[[IOFFSET_X]] + // CHECK: %[[OFFSET_X:.*]] = arith.sitofp %[[IOFFSET_X]] // CHECK: %[[VAL_30:.*]] = arith.mulf %[[X0]], %[[SCALE_X_D]] // CHECK: %[[VAL_32:.*]] = arith.addf %[[VAL_30]], %[[OFFSET_X]] // CHECK: %[[VAL_34:.*]] = arith.divf %[[VAL_32]], %[[SCALE_X_N]] @@ -384,7 +384,7 @@ func.func @resize_bilinear_fp(%input: tensor<1x23x24x1xf32>) -> () { // CHECK: %[[Y0:.+]] = arith.uitofp %[[Y]] // CHECK: %[[SCALE_Y_N:.*]] = arith.uitofp %[[ISCALE_Y_N]] // CHECK: %[[SCALE_Y_D:.*]] = arith.uitofp %[[ISCALE_Y_D]] - // CHECK: %[[OFFSET_Y:.*]] = arith.uitofp %[[IOFFSET_Y]] + // CHECK: %[[OFFSET_Y:.*]] = arith.sitofp %[[IOFFSET_Y]] // CHECK: %[[VAL_29:.*]] = arith.mulf %[[Y0]], %[[SCALE_Y_D]] // CHECK: %[[VAL_31:.*]] = arith.addf %[[VAL_29]], %[[OFFSET_Y]] // CHECK: %[[VAL_33:.*]] = arith.divf %[[VAL_31]], %[[SCALE_Y_N]] @@ -395,7 +395,7 @@ func.func @resize_bilinear_fp(%input: tensor<1x23x24x1xf32>) -> () { // CHECK: %[[X0:.+]] = arith.uitofp %[[X]] // CHECK: %[[SCALE_X_N:.*]] = arith.uitofp %[[ISCALE_X_N]] // CHECK: %[[SCALE_X_D:.*]] = arith.uitofp %[[ISCALE_X_D]] - // CHECK: %[[OFFSET_X:.*]] = arith.uitofp %[[IOFFSET_X]] + // CHECK: %[[OFFSET_X:.*]] = arith.sitofp %[[IOFFSET_X]] // CHECK: %[[VAL_30:.*]] = arith.mulf %[[X0]], %[[SCALE_X_D]] // CHECK: %[[VAL_32:.*]] = arith.addf %[[VAL_30]], %[[OFFSET_X]] // CHECK: %[[VAL_34:.*]] = arith.divf %[[VAL_32]], %[[SCALE_X_N]] -- 2.7.4