[Mlir-commits] [mlir] [mlir][intrange] Fix `arith.shl` inference in case of overflow (PR #91737)

Ivan Butygin llvmlistbot at llvm.org
Fri May 10 09:07:08 PDT 2024


================
@@ -548,6 +548,18 @@ mlir::intrange::inferShl(ArrayRef<ConstantIntRanges> argRanges) {
                         const APInt &r) -> std::optional<APInt> {
     return r.uge(r.getBitWidth()) ? std::optional<APInt>() : l.shl(r);
   };
+
+  // The minMax inference does not work when there is danger of overflow. In the
+  // signed case, this leads to the obvious problem that the sign bit might
+  // change. In the unsigned case, it also leads to problems because the largest
+  // LHS shifted by the largest RHS does not necessarily result in the largest
+  // result anymore.
+  bool signbitSafe =
----------------
Hardcode84 wrote:

nit: can we extract `lhs.smin()`/`rhs.umax()`/`lhs.smax()`/`rhs.umax()` to separate vars as they are used multiple times in this function?

https://github.com/llvm/llvm-project/pull/91737


More information about the Mlir-commits mailing list