[Mlir-commits] [mlir] 86c8ea9 - [mlir] Add check for value that might be null.

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Feb 16 00:02:45 PST 2023


Author: jacquesguan
Date: 2023-02-16T16:02:35+08:00
New Revision: 86c8ea9ac92221076518586852d13d6a1f414777

URL: https://github.com/llvm/llvm-project/commit/86c8ea9ac92221076518586852d13d6a1f414777
DIFF: https://github.com/llvm/llvm-project/commit/86c8ea9ac92221076518586852d13d6a1f414777.diff

LOG: [mlir] Add check for value that might be null.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
index 2823f27053040..aa079cff5cd7c 100644
--- a/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
@@ -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();

diff  --git a/mlir/test/Dialect/Arith/unsigned-when-equivalent.mlir b/mlir/test/Dialect/Arith/unsigned-when-equivalent.mlir
index 63d7dc739a9e0..ce77d3d2f4251 100644
--- a/mlir/test/Dialect/Arith/unsigned-when-equivalent.mlir
+++ b/mlir/test/Dialect/Arith/unsigned-when-equivalent.mlir
@@ -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> 
+}  


        


More information about the Mlir-commits mailing list