[Mlir-commits] [mlir] 3453580 - [mlir] UnsignedWhenEquivalent ignore dead code
Jeff Niu
llvmlistbot at llvm.org
Mon Dec 5 20:38:52 PST 2022
Author: Jeff Niu
Date: 2022-12-05T20:38:44-08:00
New Revision: 34535801d609923252237cd475606506a4ad244f
URL: https://github.com/llvm/llvm-project/commit/34535801d609923252237cd475606506a4ad244f
DIFF: https://github.com/llvm/llvm-project/commit/34535801d609923252237cd475606506a4ad244f.diff
LOG: [mlir] UnsignedWhenEquivalent ignore dead code
The pass was not checking for uninitialized states due to dead code.
This patch also makes LLVMFuncOp correctly return a null body when it is
external.
Fixes #58807
Depends on D139388
Reviewed By: rriddle
Differential Revision: https://reviews.llvm.org/D139389
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
mlir/test/Dialect/Arith/unsigned-when-equivalent.mlir
mlir/test/Dialect/LLVMIR/callgraph.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 55f13ba8480d1..c36e390377b32 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1337,8 +1337,9 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
/// Returns the result types of this function.
ArrayRef<Type> 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<Type> getCallableResults() { return getFunctionType().getReturnTypes(); }
diff --git a/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp b/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp
index b5752bd488b63..bb566f861524a 100644
--- a/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp
+++ b/mlir/lib/Dialect/Arith/Transforms/UnsignedWhenEquivalent.cpp
@@ -31,7 +31,7 @@ using namespace mlir::dataflow;
/// non-negative.
static LogicalResult staticallyNonNegative(DataFlowSolver &solver, Value v) {
auto *result = solver.lookupState<IntegerValueRangeLattice>(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
index 33b6bcb522764..f114acdbd0f86 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -2184,6 +2184,12 @@ LogicalResult LLVMFuncOp::verifyRegions() {
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
index 558c9f4be5b9e..bbec4a1e7d5db 100644
--- a/mlir/test/Dialect/Arith/unsigned-when-equivalent.mlir
+++ b/mlir/test/Dialect/Arith/unsigned-when-equivalent.mlir
@@ -86,3 +86,13 @@ func.func @preserves_structure(%arg0 : memref<8xindex>) {
}
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
index 268bcdfd053e3..c61fb2eca16c9 100644
--- a/mlir/test/Dialect/LLVMIR/callgraph.mlir
+++ b/mlir/test/Dialect/LLVMIR/callgraph.mlir
@@ -55,8 +55,7 @@ module attributes {"test.name" = "Normal function call"} {
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 : <Unknown-Callee-Node>
// CHECK: -- SCCs --
llvm.mlir.global external constant @_ZTIi() : !llvm.ptr<i8>
More information about the Mlir-commits
mailing list