[Mlir-commits] [mlir] f67e64d - [mlir][scf] Use getConstantIntValue instead of casting to ConstantOp (NFC) (#171242)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Dec 22 04:24:37 PST 2025


Author: lonely eagle
Date: 2025-12-22T20:24:34+08:00
New Revision: f67e64ded27adbdbd442a079aa1a7e517d0a978b

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

LOG: [mlir][scf] Use getConstantIntValue instead of casting to ConstantOp (NFC) (#171242)

Added: 
    

Modified: 
    mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
index 309121f520811..b9f5befc77409 100644
--- a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
+++ b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
@@ -421,9 +421,9 @@ static LogicalResult processParallelLoop(
                                   launchIndependent](Value val) -> Value {
     if (launchIndependent(val))
       return val;
-    if (auto constOp = val.getDefiningOp<arith::ConstantOp>())
-      return arith::ConstantOp::create(rewriter, constOp.getLoc(),
-                                       constOp.getValue());
+    if (std::optional<int64_t> constOp = getConstantIntValue(val))
+      return arith::ConstantIndexOp::create(rewriter, val.getLoc(),
+                                            constOp.value());
     return {};
   };
 
@@ -482,17 +482,15 @@ static LogicalResult processParallelLoop(
         // conditional. If the lower-bound is constant or defined before the
         // launch, we can use it in the launch bounds. Otherwise fail.
         if (!launchIndependent(lowerBound) &&
-            !isa_and_nonnull<arith::ConstantOp>(lowerBound.getDefiningOp()))
+            !getConstantIntValue(lowerBound).has_value())
           return failure();
         // The step must also be constant or defined outside of the loop nest.
-        if (!launchIndependent(step) &&
-            !isa_and_nonnull<arith::ConstantOp>(step.getDefiningOp()))
+        if (!launchIndependent(step) && !getConstantIntValue(step).has_value())
           return failure();
         // If the upper-bound is constant or defined before the launch, we can
         // use it in the launch bounds directly. Otherwise try derive a bound.
-        bool boundIsPrecise =
-            launchIndependent(upperBound) ||
-            isa_and_nonnull<arith::ConstantOp>(upperBound.getDefiningOp());
+        bool boundIsPrecise = launchIndependent(upperBound) ||
+                              getConstantIntValue(upperBound).has_value();
         {
           PatternRewriter::InsertionGuard guard(rewriter);
           rewriter.setInsertionPoint(launchOp);
@@ -621,11 +619,10 @@ ParallelToGpuLaunchLowering::matchAndRewrite(ParallelOp parallelOp,
   // Create a launch operation. We start with bound one for all grid/block
   // sizes. Those will be refined later as we discover them from mappings.
   Location loc = parallelOp.getLoc();
-  Value constantOne =
-      arith::ConstantIndexOp::create(rewriter, parallelOp.getLoc(), 1);
-  gpu::LaunchOp launchOp = gpu::LaunchOp::create(
-      rewriter, parallelOp.getLoc(), constantOne, constantOne, constantOne,
-      constantOne, constantOne, constantOne);
+  Value constantOne = arith::ConstantIndexOp::create(rewriter, loc, 1);
+  gpu::LaunchOp launchOp =
+      gpu::LaunchOp::create(rewriter, loc, constantOne, constantOne,
+                            constantOne, constantOne, constantOne, constantOne);
   rewriter.setInsertionPointToEnd(&launchOp.getBody().front());
   gpu::TerminatorOp::create(rewriter, loc);
   rewriter.setInsertionPointToStart(&launchOp.getBody().front());


        


More information about the Mlir-commits mailing list