Skip to content

Commit 90a5744

Browse files
authored
Remove redundant checks related to quantized type (#110604)
[APFloat::getSmallest](https://github.com/llvm/llvm-project/blob/915df1ae41652e2f595ce741dcd8f01878ef4e30/llvm/include/llvm/ADT/APFloat.h#L1060) (and similarly `APFloat:getLargest`) ``` APFloat getSmallest(const fltSemantics &Sem, bool Negative = false); ``` return the positive number when the default value for the second argument is used. With that being said, the check [QuantTypes.cpp#L325](https://github.com/llvm/llvm-project/blob/96f37ae45310885e09195be09d9c05e1c1dff86b/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp#L325) ```c++ if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale)) return emitError() << "illegal scale: " << scale; ``` is already covered by the check which follows [QuantTypes.cpp#L327](https://github.com/llvm/llvm-project/blob/96f37ae45310885e09195be09d9c05e1c1dff86b/mlir/lib/Dialect/Quant/IR/QuantTypes.cpp#L327) ```c++ if (scale < minScale || scale > maxScale) return emitError() << "scale out of expressed type range [" << minScale << ", " << maxScale << "]"; ``` given that range `[positive-smallest-finite-number, positive-largest-finite-number]` does not include `inf` and `nan`s. I propose to remove the redundant check. Any suggestion for improving the error message is welcome.
1 parent 3f50393 commit 90a5744

File tree

2 files changed

+1
-5
lines changed

2 files changed

+1
-5
lines changed

mlir/lib/Dialect/Quant/IR/QuantTypes.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,6 @@ LogicalResult UniformQuantizedType::verifyInvariants(
322322
// Verify scale.
323323
double minScale = getMinScale(expressedType);
324324
double maxScale = getMaxScale(expressedType);
325-
if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale))
326-
return emitError() << "illegal scale: " << scale;
327325
if (scale < minScale || scale > maxScale)
328326
return emitError() << "scale out of expressed type range [" << minScale
329327
<< ", " << maxScale << "]";
@@ -388,8 +386,6 @@ LogicalResult UniformQuantizedPerAxisType::verifyInvariants(
388386
double minScale = getMinScale(expressedType);
389387
double maxScale = getMaxScale(expressedType);
390388
for (double scale : scales) {
391-
if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale))
392-
return emitError() << "illegal scale: " << scale;
393389
if (scale < minScale || scale > maxScale)
394390
return emitError() << "scale out of expressed type range [" << minScale
395391
<< ", " << maxScale << "]";

mlir/test/Dialect/Quant/parse-uniform-invalid.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107

108108
// -----
109109
// Illegal scale: negative
110-
// expected-error@+1 {{illegal scale: -1.000000}}
110+
// expected-error@+1 {{scale out of expressed type range}}
111111
!qalias = !quant.uniform<i8<-4:3>:f32, -1.0:127>
112112

113113
// -----

0 commit comments

Comments
 (0)