[mlir] Avoid crash of UnsignedWhenEquivalent for no integer type.
authorjacquesguan <Jianjian.Guan@streamcomputing.com>
Thu, 5 Jan 2023 09:06:35 +0000 (17:06 +0800)
committerjacquesguan <Jianjian.Guan@streamcomputing.com>
Tue, 10 Jan 2023 02:05:02 +0000 (10:05 +0800)
Fixes https://github.com/llvm/llvm-project/issues/59617.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D141038

mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
mlir/test/Dialect/Arith/unsigned-when-equivalent.mlir

index 84311e4..f03ac01 100644 (file)
@@ -25,6 +25,8 @@ using namespace mlir::dataflow;
 
 IntegerValueRange IntegerValueRange::getMaxRange(Value value) {
   unsigned width = ConstantIntRanges::getStorageBitwidth(value.getType());
+  if (width == 0)
+    return {};
   APInt umin = APInt::getMinValue(width);
   APInt umax = APInt::getMaxValue(width);
   APInt smin = width != 0 ? APInt::getSignedMinValue(width) : umin;
index bbec4a1..63d7dc7 100644 (file)
@@ -96,3 +96,12 @@ func.func @dead_code() {
   %1 = arith.floordivsi %0, %0 : i8
   return
 }
+
+// Make sure not crash.
+// CHECK-LABEL: @no_integer_or_index
+func.func @no_integer_or_index() { 
+  // CHECK: arith.cmpi
+  %cst_0 = arith.constant dense<[0]> : vector<1xi32> 
+  %cmp = arith.cmpi slt, %cst_0, %cst_0 : vector<1xi32> 
+  return
+}