diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -1337,8 +1337,9 @@ /// Returns the result types of this function. ArrayRef getResultTypes() { return getFunctionType().getReturnTypes(); } - /// Returns the callable region, which is the function body. - Region *getCallableRegion() { return &getBody(); } + /// Returns the callable region, which is the function body. If the function + /// is external, returns null. + Region *getCallableRegion(); /// Returns the callable result type, which is the function return type. ArrayRef getCallableResults() { return getFunctionType().getReturnTypes(); } diff --git a/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp b/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp --- a/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp +++ b/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp @@ -31,7 +31,7 @@ /// non-negative. static LogicalResult staticallyNonNegative(DataFlowSolver &solver, Value v) { auto *result = solver.lookupState(v); - if (!result) + if (!result || result->getValue().isUninitialized()) return failure(); const ConstantIntRanges &range = result->getValue().getValue(); return success(range.smin().isNonNegative()); diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -2184,6 +2184,12 @@ return success(); } +Region *LLVMFuncOp::getCallableRegion() { + if (isExternal()) + return nullptr; + return &getBody(); +} + //===----------------------------------------------------------------------===// // Verification for LLVM::ConstantOp. //===----------------------------------------------------------------------===// diff --git a/mlir/test/Dialect/Arith/unsigned-when-equivalent.mlir b/mlir/test/Dialect/Arith/unsigned-when-equivalent.mlir --- a/mlir/test/Dialect/Arith/unsigned-when-equivalent.mlir +++ b/mlir/test/Dialect/Arith/unsigned-when-equivalent.mlir @@ -86,3 +86,13 @@ } func.return } + +func.func private @external() -> i8 + +// CHECK-LABEL: @dead_code +func.func @dead_code() { + %0 = call @external() : () -> i8 + // CHECK: arith.floordivsi + %1 = arith.floordivsi %0, %0 : i8 + return +} diff --git a/mlir/test/Dialect/LLVMIR/callgraph.mlir b/mlir/test/Dialect/LLVMIR/callgraph.mlir --- a/mlir/test/Dialect/LLVMIR/callgraph.mlir +++ b/mlir/test/Dialect/LLVMIR/callgraph.mlir @@ -55,8 +55,7 @@ module attributes {"test.name" = "Invoke call"} { // CHECK-LABEL: ---- CallGraph ---- // CHECK: - Node : 'llvm.func' {{.*}} sym_name = "invokeLandingpad" - // CHECK-DAG: -- Call-Edge : 'llvm.func' {{.*}} sym_name = "foo" - // CHECK-DAG: -- Call-Edge : 'llvm.func' {{.*}} sym_name = "bar" + // CHECK-DAG: -- Call-Edge : // CHECK: -- SCCs -- llvm.mlir.global external constant @_ZTIi() : !llvm.ptr