[Mlir-commits] [mlir] cd2d736 - [mlir][tosa] Limit right-shift to 31 bits
Rob Suderman
llvmlistbot at llvm.org
Thu Jan 20 14:42:08 PST 2022
Author: Rob Suderman
Date: 2022-01-20T14:39:57-08:00
New Revision: cd2d7369639e70df17e7977ac3a4a5b7854043fa
URL: https://github.com/llvm/llvm-project/commit/cd2d7369639e70df17e7977ac3a4a5b7854043fa
DIFF: https://github.com/llvm/llvm-project/commit/cd2d7369639e70df17e7977ac3a4a5b7854043fa.diff
LOG: [mlir][tosa] Limit right-shift to 31 bits
Right shift can occur that is a 32-bit right shift. This is undefined behavior.
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D117732
Added:
Modified:
mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp b/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp
index ff82acec21e97..3fa471c37f312 100644
--- a/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp
+++ b/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp
@@ -46,8 +46,8 @@ static void computeMultiplierAndShiftTosaScale16(double scale,
// Shifting tops out at 63 bits. Right shift to make 63 bits the max.
if (shift > 63) {
- // Shifting the multiplier by more than 32-bits is unnecessary.
- multiplier = multiplier >> std::min<int32_t>(32, shift - 63);
+ // Shifting the multiplier by more than 31-bits is unnecessary.
+ multiplier = multiplier >> std::min<int32_t>(31, shift - 63);
shift = 63;
}
}
@@ -82,7 +82,7 @@ static void computeMultiplierAndShiftTosaScale32(double scale,
// Shifting tops out at 63 bits. Right shift to make 63 bits the max.
if (shift > 63) {
// Shifting the multiplier by more than 32-bits is unnecessary.
- multiplier = multiplier >> std::min<int32_t>(32, shift - 63);
+ multiplier = multiplier >> std::min<int32_t>(31, shift - 63);
shift = 63;
}
}
More information about the Mlir-commits
mailing list