[flang-commits] [flang] [flang][mlir][fir] Unroll inner loops in presence of user vectorizati… (PR #210820)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Wed Jul 22 04:08:18 PDT 2026


================
@@ -4078,6 +4078,23 @@ llvm::SmallVector<mlir::Region *> fir::DoLoopOp::getLoopRegions() {
   return {&getRegion()};
 }
 
+std::optional<llvm::APInt> fir::DoLoopOp::getStaticTripCount() {
+  auto getConstant = [](mlir::Value v) -> std::optional<std::int64_t> {
+    while (auto cvt = mlir::dyn_cast_or_null<fir::ConvertOp>(v.getDefiningOp()))
+      v = cvt.getValue();
+    return fir::getIntIfConstant(v);
+  };
+  std::optional<std::int64_t> lb = getConstant(getLowerBound());
+  std::optional<std::int64_t> ub = getConstant(getUpperBound());
+  std::optional<std::int64_t> step = getConstant(getStep());
+  if (!lb || !ub || !step || *step == 0)
+    return std::nullopt;
+  std::int64_t count = (*ub - *lb + *step) / *step;
+  if (count < 0)
+    count = 0;
+  return llvm::APInt(64, static_cast<std::uint64_t>(count));
----------------
tblah wrote:

https://github.com/llvm/llvm-project/pull/211233 this should help

https://github.com/llvm/llvm-project/pull/210820


More information about the flang-commits mailing list