diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp --- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp +++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp @@ -619,11 +619,11 @@ mlir::Operation::operand_range args = call.getArgs(); const mlir::Value &dim = args[3]; + unsigned rank = getDimCount(args[0]); - if (!isZero(dim)) + if (!(isZero(dim) && rank > 0)) return; - unsigned rank = getDimCount(args[0]); mlir::SymbolRefAttr callee = call.getCalleeAttr(); fir::FirOpBuilder builder{getSimplificationBuilder(call, kindMap)};