[mlir] Add check for value that might be null.
authorjacquesguan <Jianjian.Guan@streamcomputing.com>
Fri, 13 Jan 2023 08:00:21 +0000 (16:00 +0800)
committerjacquesguan <Jianjian.Guan@streamcomputing.com>
Thu, 16 Feb 2023 08:02:35 +0000 (16:02 +0800)
Because we are generating uninitialized value for no integer type and use `isUninitialized()` to judge if it is valid after https://reviews.llvm.org/rG93f081c896536112e1ca8133991d23cb1134793a, we should check the value before use `getValue` to get it.
Fixes https://github.com/llvm/llvm-project/issues/59984.

Reviewed By: Mogball

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

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

index 2823f27..aa079cf 100644 (file)
@@ -128,6 +128,11 @@ void IntegerRangeAnalysis::visitNonControlFlowArguments(
     ArrayRef<IntegerValueRangeLattice *> argLattices, unsigned firstIndex) {
   if (auto inferrable = dyn_cast<InferIntRangeInterface>(op)) {
     LLVM_DEBUG(llvm::dbgs() << "Inferring ranges for " << *op << "\n");
+    // If the lattice on any operand is unitialized, bail out.
+    if (llvm::any_of(op->getOperands(), [&](Value value) {
+          return getLatticeElementFor(op, value)->getValue().isUninitialized();
+        }))
+      return;
     SmallVector<ConstantIntRanges> argRanges(
         llvm::map_range(op->getOperands(), [&](Value value) {
           return getLatticeElementFor(op, value)->getValue().getValue();
index 63d7dc7..ce77d3d 100644 (file)
@@ -105,3 +105,12 @@ func.func @no_integer_or_index() {
   %cmp = arith.cmpi slt, %cst_0, %cst_0 : vector<1xi32> 
   return
 }
+
+// CHECK-LABEL: @gpu_func
+func.func @gpu_func(%arg0: memref<2x32xf32>, %arg1: memref<2x32xf32>, %arg2: memref<32xf32>, %arg3: f32, %arg4: !gpu.async.token, %arg5: index, %arg6: index) -> memref<2x32xf32> {
+  %c1 = arith.constant 1 : index  
+  %2 = gpu.launch async [%arg4] blocks(%arg7, %arg8, %arg9) in (%arg13 = %c1, %arg14 = %c1, %arg15 = %c1) threads(%arg10, %arg11, %arg12) in (%arg16 = %c1, %arg17 = %c1, %arg18 = %c1) {
+    gpu.terminator
+  } 
+  return %arg1 : memref<2x32xf32> 
+}