[MLIR] NFC. gpu.launch op argument const folder cleanup
authorUday Bondhugula <uday@polymagelabs.com>
Tue, 21 Sep 2021 08:53:22 +0000 (14:23 +0530)
committerUday Bondhugula <uday@polymagelabs.com>
Tue, 21 Sep 2021 09:00:03 +0000 (14:30 +0530)
NFC updates to gpu.launch op argument const folder.

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

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp

index 26ab955..7c1bf8e 100644 (file)
@@ -532,23 +532,19 @@ static ParseResult parseLaunchOp(OpAsmParser &parser, OperationState &result) {
                  parser.parseOptionalAttrDict(result.attributes));
 }
 
-/// Simplify the gpu.launch when the range of the thread and block IDs is
+/// Simplify the gpu.launch when the range of a thread or block ID is
 /// trivially known to be one.
 struct FoldLaunchArguments : public OpRewritePattern<LaunchOp> {
   using OpRewritePattern<LaunchOp>::OpRewritePattern;
   LogicalResult matchAndRewrite(LaunchOp op,
                                 PatternRewriter &rewriter) const override {
-    auto isTriviallyOne = [](Value size) {
-      IntegerAttr cst;
-      return matchPattern(size, m_Constant(&cst)) && cst.getInt() == 1;
-    };
-
     // If the range implies a single value for `id`, replace `id`'s uses by
     // zero.
     Value zero;
     bool simplified = false;
     auto constPropIdUses = [&](Value id, Value size) {
-      if (!isTriviallyOne(size))
+      // Check if size is trivially one.
+      if (!matchPattern(size, m_One()))
         return;
       if (!simplified) {
         // Create a zero value the first time.