[Mlir-commits] [flang] [mlir] [flang] Emit llvm.assume for array bounds constraints (PR #178811)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jan 30 02:59:49 PST 2026
================
@@ -2699,6 +2699,34 @@ struct XArrayCoorOpConversion
mlir::Value lb =
isShifted ? integerCast(loc, rewriter, idxTy, operands[shiftOffset])
: one;
+
+ // Emit array bounds assumes per Fortran 2018 standard section 9.5.3.3.2:
+ // "The value of each subscript expression shall be within the bounds for
+ // its dimension unless the array section has size zero."
+ // For non-boxed arrays with known shape, emit: assume(index >= lb) and
+ // assume(index <= lb + extent - 1).
+ // The llvm.array_bounds attribute marks these assumes for removal before
+ // vectorization to prevent IR bloat and avoid impacting cost models.
+ if (!baseIsBoxed && !coor.getShape().empty()) {
----------------
jeanPerier wrote:
Please also add cl::opt to control the emission of this info. As I understand llmv.assume are double edge swords as they provide more info at the cost of extra IR, which could have impact on inlining or other things.
I also think this should probably only be emitted at O2 and above, so you may want to add a new FIRToLLVMPassOptions field, set that in the driver when optimizations are enabled and use it here.
In such case the cl::opt can live in include/flang/Optimizer/Passes/CommandLineOpts.h and the pass option be set-up [here](https://github.com/llvm/llvm-project/blob/e6425a764f039f29dfc4096567d64d529930d026/flang/lib/Optimizer/Passes/Pipelines.cpp#L119) in using config.OptLevel and this new cl opt.
https://github.com/llvm/llvm-project/pull/178811
More information about the Mlir-commits
mailing list