[Mlir-commits] [mlir] 7f1cb43 - [mlir][sparse] simplify negi code generation with subi

Aart Bik llvmlistbot at llvm.org
Wed Sep 29 10:00:15 PDT 2021


Author: Aart Bik
Date: 2021-09-29T10:00:06-07:00
New Revision: 7f1cb43d60a517660c579ef22351bc3ca413d52d

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

LOG: [mlir][sparse] simplify negi code generation with subi

The lack of negi details leaked from merger class into codegen part.
Also, special case for vector code was not needed, the type can be used directly!

Reviewed By: bixia

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

Added: 
    

Modified: 
    mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
    mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
index 60272e240422f..373f3d1391a20 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
@@ -790,14 +790,6 @@ static Value genExp(Merger &merger, CodeGen &codegen, PatternRewriter &rewriter,
     return genInvariantValue(merger, codegen, rewriter, exp);
   Value v0 = genExp(merger, codegen, rewriter, op, merger.exp(exp).children.e0);
   Value v1 = genExp(merger, codegen, rewriter, op, merger.exp(exp).children.e1);
-  if (merger.exp(exp).kind == Kind::kNegI) {
-    // TODO: no negi in std, need to make zero explicit.
-    Type tp = op.getOutputTensorTypes()[0].getElementType();
-    v1 = v0;
-    v0 = rewriter.create<ConstantOp>(loc, tp, rewriter.getZeroAttr(tp));
-    if (codegen.curVecLength > 1)
-      v0 = genVectorInvariantValue(codegen, rewriter, v0);
-  }
   return merger.buildExp(rewriter, loc, exp, v0, v1);
 }
 

diff  --git a/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp b/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
index 4a18a0a7441c8..fd961516b4d95 100644
--- a/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
@@ -568,7 +568,7 @@ Optional<unsigned> Merger::buildTensorExp(linalg::GenericOp op, Value v) {
       if (isa<FloorFOp>(def))
         return addExp(kFloorF, e);
       if (isa<NegFOp>(def))
-        return addExp(kNegF, e); // TODO: no negi in std?
+        return addExp(kNegF, e); // no negi in std
       if (isa<FPTruncOp>(def))
         return addExp(kTruncF, e, v);
       if (isa<FPExtOp>(def))
@@ -651,9 +651,12 @@ Value Merger::buildExp(PatternRewriter &rewriter, Location loc, unsigned e,
     return rewriter.create<FloorFOp>(loc, v0);
   case kNegF:
     return rewriter.create<NegFOp>(loc, v0);
-  case kNegI:
-    assert(v1); // no negi in std
-    return rewriter.create<SubIOp>(loc, v0, v1);
+  case kNegI: // no negi in std
+    return rewriter.create<SubIOp>(
+        loc,
+        rewriter.create<ConstantOp>(loc, v0.getType(),
+                                    rewriter.getZeroAttr(v0.getType())),
+        v0);
   case kTruncF:
     return rewriter.create<FPTruncOp>(loc, v0, inferType(e, v0));
   case kExtF:


        


More information about the Mlir-commits mailing list