[Mlir-commits] [mlir] ae7bda5 - [mlir][Linalg] Remove initial value for conditions.

Hanhan Wang llvmlistbot at llvm.org
Wed Mar 18 14:43:36 PDT 2020


Author: Hanhan Wang
Date: 2020-03-18T14:42:21-07:00
New Revision: ae7bda5dac76cd576f39c697c47101dca1a64d24

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

LOG: [mlir][Linalg] Remove initial value for conditions.

Summary:
Although bool and int1 are the same sometimes, using bool constant matches the
semantic better. In any cases, we don't have to care the type of conditions if
we remove the intial value. The type is determined automatically by the returned
type of logical operations.

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

Added: 
    

Modified: 
    mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp b/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
index 4dc41e2c87ae..817f0235ccff 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
@@ -185,9 +185,9 @@ class LinalgScopedEmitter<IndexedValueType, ConvOp> {
     if (!convOp.padding())
       return im(imIdx);
 
+    auto *context = ScopedContext::getContext();
     ValueHandle zeroIndex = std_constant_index(0);
-    SmallVector<ValueHandle, 8> conds = {
-        std_constant_int(/*value=*/1, /*width=*/1)};
+    SmallVector<ValueHandle, 8> conds;
     SmallVector<ValueHandle, 8> clampedImIdx;
     for (auto iter : llvm::enumerate(imIdx)) {
       int idx = iter.index();
@@ -201,13 +201,16 @@ class LinalgScopedEmitter<IndexedValueType, ConvOp> {
       using edsc::op::operator<;
       using edsc::op::operator>=;
       using edsc::op::operator||;
-      conds.push_back(conds.back() || (dim < zeroIndex));
-      ValueHandle bound = std_dim(convOp.input(), idx);
-      conds.push_back(conds.back() || (dim >= bound));
+      ValueHandle leftOutOfBound = dim < zeroIndex;
+      if (conds.empty())
+        conds.push_back(leftOutOfBound);
+      else
+        conds.push_back(conds.back() || leftOutOfBound);
+      ValueHandle rightBound = std_dim(convOp.input(), idx);
+      conds.push_back(conds.back() || (dim >= rightBound));
 
       // When padding is involed, the indices will only be shifted to negative,
       // so having a max op is enough.
-      auto *context = ScopedContext::getContext();
       auto maxMap = AffineMap::get(/*dimCount=*/1, 0,
                                    {getAffineDimExpr(/*position=*/0, context),
                                     getAffineConstantExpr(0, context)});
@@ -219,7 +222,8 @@ class LinalgScopedEmitter<IndexedValueType, ConvOp> {
     Type type = convOp.input().getType().cast<MemRefType>().getElementType();
     ValueHandle zero = std_constant(type, b.getZeroAttr(type));
     ValueHandle readInput = im(clampedImIdx);
-    return std_select(conds.back(), zero, readInput);
+    return conds.empty() ? readInput
+                         : std_select(conds.back(), zero, readInput);
   }
 
   static void emitScalarImplementation(ArrayRef<Value> allIvs, ConvOp convOp) {


        


More information about the Mlir-commits mailing list