[clang] [flang] [flang] integrate the option -flang-experimental-integer-overflow into -fno-wrapv (PR #110063)
Yusuke MINATO via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 25 17:25:56 PDT 2024
https://github.com/yus3710-fj created https://github.com/llvm/llvm-project/pull/110063
nsw is added to do-variable increment when -fno-wrapv is enabled as GFortran seems to do.
Therefore, the option introduced by #91579 isn't necessary any more.
Note that the feature of -flang-experimental-integer-overflow is now enabled by default.
>From c14087b7a7a3048f385b213b714650639555e68d Mon Sep 17 00:00:00 2001
From: Yusuke MINATO <minato.yusuke at fujitsu.com>
Date: Thu, 19 Sep 2024 14:44:49 +0900
Subject: [PATCH] [flang] integrate the option
-flang-experimental-integer-overflow into -fno-wrapv
nsw is added to do-variable increment when -fno-wrapv is enabled
as GFortran seems to do.
Therefore, the option introduced by PR91579 isn't necessary any
more.
Note that the feature of -flang-experimental-integer-overflow
is now enabled by default.
---
clang/include/clang/Driver/Options.td | 4 -
clang/lib/Driver/ToolChains/Flang.cpp | 1 -
flang/include/flang/Lower/LoweringOptions.def | 6 +-
.../flang/Optimizer/Transforms/Passes.h | 4 +-
.../flang/Optimizer/Transforms/Passes.td | 2 +-
flang/include/flang/Tools/CLOptions.inc | 4 +-
flang/include/flang/Tools/CrossToolHelpers.h | 2 +-
flang/lib/Frontend/CompilerInvocation.cpp | 6 -
flang/lib/Frontend/FrontendActions.cpp | 4 +-
flang/lib/Lower/Bridge.cpp | 2 +-
flang/lib/Lower/IO.cpp | 2 +-
.../Transforms/ControlFlowConverter.cpp | 4 +-
flang/test/Driver/frontend-forwarding.f90 | 4 +-
.../Fir/convert-to-llvm-openmp-and-fir.fir | 10 +-
flang/test/Fir/loop01.fir | 422 +++++++++---------
flang/test/Fir/loop02.fir | 4 +-
flang/test/Lower/HLFIR/goto-do-body.f90 | 4 +-
.../OpenMP/parallel-private-clause-fixes.f90 | 4 +-
...oop-reduction-allocatable-array-minmax.f90 | 4 +-
flang/test/Lower/OpenMP/wsloop-variable.f90 | 4 +-
flang/test/Lower/array-character.f90 | 2 +-
.../test/Lower/array-derived-assignments.f90 | 2 +-
flang/test/Lower/array-derived.f90 | 2 +-
.../array-elemental-calls-char-byval.f90 | 2 +-
.../test/Lower/array-elemental-calls-char.f90 | 2 +-
.../Lower/array-expression-assumed-size.f90 | 2 +-
flang/test/Lower/array-expression-slice-1.f90 | 2 +-
flang/test/Lower/array-substring.f90 | 80 ++--
flang/test/Lower/array-temp.f90 | 2 +-
flang/test/Lower/components.f90 | 2 +-
flang/test/Lower/do_loop.f90 | 112 ++---
flang/test/Lower/do_loop_unstructured.f90 | 376 ++++++++--------
flang/test/Lower/goto-do-body.f90 | 4 +-
flang/test/Lower/host-associated.f90 | 2 +-
flang/test/Lower/infinite_loop.f90 | 70 +--
flang/test/Lower/io-implied-do-fixes.f90 | 80 ++--
flang/test/Lower/loops2.f90 | 2 +-
flang/test/Lower/mixed_loops.f90 | 6 +-
flang/test/Lower/vector-subscript-io.f90 | 34 +-
flang/tools/bbc/bbc.cpp | 12 +-
40 files changed, 641 insertions(+), 652 deletions(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 23bd686a85f526..2dbcc66cee54b9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6742,10 +6742,6 @@ def flang_deprecated_no_hlfir : Flag<["-"], "flang-deprecated-no-hlfir">,
Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
HelpText<"Do not use HLFIR lowering (deprecated)">;
-def flang_experimental_integer_overflow : Flag<["-"], "flang-experimental-integer-overflow">,
- Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
- HelpText<"Add nsw flag to internal operations such as do-variable increment (experimental)">;
-
//===----------------------------------------------------------------------===//
// FLangOption + CoreOption + NoXarchOption
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 6ce79d27e98c48..c94ecad68cd279 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -148,7 +148,6 @@ void Flang::addCodegenOptions(const ArgList &Args,
Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
options::OPT_flang_deprecated_no_hlfir,
- options::OPT_flang_experimental_integer_overflow,
options::OPT_fno_ppc_native_vec_elem_order,
options::OPT_fppc_native_vec_elem_order});
}
diff --git a/flang/include/flang/Lower/LoweringOptions.def b/flang/include/flang/Lower/LoweringOptions.def
index 7594a57a262914..0b22e54b648e94 100644
--- a/flang/include/flang/Lower/LoweringOptions.def
+++ b/flang/include/flang/Lower/LoweringOptions.def
@@ -34,9 +34,9 @@ ENUM_LOWERINGOPT(NoPPCNativeVecElemOrder, unsigned, 1, 0)
/// On by default.
ENUM_LOWERINGOPT(Underscoring, unsigned, 1, 1)
-/// If true, add nsw flags to loop variable increments.
-/// Off by default.
-ENUM_LOWERINGOPT(NSWOnLoopVarInc, unsigned, 1, 0)
+/// If true, assume the behavior of integer overflow is defined
+/// (i.e. wraps around as two's complement). Off by default.
+ENUM_LOWERINGOPT(IntegerWrapAround, unsigned, 1, 0)
#undef LOWERINGOPT
#undef ENUM_LOWERINGOPT
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.h b/flang/include/flang/Optimizer/Transforms/Passes.h
index 3b2af3a3398108..e4dcb0060c778a 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.h
+++ b/flang/include/flang/Optimizer/Transforms/Passes.h
@@ -65,7 +65,7 @@ namespace fir {
std::unique_ptr<mlir::Pass> createAffineDemotionPass();
std::unique_ptr<mlir::Pass>
createArrayValueCopyPass(fir::ArrayValueCopyOptions options = {});
-std::unique_ptr<mlir::Pass> createCFGConversionPassWithNSW();
+std::unique_ptr<mlir::Pass> createCFGConversionPassWithoutNSW();
std::unique_ptr<mlir::Pass> createMemDataFlowOptPass();
std::unique_ptr<mlir::Pass> createPromoteToAffinePass();
std::unique_ptr<mlir::Pass>
@@ -82,7 +82,7 @@ createVScaleAttrPass(std::pair<unsigned, unsigned> vscaleAttr);
void populateCfgConversionRewrites(mlir::RewritePatternSet &patterns,
bool forceLoopToExecuteOnce = false,
- bool setNSW = false);
+ bool setNSW = true);
// declarative passes
#define GEN_PASS_REGISTRATION
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td
index bf75123e853779..a26810d65672ca 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.td
+++ b/flang/include/flang/Optimizer/Transforms/Passes.td
@@ -153,7 +153,7 @@ def CFGConversion : Pass<"cfg-conversion"> {
/*default=*/"false",
"force the body of a loop to execute at least once">,
Option<"setNSW", "set-nsw", "bool",
- /*default=*/"false",
+ /*default=*/"true",
"set nsw on loop variable increment">
];
}
diff --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc
index 04b7f0ba370b86..8bd9ce8e37afc3 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -162,10 +162,10 @@ inline void addCfgConversionPass(
mlir::PassManager &pm, const MLIRToLLVMPassPipelineConfig &config) {
if (config.NSWOnLoopVarInc)
addNestedPassToAllTopLevelOperationsConditionally(
- pm, disableCfgConversion, fir::createCFGConversionPassWithNSW);
+ pm, disableCfgConversion, fir::createCFGConversion);
else
addNestedPassToAllTopLevelOperationsConditionally(
- pm, disableCfgConversion, fir::createCFGConversion);
+ pm, disableCfgConversion, fir::createCFGConversionPassWithoutNSW);
}
inline void addAVC(
diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h
index 75fd783af237d0..dc890f0a825a9b 100644
--- a/flang/include/flang/Tools/CrossToolHelpers.h
+++ b/flang/include/flang/Tools/CrossToolHelpers.h
@@ -122,7 +122,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks {
bool NoSignedZerosFPMath =
false; ///< Set no-signed-zeros-fp-math attribute for functions.
bool UnsafeFPMath = false; ///< Set unsafe-fp-math attribute for functions.
- bool NSWOnLoopVarInc = false; ///< Add nsw flag to loop variable increments.
+ bool NSWOnLoopVarInc = true; ///< Add nsw flag to loop variable increments.
};
struct OffloadModuleOpts {
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 90c327546198b5..a2b29ab1b00f7d 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1305,12 +1305,6 @@ bool CompilerInvocation::createFromArgs(
invoc.loweringOpts.setNoPPCNativeVecElemOrder(true);
}
- // -flang-experimental-integer-overflow
- if (args.hasArg(
- clang::driver::options::OPT_flang_experimental_integer_overflow)) {
- invoc.loweringOpts.setNSWOnLoopVarInc(true);
- }
-
// Preserve all the remark options requested, i.e. -Rpass, -Rpass-missed or
// -Rpass-analysis. This will be used later when processing and outputting the
// remarks generated by LLVM in ExecuteCompilerInvocation.cpp.
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 267c3ceb44f33e..2abb6352145537 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -829,8 +829,8 @@ void CodeGenAction::generateLLVMIR() {
config.VScaleMax = vsr->second;
}
- if (ci.getInvocation().getLoweringOpts().getNSWOnLoopVarInc())
- config.NSWOnLoopVarInc = true;
+ if (ci.getInvocation().getLoweringOpts().getIntegerWrapAround())
+ config.NSWOnLoopVarInc = false;
// Create the pass pipeline
fir::createMLIRToLLVMPassPipeline(pm, config, getCurrentFile());
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index ebcb7613969661..4b275830035df9 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -2271,7 +2271,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
assert(!incrementLoopNestInfo.empty() && "empty loop nest");
mlir::Location loc = toLocation();
mlir::arith::IntegerOverflowFlags flags{};
- if (getLoweringOptions().getNSWOnLoopVarInc())
+ if (!getLoweringOptions().getIntegerWrapAround())
flags = bitEnumSet(flags, mlir::arith::IntegerOverflowFlags::nsw);
auto iofAttr = mlir::arith::IntegerOverflowFlagsAttr::get(
builder->getContext(), flags);
diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp
index 9e98b230b676f6..cc17cb93de5582 100644
--- a/flang/lib/Lower/IO.cpp
+++ b/flang/lib/Lower/IO.cpp
@@ -929,7 +929,7 @@ static void genIoLoop(Fortran::lower::AbstractConverter &converter,
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
mlir::Location loc = converter.getCurrentLocation();
mlir::arith::IntegerOverflowFlags flags{};
- if (converter.getLoweringOptions().getNSWOnLoopVarInc())
+ if (!converter.getLoweringOptions().getIntegerWrapAround())
flags = bitEnumSet(flags, mlir::arith::IntegerOverflowFlags::nsw);
auto iofAttr =
mlir::arith::IntegerOverflowFlagsAttr::get(builder.getContext(), flags);
diff --git a/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp b/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp
index 3b79d6d311b71c..d0946aebcf73ee 100644
--- a/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp
+++ b/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp
@@ -366,6 +366,6 @@ void fir::populateCfgConversionRewrites(mlir::RewritePatternSet &patterns,
patterns.getContext(), forceLoopToExecuteOnce, setNSW);
}
-std::unique_ptr<mlir::Pass> fir::createCFGConversionPassWithNSW() {
- return std::make_unique<CfgConversion>(true);
+std::unique_ptr<mlir::Pass> fir::createCFGConversionPassWithoutNSW() {
+ return std::make_unique<CfgConversion>(false);
}
diff --git a/flang/test/Driver/frontend-forwarding.f90 b/flang/test/Driver/frontend-forwarding.f90
index 35adb47b56861e..ac232672b57a33 100644
--- a/flang/test/Driver/frontend-forwarding.f90
+++ b/flang/test/Driver/frontend-forwarding.f90
@@ -14,12 +14,12 @@
! RUN: -fno-signed-zeros \
! RUN: -fassociative-math \
! RUN: -freciprocal-math \
+! RUN: -fno-strict-overflow \
! RUN: -fomit-frame-pointer \
! RUN: -fpass-plugin=Bye%pluginext \
! RUN: -fversion-loops-for-stride \
! RUN: -flang-experimental-hlfir \
! RUN: -flang-deprecated-no-hlfir \
-! RUN: -flang-experimental-integer-overflow \
! RUN: -fno-ppc-native-vector-element-order \
! RUN: -fppc-native-vector-element-order \
! RUN: -mllvm -print-before-all \
@@ -51,7 +51,6 @@
! CHECK: "-fversion-loops-for-stride"
! CHECK: "-flang-experimental-hlfir"
! CHECK: "-flang-deprecated-no-hlfir"
-! CHECK: "-flang-experimental-integer-overflow"
! CHECK: "-fno-ppc-native-vector-element-order"
! CHECK: "-fppc-native-vector-element-order"
! CHECK: "-Rpass"
@@ -63,4 +62,5 @@
! CHECK: "-Rpass=inline"
! CHECK: "-mframe-pointer=none"
! CHECK: "-mllvm" "-print-before-all"
+! CHECK: "-fwrapv"
! CHECK: "-save-temps=obj"
diff --git a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
index 4b9afd5675ea31..9d63a9da3e7b08 100644
--- a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
+++ b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
@@ -364,10 +364,10 @@ func.func @_QPopenmp_target_data_region() {
%9 = arith.subi %8, %c1_i64 : i64
%10 = fir.coordinate_of %0, %9 : (!fir.ref<!fir.array<1024xi32>>, i64) -> !fir.ref<i32>
fir.store %6 to %10 : !fir.ref<i32>
- %11 = arith.addi %arg0, %c1 : index
+ %11 = arith.addi %arg0, %c1 overflow<nsw> : index
%12 = fir.convert %c1 : (index) -> i32
%13 = fir.load %1 : !fir.ref<i32>
- %14 = arith.addi %13, %12 : i32
+ %14 = arith.addi %13, %12 overflow<nsw> : i32
fir.result %11, %14 : index, i32
}
fir.store %5#1 to %1 : !fir.ref<i32>
@@ -410,11 +410,11 @@ func.func @_QPopenmp_target_data_region() {
// CHECK: %[[VAL_21:.*]] = llvm.sub %[[VAL_19]], %[[VAL_20]] : i64
// CHECK: %[[VAL_22:.*]] = llvm.getelementptr %[[VAL_1]][0, %[[VAL_21]]] : (!llvm.ptr, i64) -> !llvm.ptr
// CHECK: llvm.store %[[VAL_17]], %[[VAL_22]] : i32, !llvm.ptr
-// CHECK: %[[VAL_23:.*]] = llvm.add %[[VAL_12]], %[[VAL_8]] : i64
+// CHECK: %[[VAL_23:.*]] = llvm.add %[[VAL_12]], %[[VAL_8]] overflow<nsw> : i64
// CHECK: %[[VAL_24:.*]] = llvm.trunc %[[VAL_8]] : i64 to i32
// CHECK: %[[VAL_25:.*]] = llvm.load %[[VAL_3]] : !llvm.ptr -> i32
-// CHECK: %[[VAL_26:.*]] = llvm.add %[[VAL_25]], %[[VAL_24]] : i32
-// CHECK: %[[VAL_27:.*]] = llvm.add %[[VAL_12]], %[[VAL_8]] : i64
+// CHECK: %[[VAL_26:.*]] = llvm.add %[[VAL_25]], %[[VAL_24]] overflow<nsw> : i32
+// CHECK: %[[VAL_27:.*]] = llvm.add %[[VAL_12]], %[[VAL_8]] overflow<nsw> : i64
// CHECK: %[[VAL_28:.*]] = llvm.mlir.constant(1 : index) : i64
// CHECK: %[[VAL_29:.*]] = llvm.sub %[[VAL_14]], %[[VAL_28]] : i64
// CHECK: llvm.br ^bb1(%[[VAL_27]], %[[VAL_26]], %[[VAL_29]] : i64, i32, i64)
diff --git a/flang/test/Fir/loop01.fir b/flang/test/Fir/loop01.fir
index c1cbb522c378c0..46324480141615 100644
--- a/flang/test/Fir/loop01.fir
+++ b/flang/test/Fir/loop01.fir
@@ -1,5 +1,5 @@
// RUN: fir-opt --split-input-file --cfg-conversion %s | FileCheck %s
-// RUN: fir-opt --split-input-file --cfg-conversion="set-nsw=true" %s | FileCheck %s --check-prefix=NSW
+// RUN: fir-opt --split-input-file --cfg-conversion="set-nsw=false" %s | FileCheck %s --check-prefix=NO-NSW
func.func @x(%lb : index, %ub : index, %step : index, %b : i1, %addr : !fir.ref<index>) {
fir.do_loop %iv = %lb to %ub step %step unordered {
@@ -35,7 +35,7 @@ func.func private @f2() -> i1
// CHECK: fir.store %[[VAL_12]] to %[[VAL_4]] : !fir.ref<index>
// CHECK: br ^bb5
// CHECK: ^bb5:
-// CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_8]], %[[VAL_2]] : index
+// CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_8]], %[[VAL_2]] overflow<nsw> : index
// CHECK: %[[VAL_14:.*]] = arith.constant 1 : index
// CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_9]], %[[VAL_14]] : index
// CHECK: br ^bb1(%[[VAL_13]], %[[VAL_15]] : index, index)
@@ -44,33 +44,33 @@ func.func private @f2() -> i1
// CHECK: }
// CHECK: func private @f2() -> i1
-// NSW: func @x(%[[VAL_0:.*]]: index, %[[VAL_1:.*]]: index, %[[VAL_2:.*]]: index, %[[VAL_3:.*]]: i1, %[[VAL_4:.*]]: !fir.ref<index>) {
-// NSW: %[[VAL_5:.*]] = arith.subi %[[VAL_1]], %[[VAL_0]] : index
-// NSW: %[[VAL_6:.*]] = arith.addi %[[VAL_5]], %[[VAL_2]] : index
-// NSW: %[[VAL_7:.*]] = arith.divsi %[[VAL_6]], %[[VAL_2]] : index
-// NSW: br ^bb1(%[[VAL_0]], %[[VAL_7]] : index, index)
-// NSW: ^bb1(%[[VAL_8:.*]]: index, %[[VAL_9:.*]]: index):
-// NSW: %[[VAL_10:.*]] = arith.constant 0 : index
-// NSW: %[[VAL_11:.*]] = arith.cmpi sgt, %[[VAL_9]], %[[VAL_10]] : index
-// NSW: cond_br %[[VAL_11]], ^bb2, ^bb6
-// NSW: ^bb2:
-// NSW: cond_br %[[VAL_3]], ^bb3, ^bb4
-// NSW: ^bb3:
-// NSW: fir.store %[[VAL_8]] to %[[VAL_4]] : !fir.ref<index>
-// NSW: br ^bb5
-// NSW: ^bb4:
-// NSW: %[[VAL_12:.*]] = arith.constant 0 : index
-// NSW: fir.store %[[VAL_12]] to %[[VAL_4]] : !fir.ref<index>
-// NSW: br ^bb5
-// NSW: ^bb5:
-// NSW: %[[VAL_13:.*]] = arith.addi %[[VAL_8]], %[[VAL_2]] overflow<nsw> : index
-// NSW: %[[VAL_14:.*]] = arith.constant 1 : index
-// NSW: %[[VAL_15:.*]] = arith.subi %[[VAL_9]], %[[VAL_14]] : index
-// NSW: br ^bb1(%[[VAL_13]], %[[VAL_15]] : index, index)
-// NSW: ^bb6:
-// NSW: return
-// NSW: }
-// NSW: func private @f2() -> i1
+// NO-NSW: func @x(%[[VAL_0:.*]]: index, %[[VAL_1:.*]]: index, %[[VAL_2:.*]]: index, %[[VAL_3:.*]]: i1, %[[VAL_4:.*]]: !fir.ref<index>) {
+// NO-NSW: %[[VAL_5:.*]] = arith.subi %[[VAL_1]], %[[VAL_0]] : index
+// NO-NSW: %[[VAL_6:.*]] = arith.addi %[[VAL_5]], %[[VAL_2]] : index
+// NO-NSW: %[[VAL_7:.*]] = arith.divsi %[[VAL_6]], %[[VAL_2]] : index
+// NO-NSW: br ^bb1(%[[VAL_0]], %[[VAL_7]] : index, index)
+// NO-NSW: ^bb1(%[[VAL_8:.*]]: index, %[[VAL_9:.*]]: index):
+// NO-NSW: %[[VAL_10:.*]] = arith.constant 0 : index
+// NO-NSW: %[[VAL_11:.*]] = arith.cmpi sgt, %[[VAL_9]], %[[VAL_10]] : index
+// NO-NSW: cond_br %[[VAL_11]], ^bb2, ^bb6
+// NO-NSW: ^bb2:
+// NO-NSW: cond_br %[[VAL_3]], ^bb3, ^bb4
+// NO-NSW: ^bb3:
+// NO-NSW: fir.store %[[VAL_8]] to %[[VAL_4]] : !fir.ref<index>
+// NO-NSW: br ^bb5
+// NO-NSW: ^bb4:
+// NO-NSW: %[[VAL_12:.*]] = arith.constant 0 : index
+// NO-NSW: fir.store %[[VAL_12]] to %[[VAL_4]] : !fir.ref<index>
+// NO-NSW: br ^bb5
+// NO-NSW: ^bb5:
+// NO-NSW: %[[VAL_13:.*]] = arith.addi %[[VAL_8]], %[[VAL_2]] : index
+// NO-NSW: %[[VAL_14:.*]] = arith.constant 1 : index
+// NO-NSW: %[[VAL_15:.*]] = arith.subi %[[VAL_9]], %[[VAL_14]] : index
+// NO-NSW: br ^bb1(%[[VAL_13]], %[[VAL_15]] : index, index)
+// NO-NSW: ^bb6:
+// NO-NSW: return
+// NO-NSW: }
+// NO-NSW: func private @f2() -> i1
// -----
@@ -101,35 +101,35 @@ func.func private @f3(i16)
// CHECK: cond_br %[[VAL_14]], ^bb2, ^bb3
// CHECK: ^bb2:
// CHECK: %[[VAL_15:.*]] = fir.call @f2() : () -> i1
-// CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_4]], %[[VAL_3]] : index
+// CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_4]], %[[VAL_3]] overflow<nsw> : index
// CHECK: br ^bb1(%[[VAL_16]], %[[VAL_15]] : index, i1)
// CHECK: ^bb3:
// CHECK: return
// CHECK: }
// CHECK: func private @f3(i16)
-// NSW: func @x2(%[[VAL_0:.*]]: index, %[[VAL_1:.*]]: index, %[[VAL_2:.*]]: i1) {
-// NSW: %[[VAL_3:.*]] = arith.constant 1 : index
-// NSW: br ^bb1(%[[VAL_0]], %[[VAL_2]] : index, i1)
-// NSW: ^bb1(%[[VAL_4:.*]]: index, %[[VAL_5:.*]]: i1):
-// NSW: %[[VAL_6:.*]] = arith.constant 0 : index
-// NSW: %[[VAL_7:.*]] = arith.cmpi slt, %[[VAL_6]], %[[VAL_3]] : index
-// NSW: %[[VAL_8:.*]] = arith.cmpi sle, %[[VAL_4]], %[[VAL_1]] : index
-// NSW: %[[VAL_9:.*]] = arith.cmpi slt, %[[VAL_3]], %[[VAL_6]] : index
-// NSW: %[[VAL_10:.*]] = arith.cmpi sle, %[[VAL_1]], %[[VAL_4]] : index
-// NSW: %[[VAL_11:.*]] = arith.andi %[[VAL_7]], %[[VAL_8]] : i1
-// NSW: %[[VAL_12:.*]] = arith.andi %[[VAL_9]], %[[VAL_10]] : i1
-// NSW: %[[VAL_13:.*]] = arith.ori %[[VAL_11]], %[[VAL_12]] : i1
-// NSW: %[[VAL_14:.*]] = arith.andi %[[VAL_5]], %[[VAL_13]] : i1
-// NSW: cond_br %[[VAL_14]], ^bb2, ^bb3
-// NSW: ^bb2:
-// NSW: %[[VAL_15:.*]] = fir.call @f2() : () -> i1
-// NSW: %[[VAL_16:.*]] = arith.addi %[[VAL_4]], %[[VAL_3]] overflow<nsw> : index
-// NSW: br ^bb1(%[[VAL_16]], %[[VAL_15]] : index, i1)
-// NSW: ^bb3:
-// NSW: return
-// NSW: }
-// NSW: func private @f3(i16)
+// NO-NSW: func @x2(%[[VAL_0:.*]]: index, %[[VAL_1:.*]]: index, %[[VAL_2:.*]]: i1) {
+// NO-NSW: %[[VAL_3:.*]] = arith.constant 1 : index
+// NO-NSW: br ^bb1(%[[VAL_0]], %[[VAL_2]] : index, i1)
+// NO-NSW: ^bb1(%[[VAL_4:.*]]: index, %[[VAL_5:.*]]: i1):
+// NO-NSW: %[[VAL_6:.*]] = arith.constant 0 : index
+// NO-NSW: %[[VAL_7:.*]] = arith.cmpi slt, %[[VAL_6]], %[[VAL_3]] : index
+// NO-NSW: %[[VAL_8:.*]] = arith.cmpi sle, %[[VAL_4]], %[[VAL_1]] : index
+// NO-NSW: %[[VAL_9:.*]] = arith.cmpi slt, %[[VAL_3]], %[[VAL_6]] : index
+// NO-NSW: %[[VAL_10:.*]] = arith.cmpi sle, %[[VAL_1]], %[[VAL_4]] : index
+// NO-NSW: %[[VAL_11:.*]] = arith.andi %[[VAL_7]], %[[VAL_8]] : i1
+// NO-NSW: %[[VAL_12:.*]] = arith.andi %[[VAL_9]], %[[VAL_10]] : i1
+// NO-NSW: %[[VAL_13:.*]] = arith.ori %[[VAL_11]], %[[VAL_12]] : i1
+// NO-NSW: %[[VAL_14:.*]] = arith.andi %[[VAL_5]], %[[VAL_13]] : i1
+// NO-NSW: cond_br %[[VAL_14]], ^bb2, ^bb3
+// NO-NSW: ^bb2:
+// NO-NSW: %[[VAL_15:.*]] = fir.call @f2() : () -> i1
+// NO-NSW: %[[VAL_16:.*]] = arith.addi %[[VAL_4]], %[[VAL_3]] : index
+// NO-NSW: br ^bb1(%[[VAL_16]], %[[VAL_15]] : index, i1)
+// NO-NSW: ^bb3:
+// NO-NSW: return
+// NO-NSW: }
+// NO-NSW: func private @f3(i16)
// -----
@@ -159,7 +159,7 @@ func.func @x3(%lo : index, %up : index) -> i1 {
// CHECK: cond_br %[[VAL_11]], ^bb2, ^bb3
// CHECK: ^bb2:
// CHECK: %[[VAL_12:.*]] = fir.call @f2() : () -> i1
-// CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_7]], %[[VAL_2]] : index
+// CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_7]], %[[VAL_2]] overflow<nsw> : index
// CHECK: %[[VAL_14:.*]] = arith.constant 1 : index
// CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_9]], %[[VAL_14]] : index
// CHECK: br ^bb1(%[[VAL_13]], %[[VAL_12]], %[[VAL_15]] : index, i1, index)
@@ -167,28 +167,28 @@ func.func @x3(%lo : index, %up : index) -> i1 {
// CHECK: return %[[VAL_8]] : i1
// CHECK: }
-// NSW-LABEL: func @x3(
-// NSW-SAME: %[[VAL_0:.*]]: index,
-// NSW-SAME: %[[VAL_1:.*]]: index) -> i1 {
-// NSW: %[[VAL_2:.*]] = arith.constant 1 : index
-// NSW: %[[VAL_3:.*]] = arith.constant true
-// NSW: %[[VAL_4:.*]] = arith.subi %[[VAL_1]], %[[VAL_0]] : index
-// NSW: %[[VAL_5:.*]] = arith.addi %[[VAL_4]], %[[VAL_2]] : index
-// NSW: %[[VAL_6:.*]] = arith.divsi %[[VAL_5]], %[[VAL_2]] : index
-// NSW: br ^bb1(%[[VAL_0]], %[[VAL_3]], %[[VAL_6]] : index, i1, index)
-// NSW: ^bb1(%[[VAL_7:.*]]: index, %[[VAL_8:.*]]: i1, %[[VAL_9:.*]]: index):
-// NSW: %[[VAL_10:.*]] = arith.constant 0 : index
-// NSW: %[[VAL_11:.*]] = arith.cmpi sgt, %[[VAL_9]], %[[VAL_10]] : index
-// NSW: cond_br %[[VAL_11]], ^bb2, ^bb3
-// NSW: ^bb2:
-// NSW: %[[VAL_12:.*]] = fir.call @f2() : () -> i1
-// NSW: %[[VAL_13:.*]] = arith.addi %[[VAL_7]], %[[VAL_2]] overflow<nsw> : index
-// NSW: %[[VAL_14:.*]] = arith.constant 1 : index
-// NSW: %[[VAL_15:.*]] = arith.subi %[[VAL_9]], %[[VAL_14]] : index
-// NSW: br ^bb1(%[[VAL_13]], %[[VAL_12]], %[[VAL_15]] : index, i1, index)
-// NSW: ^bb3:
-// NSW: return %[[VAL_8]] : i1
-// NSW: }
+// NO-NSW-LABEL: func @x3(
+// NO-NSW-SAME: %[[VAL_0:.*]]: index,
+// NO-NSW-SAME: %[[VAL_1:.*]]: index) -> i1 {
+// NO-NSW: %[[VAL_2:.*]] = arith.constant 1 : index
+// NO-NSW: %[[VAL_3:.*]] = arith.constant true
+// NO-NSW: %[[VAL_4:.*]] = arith.subi %[[VAL_1]], %[[VAL_0]] : index
+// NO-NSW: %[[VAL_5:.*]] = arith.addi %[[VAL_4]], %[[VAL_2]] : index
+// NO-NSW: %[[VAL_6:.*]] = arith.divsi %[[VAL_5]], %[[VAL_2]] : index
+// NO-NSW: br ^bb1(%[[VAL_0]], %[[VAL_3]], %[[VAL_6]] : index, i1, index)
+// NO-NSW: ^bb1(%[[VAL_7:.*]]: index, %[[VAL_8:.*]]: i1, %[[VAL_9:.*]]: index):
+// NO-NSW: %[[VAL_10:.*]] = arith.constant 0 : index
+// NO-NSW: %[[VAL_11:.*]] = arith.cmpi sgt, %[[VAL_9]], %[[VAL_10]] : index
+// NO-NSW: cond_br %[[VAL_11]], ^bb2, ^bb3
+// NO-NSW: ^bb2:
+// NO-NSW: %[[VAL_12:.*]] = fir.call @f2() : () -> i1
+// NO-NSW: %[[VAL_13:.*]] = arith.addi %[[VAL_7]], %[[VAL_2]] : index
+// NO-NSW: %[[VAL_14:.*]] = arith.constant 1 : index
+// NO-NSW: %[[VAL_15:.*]] = arith.subi %[[VAL_9]], %[[VAL_14]] : index
+// NO-NSW: br ^bb1(%[[VAL_13]], %[[VAL_12]], %[[VAL_15]] : index, i1, index)
+// NO-NSW: ^bb3:
+// NO-NSW: return %[[VAL_8]] : i1
+// NO-NSW: }
// -----
@@ -227,7 +227,7 @@ func.func private @f4(i32) -> i1
// CHECK: cond_br %[[VAL_16]], ^bb2, ^bb3
// CHECK: ^bb2:
// CHECK: %[[VAL_17:.*]] = fir.call @f2() : () -> i1
-// CHECK: %[[VAL_18:.*]] = arith.addi %[[VAL_5]], %[[VAL_2]] : index
+// CHECK: %[[VAL_18:.*]] = arith.addi %[[VAL_5]], %[[VAL_2]] overflow<nsw> : index
// CHECK: br ^bb1(%[[VAL_18]], %[[VAL_6]], %[[VAL_17]] : index, i1, i1)
// CHECK: ^bb3:
// CHECK: %[[VAL_19:.*]] = arith.andi %[[VAL_6]], %[[VAL_7]] : i1
@@ -235,33 +235,33 @@ func.func private @f4(i32) -> i1
// CHECK: }
// CHECK: func private @f4(i32) -> i1
-// NSW-LABEL: func @y3(
-// NSW-SAME: %[[VAL_0:.*]]: index,
-// NSW-SAME: %[[VAL_1:.*]]: index) -> i1 {
-// NSW: %[[VAL_2:.*]] = arith.constant 1 : index
-// NSW: %[[VAL_3:.*]] = arith.constant true
-// NSW: %[[VAL_4:.*]] = fir.call @f2() : () -> i1
-// NSW: br ^bb1(%[[VAL_0]], %[[VAL_3]], %[[VAL_4]] : index, i1, i1)
-// NSW: ^bb1(%[[VAL_5:.*]]: index, %[[VAL_6:.*]]: i1, %[[VAL_7:.*]]: i1):
-// NSW: %[[VAL_8:.*]] = arith.constant 0 : index
-// NSW: %[[VAL_9:.*]] = arith.cmpi slt, %[[VAL_8]], %[[VAL_2]] : index
-// NSW: %[[VAL_10:.*]] = arith.cmpi sle, %[[VAL_5]], %[[VAL_1]] : index
-// NSW: %[[VAL_11:.*]] = arith.cmpi slt, %[[VAL_2]], %[[VAL_8]] : index
-// NSW: %[[VAL_12:.*]] = arith.cmpi sle, %[[VAL_1]], %[[VAL_5]] : index
-// NSW: %[[VAL_13:.*]] = arith.andi %[[VAL_9]], %[[VAL_10]] : i1
-// NSW: %[[VAL_14:.*]] = arith.andi %[[VAL_11]], %[[VAL_12]] : i1
-// NSW: %[[VAL_15:.*]] = arith.ori %[[VAL_13]], %[[VAL_14]] : i1
-// NSW: %[[VAL_16:.*]] = arith.andi %[[VAL_6]], %[[VAL_15]] : i1
-// NSW: cond_br %[[VAL_16]], ^bb2, ^bb3
-// NSW: ^bb2:
-// NSW: %[[VAL_17:.*]] = fir.call @f2() : () -> i1
-// NSW: %[[VAL_18:.*]] = arith.addi %[[VAL_5]], %[[VAL_2]] overflow<nsw> : index
-// NSW: br ^bb1(%[[VAL_18]], %[[VAL_6]], %[[VAL_17]] : index, i1, i1)
-// NSW: ^bb3:
-// NSW: %[[VAL_19:.*]] = arith.andi %[[VAL_6]], %[[VAL_7]] : i1
-// NSW: return %[[VAL_19]] : i1
-// NSW: }
-// NSW: func private @f4(i32) -> i1
+// NO-NSW-LABEL: func @y3(
+// NO-NSW-SAME: %[[VAL_0:.*]]: index,
+// NO-NSW-SAME: %[[VAL_1:.*]]: index) -> i1 {
+// NO-NSW: %[[VAL_2:.*]] = arith.constant 1 : index
+// NO-NSW: %[[VAL_3:.*]] = arith.constant true
+// NO-NSW: %[[VAL_4:.*]] = fir.call @f2() : () -> i1
+// NO-NSW: br ^bb1(%[[VAL_0]], %[[VAL_3]], %[[VAL_4]] : index, i1, i1)
+// NO-NSW: ^bb1(%[[VAL_5:.*]]: index, %[[VAL_6:.*]]: i1, %[[VAL_7:.*]]: i1):
+// NO-NSW: %[[VAL_8:.*]] = arith.constant 0 : index
+// NO-NSW: %[[VAL_9:.*]] = arith.cmpi slt, %[[VAL_8]], %[[VAL_2]] : index
+// NO-NSW: %[[VAL_10:.*]] = arith.cmpi sle, %[[VAL_5]], %[[VAL_1]] : index
+// NO-NSW: %[[VAL_11:.*]] = arith.cmpi slt, %[[VAL_2]], %[[VAL_8]] : index
+// NO-NSW: %[[VAL_12:.*]] = arith.cmpi sle, %[[VAL_1]], %[[VAL_5]] : index
+// NO-NSW: %[[VAL_13:.*]] = arith.andi %[[VAL_9]], %[[VAL_10]] : i1
+// NO-NSW: %[[VAL_14:.*]] = arith.andi %[[VAL_11]], %[[VAL_12]] : i1
+// NO-NSW: %[[VAL_15:.*]] = arith.ori %[[VAL_13]], %[[VAL_14]] : i1
+// NO-NSW: %[[VAL_16:.*]] = arith.andi %[[VAL_6]], %[[VAL_15]] : i1
+// NO-NSW: cond_br %[[VAL_16]], ^bb2, ^bb3
+// NO-NSW: ^bb2:
+// NO-NSW: %[[VAL_17:.*]] = fir.call @f2() : () -> i1
+// NO-NSW: %[[VAL_18:.*]] = arith.addi %[[VAL_5]], %[[VAL_2]] : index
+// NO-NSW: br ^bb1(%[[VAL_18]], %[[VAL_6]], %[[VAL_17]] : index, i1, i1)
+// NO-NSW: ^bb3:
+// NO-NSW: %[[VAL_19:.*]] = arith.andi %[[VAL_6]], %[[VAL_7]] : i1
+// NO-NSW: return %[[VAL_19]] : i1
+// NO-NSW: }
+// NO-NSW: func private @f4(i32) -> i1
// -----
@@ -291,7 +291,7 @@ func.func @x4(%lo : index, %up : index) -> index {
// CHECK: ^bb2:
// CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_6]] : (index) -> i32
// CHECK: %[[VAL_11:.*]] = fir.call @f4(%[[VAL_10]]) : (i32) -> i1
-// CHECK: %[[VAL_12:.*]] = arith.addi %[[VAL_6]], %[[VAL_2]] : index
+// CHECK: %[[VAL_12:.*]] = arith.addi %[[VAL_6]], %[[VAL_2]] overflow<nsw> : index
// CHECK: %[[VAL_13:.*]] = arith.constant 1 : index
// CHECK: %[[VAL_14:.*]] = arith.subi %[[VAL_7]], %[[VAL_13]] : index
// CHECK: br ^bb1(%[[VAL_12]], %[[VAL_14]] : index, index)
@@ -299,28 +299,28 @@ func.func @x4(%lo : index, %up : index) -> index {
// CHECK: return %[[VAL_6]] : index
// CHECK: }
-// NSW-LABEL: func @x4(
-// NSW-SAME: %[[VAL_0:.*]]: index,
-// NSW-SAME: %[[VAL_1:.*]]: index) -> index {
-// NSW: %[[VAL_2:.*]] = arith.constant 1 : index
-// NSW: %[[VAL_3:.*]] = arith.subi %[[VAL_1]], %[[VAL_0]] : index
-// NSW: %[[VAL_4:.*]] = arith.addi %[[VAL_3]], %[[VAL_2]] : index
-// NSW: %[[VAL_5:.*]] = arith.divsi %[[VAL_4]], %[[VAL_2]] : index
-// NSW: br ^bb1(%[[VAL_0]], %[[VAL_5]] : index, index)
-// NSW: ^bb1(%[[VAL_6:.*]]: index, %[[VAL_7:.*]]: index):
-// NSW: %[[VAL_8:.*]] = arith.constant 0 : index
-// NSW: %[[VAL_9:.*]] = arith.cmpi sgt, %[[VAL_7]], %[[VAL_8]] : index
-// NSW: cond_br %[[VAL_9]], ^bb2, ^bb3
-// NSW: ^bb2:
-// NSW: %[[VAL_10:.*]] = fir.convert %[[VAL_6]] : (index) -> i32
-// NSW: %[[VAL_11:.*]] = fir.call @f4(%[[VAL_10]]) : (i32) -> i1
-// NSW: %[[VAL_12:.*]] = arith.addi %[[VAL_6]], %[[VAL_2]] overflow<nsw> : index
-// NSW: %[[VAL_13:.*]] = arith.constant 1 : index
-// NSW: %[[VAL_14:.*]] = arith.subi %[[VAL_7]], %[[VAL_13]] : index
-// NSW: br ^bb1(%[[VAL_12]], %[[VAL_14]] : index, index)
-// NSW: ^bb3:
-// NSW: return %[[VAL_6]] : index
-// NSW: }
+// NO-NSW-LABEL: func @x4(
+// NO-NSW-SAME: %[[VAL_0:.*]]: index,
+// NO-NSW-SAME: %[[VAL_1:.*]]: index) -> index {
+// NO-NSW: %[[VAL_2:.*]] = arith.constant 1 : index
+// NO-NSW: %[[VAL_3:.*]] = arith.subi %[[VAL_1]], %[[VAL_0]] : index
+// NO-NSW: %[[VAL_4:.*]] = arith.addi %[[VAL_3]], %[[VAL_2]] : index
+// NO-NSW: %[[VAL_5:.*]] = arith.divsi %[[VAL_4]], %[[VAL_2]] : index
+// NO-NSW: br ^bb1(%[[VAL_0]], %[[VAL_5]] : index, index)
+// NO-NSW: ^bb1(%[[VAL_6:.*]]: index, %[[VAL_7:.*]]: index):
+// NO-NSW: %[[VAL_8:.*]] = arith.constant 0 : index
+// NO-NSW: %[[VAL_9:.*]] = arith.cmpi sgt, %[[VAL_7]], %[[VAL_8]] : index
+// NO-NSW: cond_br %[[VAL_9]], ^bb2, ^bb3
+// NO-NSW: ^bb2:
+// NO-NSW: %[[VAL_10:.*]] = fir.convert %[[VAL_6]] : (index) -> i32
+// NO-NSW: %[[VAL_11:.*]] = fir.call @f4(%[[VAL_10]]) : (i32) -> i1
+// NO-NSW: %[[VAL_12:.*]] = arith.addi %[[VAL_6]], %[[VAL_2]] : index
+// NO-NSW: %[[VAL_13:.*]] = arith.constant 1 : index
+// NO-NSW: %[[VAL_14:.*]] = arith.subi %[[VAL_7]], %[[VAL_13]] : index
+// NO-NSW: br ^bb1(%[[VAL_12]], %[[VAL_14]] : index, index)
+// NO-NSW: ^bb3:
+// NO-NSW: return %[[VAL_6]] : index
+// NO-NSW: }
// -----
@@ -356,37 +356,37 @@ func.func @y4(%lo : index, %up : index) -> index {
// CHECK: ^bb2:
// CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_4]] : (index) -> i32
// CHECK: %[[VAL_16:.*]] = fir.call @f4(%[[VAL_15]]) : (i32) -> i1
-// CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_4]], %[[VAL_2]] : index
+// CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_4]], %[[VAL_2]] overflow<nsw> : index
// CHECK: br ^bb1(%[[VAL_17]], %[[VAL_16]] : index, i1)
// CHECK: ^bb3:
// CHECK: return %[[VAL_4]] : index
// CHECK: }
-// NSW-LABEL: func @y4(
-// NSW-SAME: %[[VAL_0:.*]]: index,
-// NSW-SAME: %[[VAL_1:.*]]: index) -> index {
-// NSW: %[[VAL_2:.*]] = arith.constant 1 : index
-// NSW: %[[VAL_3:.*]] = arith.constant true
-// NSW: br ^bb1(%[[VAL_0]], %[[VAL_3]] : index, i1)
-// NSW: ^bb1(%[[VAL_4:.*]]: index, %[[VAL_5:.*]]: i1):
-// NSW: %[[VAL_6:.*]] = arith.constant 0 : index
-// NSW: %[[VAL_7:.*]] = arith.cmpi slt, %[[VAL_6]], %[[VAL_2]] : index
-// NSW: %[[VAL_8:.*]] = arith.cmpi sle, %[[VAL_4]], %[[VAL_1]] : index
-// NSW: %[[VAL_9:.*]] = arith.cmpi slt, %[[VAL_2]], %[[VAL_6]] : index
-// NSW: %[[VAL_10:.*]] = arith.cmpi sle, %[[VAL_1]], %[[VAL_4]] : index
-// NSW: %[[VAL_11:.*]] = arith.andi %[[VAL_7]], %[[VAL_8]] : i1
-// NSW: %[[VAL_12:.*]] = arith.andi %[[VAL_9]], %[[VAL_10]] : i1
-// NSW: %[[VAL_13:.*]] = arith.ori %[[VAL_11]], %[[VAL_12]] : i1
-// NSW: %[[VAL_14:.*]] = arith.andi %[[VAL_5]], %[[VAL_13]] : i1
-// NSW: cond_br %[[VAL_14]], ^bb2, ^bb3
-// NSW: ^bb2:
-// NSW: %[[VAL_15:.*]] = fir.convert %[[VAL_4]] : (index) -> i32
-// NSW: %[[VAL_16:.*]] = fir.call @f4(%[[VAL_15]]) : (i32) -> i1
-// NSW: %[[VAL_17:.*]] = arith.addi %[[VAL_4]], %[[VAL_2]] overflow<nsw> : index
-// NSW: br ^bb1(%[[VAL_17]], %[[VAL_16]] : index, i1)
-// NSW: ^bb3:
-// NSW: return %[[VAL_4]] : index
-// NSW: }
+// NO-NSW-LABEL: func @y4(
+// NO-NSW-SAME: %[[VAL_0:.*]]: index,
+// NO-NSW-SAME: %[[VAL_1:.*]]: index) -> index {
+// NO-NSW: %[[VAL_2:.*]] = arith.constant 1 : index
+// NO-NSW: %[[VAL_3:.*]] = arith.constant true
+// NO-NSW: br ^bb1(%[[VAL_0]], %[[VAL_3]] : index, i1)
+// NO-NSW: ^bb1(%[[VAL_4:.*]]: index, %[[VAL_5:.*]]: i1):
+// NO-NSW: %[[VAL_6:.*]] = arith.constant 0 : index
+// NO-NSW: %[[VAL_7:.*]] = arith.cmpi slt, %[[VAL_6]], %[[VAL_2]] : index
+// NO-NSW: %[[VAL_8:.*]] = arith.cmpi sle, %[[VAL_4]], %[[VAL_1]] : index
+// NO-NSW: %[[VAL_9:.*]] = arith.cmpi slt, %[[VAL_2]], %[[VAL_6]] : index
+// NO-NSW: %[[VAL_10:.*]] = arith.cmpi sle, %[[VAL_1]], %[[VAL_4]] : index
+// NO-NSW: %[[VAL_11:.*]] = arith.andi %[[VAL_7]], %[[VAL_8]] : i1
+// NO-NSW: %[[VAL_12:.*]] = arith.andi %[[VAL_9]], %[[VAL_10]] : i1
+// NO-NSW: %[[VAL_13:.*]] = arith.ori %[[VAL_11]], %[[VAL_12]] : i1
+// NO-NSW: %[[VAL_14:.*]] = arith.andi %[[VAL_5]], %[[VAL_13]] : i1
+// NO-NSW: cond_br %[[VAL_14]], ^bb2, ^bb3
+// NO-NSW: ^bb2:
+// NO-NSW: %[[VAL_15:.*]] = fir.convert %[[VAL_4]] : (index) -> i32
+// NO-NSW: %[[VAL_16:.*]] = fir.call @f4(%[[VAL_15]]) : (i32) -> i1
+// NO-NSW: %[[VAL_17:.*]] = arith.addi %[[VAL_4]], %[[VAL_2]] : index
+// NO-NSW: br ^bb1(%[[VAL_17]], %[[VAL_16]] : index, i1)
+// NO-NSW: ^bb3:
+// NO-NSW: return %[[VAL_4]] : index
+// NO-NSW: }
// -----
@@ -420,7 +420,7 @@ func.func @x5(%lo : index, %up : index) -> index {
// CHECK: ^bb2:
// CHECK: %[[VAL_12:.*]] = fir.call @f2() : () -> i1
// CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_12]] : (i1) -> i16
-// CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_7]], %[[VAL_2]] : index
+// CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_7]], %[[VAL_2]] overflow<nsw> : index
// CHECK: %[[VAL_15:.*]] = arith.constant 1 : index
// CHECK: %[[VAL_16:.*]] = arith.subi %[[VAL_9]], %[[VAL_15]] : index
// CHECK: br ^bb1(%[[VAL_14]], %[[VAL_13]], %[[VAL_16]] : index, i16, index)
@@ -429,30 +429,30 @@ func.func @x5(%lo : index, %up : index) -> index {
// CHECK: return %[[VAL_7]] : index
// CHECK: }
-// NSW-LABEL: func @x5(
-// NSW-SAME: %[[VAL_0:.*]]: index,
-// NSW-SAME: %[[VAL_1:.*]]: index) -> index {
-// NSW: %[[VAL_2:.*]] = arith.constant 1 : index
-// NSW: %[[VAL_3:.*]] = arith.constant 42 : i16
-// NSW: %[[VAL_4:.*]] = arith.subi %[[VAL_1]], %[[VAL_0]] : index
-// NSW: %[[VAL_5:.*]] = arith.addi %[[VAL_4]], %[[VAL_2]] : index
-// NSW: %[[VAL_6:.*]] = arith.divsi %[[VAL_5]], %[[VAL_2]] : index
-// NSW: br ^bb1(%[[VAL_0]], %[[VAL_3]], %[[VAL_6]] : index, i16, index)
-// NSW: ^bb1(%[[VAL_7:.*]]: index, %[[VAL_8:.*]]: i16, %[[VAL_9:.*]]: index):
-// NSW: %[[VAL_10:.*]] = arith.constant 0 : index
-// NSW: %[[VAL_11:.*]] = arith.cmpi sgt, %[[VAL_9]], %[[VAL_10]] : index
-// NSW: cond_br %[[VAL_11]], ^bb2, ^bb3
-// NSW: ^bb2:
-// NSW: %[[VAL_12:.*]] = fir.call @f2() : () -> i1
-// NSW: %[[VAL_13:.*]] = fir.convert %[[VAL_12]] : (i1) -> i16
-// NSW: %[[VAL_14:.*]] = arith.addi %[[VAL_7]], %[[VAL_2]] overflow<nsw> : index
-// NSW: %[[VAL_15:.*]] = arith.constant 1 : index
-// NSW: %[[VAL_16:.*]] = arith.subi %[[VAL_9]], %[[VAL_15]] : index
-// NSW: br ^bb1(%[[VAL_14]], %[[VAL_13]], %[[VAL_16]] : index, i16, index)
-// NSW: ^bb3:
-// NSW: fir.call @f3(%[[VAL_8]]) : (i16) -> ()
-// NSW: return %[[VAL_7]] : index
-// NSW: }
+// NO-NSW-LABEL: func @x5(
+// NO-NSW-SAME: %[[VAL_0:.*]]: index,
+// NO-NSW-SAME: %[[VAL_1:.*]]: index) -> index {
+// NO-NSW: %[[VAL_2:.*]] = arith.constant 1 : index
+// NO-NSW: %[[VAL_3:.*]] = arith.constant 42 : i16
+// NO-NSW: %[[VAL_4:.*]] = arith.subi %[[VAL_1]], %[[VAL_0]] : index
+// NO-NSW: %[[VAL_5:.*]] = arith.addi %[[VAL_4]], %[[VAL_2]] : index
+// NO-NSW: %[[VAL_6:.*]] = arith.divsi %[[VAL_5]], %[[VAL_2]] : index
+// NO-NSW: br ^bb1(%[[VAL_0]], %[[VAL_3]], %[[VAL_6]] : index, i16, index)
+// NO-NSW: ^bb1(%[[VAL_7:.*]]: index, %[[VAL_8:.*]]: i16, %[[VAL_9:.*]]: index):
+// NO-NSW: %[[VAL_10:.*]] = arith.constant 0 : index
+// NO-NSW: %[[VAL_11:.*]] = arith.cmpi sgt, %[[VAL_9]], %[[VAL_10]] : index
+// NO-NSW: cond_br %[[VAL_11]], ^bb2, ^bb3
+// NO-NSW: ^bb2:
+// NO-NSW: %[[VAL_12:.*]] = fir.call @f2() : () -> i1
+// NO-NSW: %[[VAL_13:.*]] = fir.convert %[[VAL_12]] : (i1) -> i16
+// NO-NSW: %[[VAL_14:.*]] = arith.addi %[[VAL_7]], %[[VAL_2]] : index
+// NO-NSW: %[[VAL_15:.*]] = arith.constant 1 : index
+// NO-NSW: %[[VAL_16:.*]] = arith.subi %[[VAL_9]], %[[VAL_15]] : index
+// NO-NSW: br ^bb1(%[[VAL_14]], %[[VAL_13]], %[[VAL_16]] : index, i16, index)
+// NO-NSW: ^bb3:
+// NO-NSW: fir.call @f3(%[[VAL_8]]) : (i16) -> ()
+// NO-NSW: return %[[VAL_7]] : index
+// NO-NSW: }
// -----
@@ -496,7 +496,7 @@ func.func @y5(%lo : index, %up : index) -> index {
// CHECK: ^bb2:
// CHECK: %[[VAL_17:.*]] = fir.call @f2() : () -> i1
// CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i1) -> i16
-// CHECK: %[[VAL_19:.*]] = arith.addi %[[VAL_5]], %[[VAL_2]] : index
+// CHECK: %[[VAL_19:.*]] = arith.addi %[[VAL_5]], %[[VAL_2]] overflow<nsw> : index
// CHECK: br ^bb1(%[[VAL_19]], %[[VAL_17]], %[[VAL_18]] : index, i1, i16)
// CHECK: ^bb3:
// CHECK: cond_br %[[VAL_6]], ^bb4, ^bb5
@@ -509,36 +509,36 @@ func.func @y5(%lo : index, %up : index) -> index {
// CHECK: return %[[VAL_5]] : index
// CHECK: }
-// NSW-LABEL: func @y5(
-// NSW-SAME: %[[VAL_0:.*]]: index,
-// NSW-SAME: %[[VAL_1:.*]]: index) -> index {
-// NSW: %[[VAL_2:.*]] = arith.constant 1 : index
-// NSW: %[[VAL_3:.*]] = arith.constant 42 : i16
-// NSW: %[[VAL_4:.*]] = arith.constant true
-// NSW: br ^bb1(%[[VAL_0]], %[[VAL_4]], %[[VAL_3]] : index, i1, i16)
-// NSW: ^bb1(%[[VAL_5:.*]]: index, %[[VAL_6:.*]]: i1, %[[VAL_7:.*]]: i16):
-// NSW: %[[VAL_8:.*]] = arith.constant 0 : index
-// NSW: %[[VAL_9:.*]] = arith.cmpi slt, %[[VAL_8]], %[[VAL_2]] : index
-// NSW: %[[VAL_10:.*]] = arith.cmpi sle, %[[VAL_5]], %[[VAL_1]] : index
-// NSW: %[[VAL_11:.*]] = arith.cmpi slt, %[[VAL_2]], %[[VAL_8]] : index
-// NSW: %[[VAL_12:.*]] = arith.cmpi sle, %[[VAL_1]], %[[VAL_5]] : index
-// NSW: %[[VAL_13:.*]] = arith.andi %[[VAL_9]], %[[VAL_10]] : i1
-// NSW: %[[VAL_14:.*]] = arith.andi %[[VAL_11]], %[[VAL_12]] : i1
-// NSW: %[[VAL_15:.*]] = arith.ori %[[VAL_13]], %[[VAL_14]] : i1
-// NSW: %[[VAL_16:.*]] = arith.andi %[[VAL_6]], %[[VAL_15]] : i1
-// NSW: cond_br %[[VAL_16]], ^bb2, ^bb3
-// NSW: ^bb2:
-// NSW: %[[VAL_17:.*]] = fir.call @f2() : () -> i1
-// NSW: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i1) -> i16
-// NSW: %[[VAL_19:.*]] = arith.addi %[[VAL_5]], %[[VAL_2]] overflow<nsw> : index
-// NSW: br ^bb1(%[[VAL_19]], %[[VAL_17]], %[[VAL_18]] : index, i1, i16)
-// NSW: ^bb3:
-// NSW: cond_br %[[VAL_6]], ^bb4, ^bb5
-// NSW: ^bb4:
-// NSW: %[[VAL_20:.*]] = arith.constant 0 : i32
-// NSW: %[[VAL_21:.*]] = fir.call @f4(%[[VAL_20]]) : (i32) -> i1
-// NSW: br ^bb5
-// NSW: ^bb5:
-// NSW: fir.call @f3(%[[VAL_7]]) : (i16) -> ()
-// NSW: return %[[VAL_5]] : index
-// NSW: }
+// NO-NSW-LABEL: func @y5(
+// NO-NSW-SAME: %[[VAL_0:.*]]: index,
+// NO-NSW-SAME: %[[VAL_1:.*]]: index) -> index {
+// NO-NSW: %[[VAL_2:.*]] = arith.constant 1 : index
+// NO-NSW: %[[VAL_3:.*]] = arith.constant 42 : i16
+// NO-NSW: %[[VAL_4:.*]] = arith.constant true
+// NO-NSW: br ^bb1(%[[VAL_0]], %[[VAL_4]], %[[VAL_3]] : index, i1, i16)
+// NO-NSW: ^bb1(%[[VAL_5:.*]]: index, %[[VAL_6:.*]]: i1, %[[VAL_7:.*]]: i16):
+// NO-NSW: %[[VAL_8:.*]] = arith.constant 0 : index
+// NO-NSW: %[[VAL_9:.*]] = arith.cmpi slt, %[[VAL_8]], %[[VAL_2]] : index
+// NO-NSW: %[[VAL_10:.*]] = arith.cmpi sle, %[[VAL_5]], %[[VAL_1]] : index
+// NO-NSW: %[[VAL_11:.*]] = arith.cmpi slt, %[[VAL_2]], %[[VAL_8]] : index
+// NO-NSW: %[[VAL_12:.*]] = arith.cmpi sle, %[[VAL_1]], %[[VAL_5]] : index
+// NO-NSW: %[[VAL_13:.*]] = arith.andi %[[VAL_9]], %[[VAL_10]] : i1
+// NO-NSW: %[[VAL_14:.*]] = arith.andi %[[VAL_11]], %[[VAL_12]] : i1
+// NO-NSW: %[[VAL_15:.*]] = arith.ori %[[VAL_13]], %[[VAL_14]] : i1
+// NO-NSW: %[[VAL_16:.*]] = arith.andi %[[VAL_6]], %[[VAL_15]] : i1
+// NO-NSW: cond_br %[[VAL_16]], ^bb2, ^bb3
+// NO-NSW: ^bb2:
+// NO-NSW: %[[VAL_17:.*]] = fir.call @f2() : () -> i1
+// NO-NSW: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i1) -> i16
+// NO-NSW: %[[VAL_19:.*]] = arith.addi %[[VAL_5]], %[[VAL_2]] : index
+// NO-NSW: br ^bb1(%[[VAL_19]], %[[VAL_17]], %[[VAL_18]] : index, i1, i16)
+// NO-NSW: ^bb3:
+// NO-NSW: cond_br %[[VAL_6]], ^bb4, ^bb5
+// NO-NSW: ^bb4:
+// NO-NSW: %[[VAL_20:.*]] = arith.constant 0 : i32
+// NO-NSW: %[[VAL_21:.*]] = fir.call @f4(%[[VAL_20]]) : (i32) -> i1
+// NO-NSW: br ^bb5
+// NO-NSW: ^bb5:
+// NO-NSW: fir.call @f3(%[[VAL_7]]) : (i16) -> ()
+// NO-NSW: return %[[VAL_5]] : index
+// NO-NSW: }
diff --git a/flang/test/Fir/loop02.fir b/flang/test/Fir/loop02.fir
index 50948e0e7aa6b5..fb209a9dfeb426 100644
--- a/flang/test/Fir/loop02.fir
+++ b/flang/test/Fir/loop02.fir
@@ -31,7 +31,7 @@ func.func private @y(%addr : !fir.ref<index>)
// CHECK: cond_br %[[VAL_13]], ^bb2, ^bb3
// CHECK: ^bb2:
// CHECK: fir.call @y(%[[VAL_0]]) : (!fir.ref<index>) -> ()
-// CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_10]], %[[VAL_2]] : index
+// CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_10]], %[[VAL_2]] overflow<nsw> : index
// CHECK: %[[VAL_15:.*]] = arith.constant 1 : index
// CHECK: %[[VAL_16:.*]] = arith.subi %[[VAL_11]], %[[VAL_15]] : index
// CHECK: br ^bb1(%[[VAL_14]], %[[VAL_16]] : index, index)
@@ -54,7 +54,7 @@ func.func private @y(%addr : !fir.ref<index>)
// NOOPT: cond_br %[[VAL_9]], ^bb2, ^bb3
// NOOPT: ^bb2:
// NOOPT: fir.call @y(%[[VAL_0]]) : (!fir.ref<index>) -> ()
-// NOOPT: %[[VAL_10:.*]] = arith.addi %[[VAL_6]], %[[VAL_2]] : index
+// NOOPT: %[[VAL_10:.*]] = arith.addi %[[VAL_6]], %[[VAL_2]] overflow<nsw> : index
// NOOPT: %[[VAL_11:.*]] = arith.constant 1 : index
// NOOPT: %[[VAL_12:.*]] = arith.subi %[[VAL_7]], %[[VAL_11]] : index
// NOOPT: br ^bb1(%[[VAL_10]], %[[VAL_12]] : index, index)
diff --git a/flang/test/Lower/HLFIR/goto-do-body.f90 b/flang/test/Lower/HLFIR/goto-do-body.f90
index 383b839e591e33..5f5b09ccb8f7dc 100644
--- a/flang/test/Lower/HLFIR/goto-do-body.f90
+++ b/flang/test/Lower/HLFIR/goto-do-body.f90
@@ -40,7 +40,7 @@ subroutine sub1()
! CHECK: %[[TMP5:.*]] = arith.subi %[[TMP4]], %[[C1]] : i32
! CHECK: fir.store %[[TMP5]] to %[[TRIP]] : !fir.ref<i32>
! CHECK: %[[TMP6:.*]] = fir.load %[[I]]#1 : !fir.ref<i32>
-! CHECK: %[[TMP7:.*]] = arith.addi %[[TMP6]], %[[C1]] : i32
+! CHECK: %[[TMP7:.*]] = arith.addi %[[TMP6]], %[[C1]] overflow<nsw> : i32
! CHECK: fir.store %[[TMP7]] to %[[I]]#1 : !fir.ref<i32>
! CHECK: cf.br ^[[HEADER]]
end do
@@ -104,7 +104,7 @@ subroutine sub2()
! CHECK: fir.store %[[TMP9]] to %[[TRIP]] : !fir.ref<i32>
! CHECK: %[[TMP10:.*]] = fir.load %[[I]]#1 : !fir.ref<i32>
! CHECK: %[[STEP_VAL:.*]] = fir.load %[[STEP_VAR]] : !fir.ref<i32>
-! CHECK: %[[TMP11:.*]] = arith.addi %[[TMP10]], %[[STEP_VAL]] : i32
+! CHECK: %[[TMP11:.*]] = arith.addi %[[TMP10]], %[[STEP_VAL]] overflow<nsw> : i32
! CHECK: fir.store %[[TMP11]] to %[[I]]#1 : !fir.ref<i32>
! CHECK: cf.br ^[[HEADER]]
end do
diff --git a/flang/test/Lower/OpenMP/parallel-private-clause-fixes.f90 b/flang/test/Lower/OpenMP/parallel-private-clause-fixes.f90
index 073146b8b2e87a..d43362e7a813de 100644
--- a/flang/test/Lower/OpenMP/parallel-private-clause-fixes.f90
+++ b/flang/test/Lower/OpenMP/parallel-private-clause-fixes.f90
@@ -82,10 +82,10 @@
! CHECK: %[[VAL_15:.*]] = fir.load %[[PRIV_J_DECL]]#0 : !fir.ref<i32>
! CHECK: %[[VAL_16:.*]] = arith.addi %[[LOAD]], %[[VAL_15]] : i32
! CHECK: hlfir.assign %[[VAL_16]] to %[[PRIV_X_DECL]]#0 : i32, !fir.ref<i32>
-! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_13]], %[[VAL_11]] : index
+! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_13]], %[[VAL_11]] overflow<nsw> : index
! CHECK: %[[STEPCAST:.*]] = fir.convert %[[VAL_11]] : (index) -> i32
! CHECK: %[[IVLOAD:.*]] = fir.load %[[PRIV_J_DECL]]#1 : !fir.ref<i32>
-! CHECK: %[[IVINC:.*]] = arith.addi %[[IVLOAD]], %[[STEPCAST]]
+! CHECK: %[[IVINC:.*]] = arith.addi %[[IVLOAD]], %[[STEPCAST]] overflow<nsw> :
! CHECK: fir.result %[[VAL_17]], %[[IVINC]] : index, i32
! CHECK: }
! CHECK: fir.store %[[VAL_12]]#1 to %[[PRIV_J_DECL]]#1 : !fir.ref<i32>
diff --git a/flang/test/Lower/OpenMP/wsloop-reduction-allocatable-array-minmax.f90 b/flang/test/Lower/OpenMP/wsloop-reduction-allocatable-array-minmax.f90
index 6b901bae539ff9..be8d5ac1bfbf98 100644
--- a/flang/test/Lower/OpenMP/wsloop-reduction-allocatable-array-minmax.f90
+++ b/flang/test/Lower/OpenMP/wsloop-reduction-allocatable-array-minmax.f90
@@ -206,10 +206,10 @@ program reduce15
! CHECK: %[[VAL_48:.*]] = fir.convert %[[VAL_47]] : (i32) -> i64
! CHECK: %[[VAL_49:.*]] = hlfir.designate %[[VAL_46]] (%[[VAL_48]]) : (!fir.box<!fir.heap<!fir.array<?xi32>>>, i64) -> !fir.ref<i32>
! CHECK: hlfir.assign %[[VAL_45]] to %[[VAL_49]] : i32, !fir.ref<i32>
-! CHECK: %[[VAL_50:.*]] = arith.addi %[[VAL_43]], %[[VAL_40]] : index
+! CHECK: %[[VAL_50:.*]] = arith.addi %[[VAL_43]], %[[VAL_40]] overflow<nsw> : index
! CHECK: %[[VAL_51:.*]] = fir.convert %[[VAL_40]] : (index) -> i32
! CHECK: %[[VAL_52:.*]] = fir.load %[[VAL_3]]#1 : !fir.ref<i32>
-! CHECK: %[[VAL_53:.*]] = arith.addi %[[VAL_52]], %[[VAL_51]] : i32
+! CHECK: %[[VAL_53:.*]] = arith.addi %[[VAL_52]], %[[VAL_51]] overflow<nsw> : i32
! CHECK: fir.result %[[VAL_50]], %[[VAL_53]] : index, i32
! CHECK: }
! CHECK: fir.store %[[VAL_54:.*]]#1 to %[[VAL_3]]#1 : !fir.ref<i32>
diff --git a/flang/test/Lower/OpenMP/wsloop-variable.f90 b/flang/test/Lower/OpenMP/wsloop-variable.f90
index 7bfb9274f389a3..985640e78ed08e 100644
--- a/flang/test/Lower/OpenMP/wsloop-variable.f90
+++ b/flang/test/Lower/OpenMP/wsloop-variable.f90
@@ -153,10 +153,10 @@ subroutine wsloop_variable_sub
!CHECK: %[[VAL_42:.*]] = arith.addi %[[VAL_40]], %[[VAL_41]] : i64
!CHECK: %[[VAL_43:.*]] = fir.convert %[[VAL_42]] : (i64) -> f32
!CHECK: hlfir.assign %[[VAL_43]] to %[[VAL_21]]#0 : f32, !fir.ref<f32>
-!CHECK: %[[VAL_44:.*]] = arith.addi %[[VAL_37]], %[[VAL_34]] : index
+!CHECK: %[[VAL_44:.*]] = arith.addi %[[VAL_37]], %[[VAL_34]] overflow<nsw> : index
!CHECK: %[[VAL_45:.*]] = fir.convert %[[VAL_34]] : (index) -> i64
!CHECK: %[[VAL_46:.*]] = fir.load %[[VAL_17]]#1 : !fir.ref<i64>
-!CHECK: %[[VAL_47:.*]] = arith.addi %[[VAL_46]], %[[VAL_45]] : i64
+!CHECK: %[[VAL_47:.*]] = arith.addi %[[VAL_46]], %[[VAL_45]] overflow<nsw> : i64
!CHECK: fir.result %[[VAL_44]], %[[VAL_47]] : index, i64
!CHECK: }
!CHECK: fir.store %[[VAL_48:.*]]#1 to %[[VAL_17]]#1 : !fir.ref<i64>
diff --git a/flang/test/Lower/array-character.f90 b/flang/test/Lower/array-character.f90
index c93ef4be30823c..53adc5c02958c3 100644
--- a/flang/test/Lower/array-character.f90
+++ b/flang/test/Lower/array-character.f90
@@ -1,4 +1,4 @@
-! RUN: bbc -hlfir=false %s -o - | fir-opt --canonicalize --cse | FileCheck %s
+! RUN: bbc -hlfir=false -fwrapv %s -o - | fir-opt --canonicalize --cse | FileCheck %s
! CHECK-LABEL: func @_QPissue(
! CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1>{{.*}}, %[[VAL_1:.*]]: !fir.boxchar<1>{{.*}}) {
diff --git a/flang/test/Lower/array-derived-assignments.f90 b/flang/test/Lower/array-derived-assignments.f90
index 71e61f651302a3..f4e51271d59368 100644
--- a/flang/test/Lower/array-derived-assignments.f90
+++ b/flang/test/Lower/array-derived-assignments.f90
@@ -1,5 +1,5 @@
! Test derived type assignment lowering inside array expression
-! RUN: bbc -hlfir=false %s -o - | FileCheck %s
+! RUN: bbc -hlfir=false -fwrapv %s -o - | FileCheck %s
module array_derived_assign
type simple_copy
diff --git a/flang/test/Lower/array-derived.f90 b/flang/test/Lower/array-derived.f90
index b5eb7621c90f10..a0c55f5d88255f 100644
--- a/flang/test/Lower/array-derived.f90
+++ b/flang/test/Lower/array-derived.f90
@@ -1,4 +1,4 @@
-! RUN: bbc -hlfir=false %s -o - | FileCheck %s
+! RUN: bbc -hlfir=false -fwrapv %s -o - | FileCheck %s
module cs
type r
diff --git a/flang/test/Lower/array-elemental-calls-char-byval.f90 b/flang/test/Lower/array-elemental-calls-char-byval.f90
index c321614e7fc5b5..682191fc789562 100644
--- a/flang/test/Lower/array-elemental-calls-char-byval.f90
+++ b/flang/test/Lower/array-elemental-calls-char-byval.f90
@@ -1,6 +1,6 @@
! Test lowering of elemental calls with character argument
! with the VALUE attribute.
-! RUN: bbc -hlfir=false -o - %s | FileCheck %s
+! RUN: bbc -hlfir=false -fwrapv -o - %s | FileCheck %s
module char_elem_byval
diff --git a/flang/test/Lower/array-elemental-calls-char.f90 b/flang/test/Lower/array-elemental-calls-char.f90
index 652e79232c1b5e..51c1eda2de7b1d 100644
--- a/flang/test/Lower/array-elemental-calls-char.f90
+++ b/flang/test/Lower/array-elemental-calls-char.f90
@@ -1,6 +1,6 @@
! Test lowering of elemental calls with character argument
! without the VALUE attribute.
-! RUN: bbc -hlfir=false -o - %s | FileCheck %s
+! RUN: bbc -hlfir=false -fwrapv -o - %s | FileCheck %s
module char_elem
diff --git a/flang/test/Lower/array-expression-assumed-size.f90 b/flang/test/Lower/array-expression-assumed-size.f90
index ae35da951538b8..2fbf315aff1148 100644
--- a/flang/test/Lower/array-expression-assumed-size.f90
+++ b/flang/test/Lower/array-expression-assumed-size.f90
@@ -1,5 +1,5 @@
! RUN: bbc --emit-fir -hlfir=false %s -o - | FileCheck %s
-! RUN: bbc -hlfir=false %s -o - | FileCheck --check-prefix=PostOpt %s
+! RUN: bbc -hlfir=false -fwrapv %s -o - | FileCheck --check-prefix=PostOpt %s
subroutine assumed_size_test(a)
diff --git a/flang/test/Lower/array-expression-slice-1.f90 b/flang/test/Lower/array-expression-slice-1.f90
index 15245090243290..b597814bc0d9f1 100644
--- a/flang/test/Lower/array-expression-slice-1.f90
+++ b/flang/test/Lower/array-expression-slice-1.f90
@@ -1,4 +1,4 @@
-! RUN: bbc -hlfir=false -o - --outline-intrinsics %s | FileCheck %s
+! RUN: bbc -hlfir=false -fwrapv -o - --outline-intrinsics %s | FileCheck %s
! CHECK-LABEL: func @_QQmain() attributes {fir.bindc_name = "p"} {
! CHECK-DAG: %[[VAL_0:.*]] = arith.constant 10 : index
diff --git a/flang/test/Lower/array-substring.f90 b/flang/test/Lower/array-substring.f90
index 2e283997e3e003..98fcf2f055e2f5 100644
--- a/flang/test/Lower/array-substring.f90
+++ b/flang/test/Lower/array-substring.f90
@@ -1,5 +1,5 @@
! RUN: bbc -hlfir=false %s -o - | FileCheck %s
-! RUN: bbc -hlfir=false -integer-overflow %s -o - | FileCheck %s --check-prefix=NSW
+! RUN: bbc -hlfir=false -fwrapv %s -o - | FileCheck %s --check-prefix=NO-NSW
! CHECK-LABEL: func @_QPtest(
! CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1>{{.*}}) -> !fir.array<1x!fir.logical<4>> {
@@ -32,8 +32,9 @@
! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (i1) -> !fir.logical<4>
! CHECK: %[[VAL_27:.*]] = fir.array_coor %[[VAL_8]](%[[VAL_9]]) %[[VAL_15]] : (!fir.ref<!fir.array<1x!fir.logical<4>>>, !fir.shape<1>, index) -> !fir.ref<!fir.logical<4>>
! CHECK: fir.store %[[VAL_26]] to %[[VAL_27]] : !fir.ref<!fir.logical<4>>
+! CHECK: %[[VAL_15_NSW:.*]] = arith.addi %[[VAL_12]], %[[VAL_1]] overflow<nsw> : index
! CHECK: %[[VAL_28:.*]] = arith.subi %[[VAL_13]], %[[VAL_1]] : index
-! CHECK: br ^bb1(%[[VAL_15]], %[[VAL_28]] : index, index)
+! CHECK: br ^bb1(%[[VAL_15_NSW]], %[[VAL_28]] : index, index)
! CHECK: ^bb3:
! CHECK: %[[VAL_29:.*]] = fir.load %[[VAL_8]] : !fir.ref<!fir.array<1x!fir.logical<4>>>
! CHECK: return %[[VAL_29]] : !fir.array<1x!fir.logical<4>>
@@ -47,41 +48,40 @@ function test(C)
test = C(1:1)(1:8) == (/'ABCDabcd'/)
end function test
-! NSW-LABEL: func @_QPtest(
-! NSW-SAME: %[[VAL_0:.*]]: !fir.boxchar<1>{{.*}}) -> !fir.array<1x!fir.logical<4>> {
-! NSW-DAG: %[[VAL_1:.*]] = arith.constant 1 : index
-! NSW-DAG: %[[VAL_2:.*]] = arith.constant 0 : index
-! NSW-DAG: %[[VAL_3:.*]] = arith.constant 0 : i32
-! NSW-DAG: %[[VAL_4:.*]] = arith.constant 8 : index
-! NSW: %[[VAL_6:.*]]:2 = fir.unboxchar %[[VAL_0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
-! NSW: %[[VAL_7:.*]] = fir.convert %[[VAL_6]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.array<1x!fir.char<1,12>>>
-! NSW: %[[VAL_8:.*]] = fir.alloca !fir.array<1x!fir.logical<4>> {bindc_name = "test", uniq_name = "_QFtestEtest"}
-! NSW: %[[VAL_9:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1>
-! NSW: %[[VAL_10:.*]] = fir.slice %[[VAL_1]], %[[VAL_1]], %[[VAL_1]] : (index, index, index) -> !fir.slice<1>
-! NSW: %[[VAL_11:.*]] = fir.address_of(@_QQ{{.*}}) : !fir.ref<!fir.array<1x!fir.char<1,8>>>
-! NSW: br ^bb1(%[[VAL_2]], %[[VAL_1]] : index, index)
-! NSW: ^bb1(%[[VAL_12:.*]]: index, %[[VAL_13:.*]]: index):
-! NSW: %[[VAL_14:.*]] = arith.cmpi sgt, %[[VAL_13]], %[[VAL_2]] : index
-! NSW: cond_br %[[VAL_14]], ^bb2, ^bb3
-! NSW: ^bb2:
-! NSW: %[[VAL_15:.*]] = arith.addi %[[VAL_12]], %[[VAL_1]] : index
-! NSW: %[[VAL_16:.*]] = fir.array_coor %[[VAL_7]](%[[VAL_9]]) {{\[}}%[[VAL_10]]] %[[VAL_15]] : (!fir.ref<!fir.array<1x!fir.char<1,12>>>, !fir.shape<1>, !fir.slice<1>, index) -> !fir.ref<!fir.char<1,12>>
-! NSW: %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (!fir.ref<!fir.char<1,12>>) -> !fir.ref<!fir.array<12x!fir.char<1>>>
-! NSW: %[[VAL_18:.*]] = fir.coordinate_of %[[VAL_17]], %[[VAL_2]] : (!fir.ref<!fir.array<12x!fir.char<1>>>, index) -> !fir.ref<!fir.char<1>>
-! NSW: %[[VAL_19:.*]] = fir.convert %[[VAL_18]] : (!fir.ref<!fir.char<1>>) -> !fir.ref<!fir.char<1,?>>
-! NSW: %[[VAL_20:.*]] = fir.array_coor %[[VAL_11]](%[[VAL_9]]) %[[VAL_15]] : (!fir.ref<!fir.array<1x!fir.char<1,8>>>, !fir.shape<1>, index) -> !fir.ref<!fir.char<1,8>>
-! NSW: %[[VAL_21:.*]] = fir.convert %[[VAL_19]] : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<i8>
-! NSW: %[[VAL_22:.*]] = fir.convert %[[VAL_20]] : (!fir.ref<!fir.char<1,8>>) -> !fir.ref<i8>
-! NSW: %[[VAL_23:.*]] = fir.convert %[[VAL_4]] : (index) -> i64
-! NSW: %[[VAL_24:.*]] = fir.call @_FortranACharacterCompareScalar1(%[[VAL_21]], %[[VAL_22]], %[[VAL_23]], %[[VAL_23]]) {{.*}}: (!fir.ref<i8>, !fir.ref<i8>, i64, i64) -> i32
-! NSW: %[[VAL_25:.*]] = arith.cmpi eq, %[[VAL_24]], %[[VAL_3]] : i32
-! NSW: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (i1) -> !fir.logical<4>
-! NSW: %[[VAL_27:.*]] = fir.array_coor %[[VAL_8]](%[[VAL_9]]) %[[VAL_15]] : (!fir.ref<!fir.array<1x!fir.logical<4>>>, !fir.shape<1>, index) -> !fir.ref<!fir.logical<4>>
-! NSW: fir.store %[[VAL_26]] to %[[VAL_27]] : !fir.ref<!fir.logical<4>>
-! NSW: %[[VAL_15_NSW:.*]] = arith.addi %[[VAL_12]], %[[VAL_1]] overflow<nsw> : index
-! NSW: %[[VAL_28:.*]] = arith.subi %[[VAL_13]], %[[VAL_1]] : index
-! NSW: br ^bb1(%[[VAL_15_NSW]], %[[VAL_28]] : index, index)
-! NSW: ^bb3:
-! NSW: %[[VAL_29:.*]] = fir.load %[[VAL_8]] : !fir.ref<!fir.array<1x!fir.logical<4>>>
-! NSW: return %[[VAL_29]] : !fir.array<1x!fir.logical<4>>
-! NSW: }
+! NO-NSW-LABEL: func @_QPtest(
+! NO-NSW-SAME: %[[VAL_0:.*]]: !fir.boxchar<1>{{.*}}) -> !fir.array<1x!fir.logical<4>> {
+! NO-NSW-DAG: %[[VAL_1:.*]] = arith.constant 1 : index
+! NO-NSW-DAG: %[[VAL_2:.*]] = arith.constant 0 : index
+! NO-NSW-DAG: %[[VAL_3:.*]] = arith.constant 0 : i32
+! NO-NSW-DAG: %[[VAL_4:.*]] = arith.constant 8 : index
+! NO-NSW: %[[VAL_6:.*]]:2 = fir.unboxchar %[[VAL_0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
+! NO-NSW: %[[VAL_7:.*]] = fir.convert %[[VAL_6]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.array<1x!fir.char<1,12>>>
+! NO-NSW: %[[VAL_8:.*]] = fir.alloca !fir.array<1x!fir.logical<4>> {bindc_name = "test", uniq_name = "_QFtestEtest"}
+! NO-NSW: %[[VAL_9:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1>
+! NO-NSW: %[[VAL_10:.*]] = fir.slice %[[VAL_1]], %[[VAL_1]], %[[VAL_1]] : (index, index, index) -> !fir.slice<1>
+! NO-NSW: %[[VAL_11:.*]] = fir.address_of(@_QQ{{.*}}) : !fir.ref<!fir.array<1x!fir.char<1,8>>>
+! NO-NSW: br ^bb1(%[[VAL_2]], %[[VAL_1]] : index, index)
+! NO-NSW: ^bb1(%[[VAL_12:.*]]: index, %[[VAL_13:.*]]: index):
+! NO-NSW: %[[VAL_14:.*]] = arith.cmpi sgt, %[[VAL_13]], %[[VAL_2]] : index
+! NO-NSW: cond_br %[[VAL_14]], ^bb2, ^bb3
+! NO-NSW: ^bb2:
+! NO-NSW: %[[VAL_15:.*]] = arith.addi %[[VAL_12]], %[[VAL_1]] : index
+! NO-NSW: %[[VAL_16:.*]] = fir.array_coor %[[VAL_7]](%[[VAL_9]]) {{\[}}%[[VAL_10]]] %[[VAL_15]] : (!fir.ref<!fir.array<1x!fir.char<1,12>>>, !fir.shape<1>, !fir.slice<1>, index) -> !fir.ref<!fir.char<1,12>>
+! NO-NSW: %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (!fir.ref<!fir.char<1,12>>) -> !fir.ref<!fir.array<12x!fir.char<1>>>
+! NO-NSW: %[[VAL_18:.*]] = fir.coordinate_of %[[VAL_17]], %[[VAL_2]] : (!fir.ref<!fir.array<12x!fir.char<1>>>, index) -> !fir.ref<!fir.char<1>>
+! NO-NSW: %[[VAL_19:.*]] = fir.convert %[[VAL_18]] : (!fir.ref<!fir.char<1>>) -> !fir.ref<!fir.char<1,?>>
+! NO-NSW: %[[VAL_20:.*]] = fir.array_coor %[[VAL_11]](%[[VAL_9]]) %[[VAL_15]] : (!fir.ref<!fir.array<1x!fir.char<1,8>>>, !fir.shape<1>, index) -> !fir.ref<!fir.char<1,8>>
+! NO-NSW: %[[VAL_21:.*]] = fir.convert %[[VAL_19]] : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<i8>
+! NO-NSW: %[[VAL_22:.*]] = fir.convert %[[VAL_20]] : (!fir.ref<!fir.char<1,8>>) -> !fir.ref<i8>
+! NO-NSW: %[[VAL_23:.*]] = fir.convert %[[VAL_4]] : (index) -> i64
+! NO-NSW: %[[VAL_24:.*]] = fir.call @_FortranACharacterCompareScalar1(%[[VAL_21]], %[[VAL_22]], %[[VAL_23]], %[[VAL_23]]) {{.*}}: (!fir.ref<i8>, !fir.ref<i8>, i64, i64) -> i32
+! NO-NSW: %[[VAL_25:.*]] = arith.cmpi eq, %[[VAL_24]], %[[VAL_3]] : i32
+! NO-NSW: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (i1) -> !fir.logical<4>
+! NO-NSW: %[[VAL_27:.*]] = fir.array_coor %[[VAL_8]](%[[VAL_9]]) %[[VAL_15]] : (!fir.ref<!fir.array<1x!fir.logical<4>>>, !fir.shape<1>, index) -> !fir.ref<!fir.logical<4>>
+! NO-NSW: fir.store %[[VAL_26]] to %[[VAL_27]] : !fir.ref<!fir.logical<4>>
+! NO-NSW: %[[VAL_28:.*]] = arith.subi %[[VAL_13]], %[[VAL_1]] : index
+! NO-NSW: br ^bb1(%[[VAL_15]], %[[VAL_28]] : index, index)
+! NO-NSW: ^bb3:
+! NO-NSW: %[[VAL_29:.*]] = fir.load %[[VAL_8]] : !fir.ref<!fir.array<1x!fir.logical<4>>>
+! NO-NSW: return %[[VAL_29]] : !fir.array<1x!fir.logical<4>>
+! NO-NSW: }
diff --git a/flang/test/Lower/array-temp.f90 b/flang/test/Lower/array-temp.f90
index 10c5ee91d44bda..718aef84a4e853 100644
--- a/flang/test/Lower/array-temp.f90
+++ b/flang/test/Lower/array-temp.f90
@@ -1,4 +1,4 @@
-! RUN: bbc -hlfir=false %s -o - | FileCheck %s
+! RUN: bbc -hlfir=false -fwrapv %s -o - | FileCheck %s
! CHECK-LABEL: func @_QPss1()
subroutine ss1
diff --git a/flang/test/Lower/components.f90 b/flang/test/Lower/components.f90
index e1582a8a31e0d4..28e836c5d10456 100644
--- a/flang/test/Lower/components.f90
+++ b/flang/test/Lower/components.f90
@@ -1,4 +1,4 @@
-! RUN: bbc -hlfir=false %s -o - | FileCheck %s
+! RUN: bbc -hlfir=false -fwrapv %s -o - | FileCheck %s
module components_test
type t1
diff --git a/flang/test/Lower/do_loop.f90 b/flang/test/Lower/do_loop.f90
index a46e6c947391b7..455f31fbbe2985 100644
--- a/flang/test/Lower/do_loop.f90
+++ b/flang/test/Lower/do_loop.f90
@@ -1,6 +1,6 @@
! RUN: bbc --use-desc-for-alloc=false -emit-fir -hlfir=false -o - %s | FileCheck %s
! RUN: %flang_fc1 -mllvm --use-desc-for-alloc=false -emit-fir -flang-deprecated-no-hlfir -o - %s | FileCheck %s
-! RUN: %flang_fc1 -mllvm --use-desc-for-alloc=false -emit-fir -flang-deprecated-no-hlfir -flang-experimental-integer-overflow -o - %s | FileCheck %s --check-prefix=NSW
+! RUN: %flang_fc1 -mllvm --use-desc-for-alloc=false -emit-fir -flang-deprecated-no-hlfir -fwrapv -o - %s | FileCheck %s --check-prefix=NO-NSW
! Simple tests for structured ordered loops with loop-control.
! Tests the structure of the loop, storage to index variable and return and
@@ -8,10 +8,10 @@
! Test a simple loop with the final value of the index variable read outside the loop
! CHECK-LABEL: simple_loop
-! NSW-LABEL: simple_loop
+! NO-NSW-LABEL: simple_loop
subroutine simple_loop
! CHECK: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsimple_loopEi"}
- ! NSW: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsimple_loopEi"}
+ ! NO-NSW: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsimple_loopEi"}
integer :: i
! CHECK: %[[C1:.*]] = arith.constant 1 : i32
@@ -21,18 +21,18 @@ subroutine simple_loop
! CHECK: %[[C1:.*]] = arith.constant 1 : index
! CHECK: %[[LB:.*]] = fir.convert %[[C1_CVT]] : (index) -> i32
! CHECK: %[[LI_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
- ! NSW: %[[LI_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
+ ! NO-NSW: %[[LI_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
! CHECK-SAME: %[[C1_CVT]] to %[[C5_CVT]] step %[[C1]]
! CHECK-SAME: iter_args(%[[IV:.*]] = %[[LB]]) -> (index, i32) {
do i=1,5
! CHECK: fir.store %[[IV]] to %[[I_REF]] : !fir.ref<i32>
- ! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[C1]] : index
- ! NSW: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[C1:.*]] overflow<nsw> : index
+ ! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[C1]] overflow<nsw> : index
+ ! NO-NSW: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[C1:[^ ]*]] : index
! CHECK: %[[STEPCAST:.*]] = fir.convert %[[C1]] : (index) -> i32
! CHECK: %[[IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
- ! NSW: %[[IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
- ! CHECK: %[[IVINC:.*]] = arith.addi %[[IVLOAD]], %[[STEPCAST]] : i32
- ! NSW: %[[IVINC:.*]] = arith.addi %[[IVLOAD]], %[[STEPCAST:.*]] overflow<nsw> : i32
+ ! NO-NSW: %[[IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
+ ! CHECK: %[[IVINC:.*]] = arith.addi %[[IVLOAD]], %[[STEPCAST]] overflow<nsw> : i32
+ ! NO-NSW: %[[IVINC:.*]] = arith.addi %[[IVLOAD]], %[[STEPCAST:[^ ]*]] : i32
! CHECK: fir.result %[[LI_NEXT]], %[[IVINC]] : index, i32
! CHECK: }
end do
@@ -44,14 +44,14 @@ subroutine simple_loop
! Test a 2-nested loop with a body composed of a reduction. Values are read from a 2d array.
! CHECK-LABEL: nested_loop
-! NSW-LABEL: nested_loop
+! NO-NSW-LABEL: nested_loop
subroutine nested_loop
! CHECK: %[[ARR_REF:.*]] = fir.alloca !fir.array<5x5xi32> {bindc_name = "arr", uniq_name = "_QFnested_loopEarr"}
! CHECK: %[[ASUM_REF:.*]] = fir.alloca i32 {bindc_name = "asum", uniq_name = "_QFnested_loopEasum"}
! CHECK: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFnested_loopEi"}
- ! NSW: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFnested_loopEi"}
+ ! NO-NSW: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFnested_loopEi"}
! CHECK: %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFnested_loopEj"}
- ! NSW: %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFnested_loopEj"}
+ ! NO-NSW: %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFnested_loopEj"}
integer :: asum, arr(5,5)
integer :: i, j
asum = 0
@@ -62,7 +62,7 @@ subroutine nested_loop
! CHECK: %[[ST_I:.*]] = arith.constant 1 : index
! CHECK: %[[I_LB:.*]] = fir.convert %[[S_I_CVT]] : (index) -> i32
! CHECK: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
- ! NSW: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
+ ! NO-NSW: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
! CHECK-SAME: %[[S_I_CVT]] to %[[E_I_CVT]] step %[[ST_I]]
! CHECK-SAME: iter_args(%[[I_IV:.*]] = %[[I_LB]]) -> (index, i32) {
do i=1,5
@@ -74,7 +74,7 @@ subroutine nested_loop
! CHECK: %[[ST_J:.*]] = arith.constant 1 : index
! CHECK: %[[J_LB:.*]] = fir.convert %[[S_J_CVT]] : (index) -> i32
! CHECK: %[[J_RES:.*]]:2 = fir.do_loop %[[LJ:[^ ]*]] =
- ! NSW: %[[J_RES:.*]]:2 = fir.do_loop %[[LJ:[^ ]*]] =
+ ! NO-NSW: %[[J_RES:.*]]:2 = fir.do_loop %[[LJ:[^ ]*]] =
! CHECK-SAME: %[[S_J_CVT]] to %[[E_J_CVT]] step %[[ST_J]]
! CHECK-SAME: iter_args(%[[J_IV:.*]] = %[[J_LB]]) -> (index, i32) {
do j=1,5
@@ -93,24 +93,24 @@ subroutine nested_loop
! CHECK: %[[ASUM_NEW:.*]] = arith.addi %[[ASUM]], %[[ARR_VAL]] : i32
! CHECK: fir.store %[[ASUM_NEW]] to %[[ASUM_REF]] : !fir.ref<i32>
asum = asum + arr(i,j)
- ! CHECK: %[[LJ_NEXT:.*]] = arith.addi %[[LJ]], %[[ST_J]] : index
- ! NSW: %[[LJ_NEXT:.*]] = arith.addi %[[LJ]], %[[ST_J:.*]] overflow<nsw> : index
+ ! CHECK: %[[LJ_NEXT:.*]] = arith.addi %[[LJ]], %[[ST_J]] overflow<nsw> : index
+ ! NO-NSW: %[[LJ_NEXT:.*]] = arith.addi %[[LJ]], %[[ST_J:[^ ]*]] : index
! CHECK: %[[J_STEPCAST:.*]] = fir.convert %[[ST_J]] : (index) -> i32
! CHECK: %[[J_IVLOAD:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
- ! NSW: %[[J_IVLOAD:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
- ! CHECK: %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST]] : i32
- ! NSW: %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST:.*]] overflow<nsw> : i32
+ ! NO-NSW: %[[J_IVLOAD:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
+ ! CHECK: %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST]] overflow<nsw> : i32
+ ! NO-NSW: %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST:[^ ]*]] : i32
! CHECK: fir.result %[[LJ_NEXT]], %[[J_IVINC]] : index, i32
! CHECK: }
end do
! CHECK: fir.store %[[J_RES]]#1 to %[[J_REF]] : !fir.ref<i32>
- ! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_I]] : index
- ! NSW: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_I:.*]] overflow<nsw> : index
+ ! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_I]] overflow<nsw> : index
+ ! NO-NSW: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_I:[^ ]*]] : index
! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[ST_I]] : (index) -> i32
! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
- ! NSW: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
- ! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i32
- ! NSW: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST:.*]] overflow<nsw> : i32
+ ! NO-NSW: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
+ ! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] overflow<nsw> : i32
+ ! NO-NSW: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST:[^ ]*]] : i32
! CHECK: fir.result %[[LI_NEXT]], %[[I_IVINC]] : index, i32
! CHECK: }
end do
@@ -119,11 +119,11 @@ subroutine nested_loop
! Test a downcounting loop
! CHECK-LABEL: down_counting_loop
-! NSW-LABEL: down_counting_loop
+! NO-NSW-LABEL: down_counting_loop
subroutine down_counting_loop()
integer :: i
! CHECK: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFdown_counting_loopEi"}
- ! NSW: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFdown_counting_loopEi"}
+ ! NO-NSW: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFdown_counting_loopEi"}
! CHECK: %[[C5:.*]] = arith.constant 5 : i32
! CHECK: %[[C5_CVT:.*]] = fir.convert %[[C5]] : (i32) -> index
@@ -133,18 +133,18 @@ subroutine down_counting_loop()
! CHECK: %[[CMINUS1_STEP_CVT:.*]] = fir.convert %[[CMINUS1]] : (i32) -> index
! CHECK: %[[I_LB:.*]] = fir.convert %[[C5_CVT]] : (index) -> i32
! CHECK: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
- ! NSW: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
+ ! NO-NSW: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
! CHECK-SAME: %[[C5_CVT]] to %[[C1_CVT]] step %[[CMINUS1_STEP_CVT]]
! CHECK-SAME: iter_args(%[[I_IV:.*]] = %[[I_LB]]) -> (index, i32) {
do i=5,1,-1
! CHECK: fir.store %[[I_IV]] to %[[I_REF]] : !fir.ref<i32>
- ! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[CMINUS1_STEP_CVT]] : index
- ! NSW: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[CMINUS1_STEP_CVT:.*]] overflow<nsw> : index
+ ! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[CMINUS1_STEP_CVT]] overflow<nsw> : index
+ ! NO-NSW: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[CMINUS1_STEP_CVT:[^ ]*]] : index
! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[CMINUS1_STEP_CVT]] : (index) -> i32
! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
- ! NSW: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
- ! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i32
- ! NSW: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST:.*]] overflow<nsw> : i32
+ ! NO-NSW: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
+ ! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] overflow<nsw> : i32
+ ! NO-NSW: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST:[^ ]*]] : i32
! CHECK: fir.result %[[LI_NEXT]], %[[I_IVINC]] : index, i32
! CHECK: }
end do
@@ -153,7 +153,7 @@ subroutine down_counting_loop()
! Test a general loop with a variable step
! CHECK-LABEL: loop_with_variable_step
-! NSW-LABEL: loop_with_variable_step
+! NO-NSW-LABEL: loop_with_variable_step
! CHECK-SAME: (%[[S_REF:.*]]: !fir.ref<i32> {fir.bindc_name = "s"}, %[[E_REF:.*]]: !fir.ref<i32> {fir.bindc_name = "e"}, %[[ST_REF:.*]]: !fir.ref<i32> {fir.bindc_name = "st"}) {
subroutine loop_with_variable_step(s,e,st)
integer :: s, e, st
@@ -166,18 +166,18 @@ subroutine loop_with_variable_step(s,e,st)
! CHECK: %[[ST_CVT:.*]] = fir.convert %[[ST]] : (i32) -> index
! CHECK: %[[I_LB:.*]] = fir.convert %[[S_CVT]] : (index) -> i32
! CHECK: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
- ! NSW: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
+ ! NO-NSW: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
! CHECK-SAME: %[[S_CVT]] to %[[E_CVT]] step %[[ST_CVT]]
! CHECK-SAME: iter_args(%[[I_IV:.*]] = %[[I_LB]]) -> (index, i32) {
do i=s,e,st
! CHECK: fir.store %[[I_IV]] to %[[I_REF]] : !fir.ref<i32>
- ! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT]] : index
- ! NSW: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT:.*]] overflow<nsw> : index
+ ! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT]] overflow<nsw> : index
+ ! NO-NSW: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT:[^ ]*]] : index
! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[ST_CVT]] : (index) -> i32
! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
- ! NSW: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
- ! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i32
- ! NSW: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST:.*]] overflow<nsw> : i32
+ ! NO-NSW: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
+ ! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] overflow<nsw> : i32
+ ! NO-NSW: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST:[^ ]*]] : i32
! CHECK: fir.result %[[LI_NEXT]], %[[I_IVINC]] : index, i32
! CHECK: }
end do
@@ -186,13 +186,13 @@ subroutine loop_with_variable_step(s,e,st)
! Test usage of pointer variables as index, start, end and step variables
! CHECK-LABEL: loop_with_pointer_variables
-! NSW-LABEL: loop_with_pointer_variables
+! NO-NSW-LABEL: loop_with_pointer_variables
! CHECK-SAME: (%[[S_REF:.*]]: !fir.ref<i32> {fir.bindc_name = "s", fir.target}, %[[E_REF:.*]]: !fir.ref<i32> {fir.bindc_name = "e", fir.target}, %[[ST_REF:.*]]: !fir.ref<i32> {fir.bindc_name = "st", fir.target}) {
subroutine loop_with_pointer_variables(s,e,st)
! CHECK: %[[E_PTR_REF:.*]] = fir.alloca !fir.ptr<i32> {uniq_name = "_QFloop_with_pointer_variablesEeptr.addr"}
! CHECK: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", fir.target, uniq_name = "_QFloop_with_pointer_variablesEi"}
! CHECK: %[[I_PTR_REF:.*]] = fir.alloca !fir.ptr<i32> {uniq_name = "_QFloop_with_pointer_variablesEiptr.addr"}
-! NSW: %[[I_PTR_REF:.*]] = fir.alloca !fir.ptr<i32> {uniq_name = "_QFloop_with_pointer_variablesEiptr.addr"}
+! NO-NSW: %[[I_PTR_REF:.*]] = fir.alloca !fir.ptr<i32> {uniq_name = "_QFloop_with_pointer_variablesEiptr.addr"}
! CHECK: %[[S_PTR_REF:.*]] = fir.alloca !fir.ptr<i32> {uniq_name = "_QFloop_with_pointer_variablesEsptr.addr"}
! CHECK: %[[ST_PTR_REF:.*]] = fir.alloca !fir.ptr<i32> {uniq_name = "_QFloop_with_pointer_variablesEstptr.addr"}
integer, target :: i
@@ -213,7 +213,7 @@ subroutine loop_with_pointer_variables(s,e,st)
stptr => st
! CHECK: %[[I_PTR:.*]] = fir.load %[[I_PTR_REF]] : !fir.ref<!fir.ptr<i32>>
-! NSW: %[[I_PTR:.*]] = fir.load %[[I_PTR_REF]] : !fir.ref<!fir.ptr<i32>>
+! NO-NSW: %[[I_PTR:.*]] = fir.load %[[I_PTR_REF]] : !fir.ref<!fir.ptr<i32>>
! CHECK: %[[S_PTR:.*]] = fir.load %[[S_PTR_REF]] : !fir.ref<!fir.ptr<i32>>
! CHECK: %[[S:.*]] = fir.load %[[S_PTR]] : !fir.ptr<i32>
! CHECK: %[[S_CVT:.*]] = fir.convert %[[S]] : (i32) -> index
@@ -225,18 +225,18 @@ subroutine loop_with_pointer_variables(s,e,st)
! CHECK: %[[ST_CVT:.*]] = fir.convert %[[ST]] : (i32) -> index
! CHECK: %[[I_LB:.*]] = fir.convert %[[S_CVT]] : (index) -> i32
! CHECK: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
-! NSW: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
+! NO-NSW: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
! CHECK-SAME: %[[S_CVT]] to %[[E_CVT]] step %[[ST_CVT]]
! CHECK-SAME: iter_args(%[[I_IV:.*]] = %[[I_LB]]) -> (index, i32) {
do iptr=sptr,eptr,stptr
! CHECK: fir.store %[[I_IV]] to %[[I_PTR]] : !fir.ptr<i32>
-! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT]] : index
-! NSW: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT:.*]] overflow<nsw> : index
+! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT]] overflow<nsw> : index
+! NO-NSW: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT:[^ ]*]] : index
! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[ST_CVT]] : (index) -> i32
! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_PTR]] : !fir.ptr<i32>
-! NSW: %[[I_IVLOAD:.*]] = fir.load %[[I_PTR]] : !fir.ptr<i32>
-! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i32
-! NSW: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST:.*]] overflow<nsw> : i32
+! NO-NSW: %[[I_IVLOAD:.*]] = fir.load %[[I_PTR]] : !fir.ptr<i32>
+! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] overflow<nsw> : i32
+! NO-NSW: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST:[^ ]*]] : i32
! CHECK: fir.result %[[LI_NEXT]], %[[I_IVINC]] : index, i32
end do
! CHECK: }
@@ -245,11 +245,11 @@ subroutine loop_with_pointer_variables(s,e,st)
! Test usage of non-default integer kind for loop control and loop index variable
! CHECK-LABEL: loop_with_non_default_integer
-! NSW-LABEL: loop_with_non_default_integer
+! NO-NSW-LABEL: loop_with_non_default_integer
! CHECK-SAME: (%[[S_REF:.*]]: !fir.ref<i64> {fir.bindc_name = "s"}, %[[E_REF:.*]]: !fir.ref<i64> {fir.bindc_name = "e"}, %[[ST_REF:.*]]: !fir.ref<i64> {fir.bindc_name = "st"}) {
subroutine loop_with_non_default_integer(s,e,st)
! CHECK: %[[I_REF:.*]] = fir.alloca i64 {bindc_name = "i", uniq_name = "_QFloop_with_non_default_integerEi"}
- ! NSW: %[[I_REF:.*]] = fir.alloca i64 {bindc_name = "i", uniq_name = "_QFloop_with_non_default_integerEi"}
+ ! NO-NSW: %[[I_REF:.*]] = fir.alloca i64 {bindc_name = "i", uniq_name = "_QFloop_with_non_default_integerEi"}
integer(kind=8):: i
! CHECK: %[[S:.*]] = fir.load %[[S_REF]] : !fir.ref<i64>
! CHECK: %[[S_CVT:.*]] = fir.convert %[[S]] : (i64) -> index
@@ -261,18 +261,18 @@ subroutine loop_with_non_default_integer(s,e,st)
! CHECK: %[[I_LB:.*]] = fir.convert %[[S_CVT]] : (index) -> i64
! CHECK: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
- ! NSW: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
+ ! NO-NSW: %[[I_RES:.*]]:2 = fir.do_loop %[[LI:[^ ]*]] =
! CHECK-SAME: %[[S_CVT]] to %[[E_CVT]] step %[[ST_CVT]]
! CHECK-SAME: iter_args(%[[I_IV:.*]] = %[[I_LB]]) -> (index, i64) {
do i=s,e,st
! CHECK: fir.store %[[I_IV]] to %[[I_REF]] : !fir.ref<i64>
- ! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT]] : index
- ! NSW: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT:.*]] overflow<nsw> : index
+ ! CHECK: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT]] overflow<nsw> : index
+ ! NO-NSW: %[[LI_NEXT:.*]] = arith.addi %[[LI]], %[[ST_CVT:[^ ]*]] : index
! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[ST_CVT]] : (index) -> i64
! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i64>
- ! NSW: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i64>
- ! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i64
- ! NSW: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST:.*]] overflow<nsw> : i64
+ ! NO-NSW: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i64>
+ ! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] overflow<nsw> : i64
+ ! NO-NSW: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST:[^ ]*]] : i64
! CHECK: fir.result %[[LI_NEXT]], %[[I_IVINC]] : index, i64
end do
! CHECK: }
diff --git a/flang/test/Lower/do_loop_unstructured.f90 b/flang/test/Lower/do_loop_unstructured.f90
index e1a669e09c9a89..7bf2a0d428c827 100644
--- a/flang/test/Lower/do_loop_unstructured.f90
+++ b/flang/test/Lower/do_loop_unstructured.f90
@@ -1,6 +1,6 @@
! RUN: bbc -emit-fir -hlfir=false -o - %s | FileCheck %s
! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -o - %s | FileCheck %s
-! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -flang-experimental-integer-overflow -o - %s | FileCheck %s --check-prefix=NSW
+! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fwrapv -o - %s | FileCheck %s --check-prefix=NO-NSW
! Tests for unstructured loops.
@@ -39,41 +39,41 @@ subroutine simple_unstructured()
! CHECK: fir.store %[[TRIP_VAR_NEXT]] to %[[TRIP_VAR_REF]] : !fir.ref<i32>
! CHECK: %[[LOOP_VAR:.*]] = fir.load %[[LOOP_VAR_REF]] : !fir.ref<i32>
! CHECK: %[[STEP_ONE_2:.*]] = arith.constant 1 : i32
-! CHECK: %[[LOOP_VAR_NEXT:.*]] = arith.addi %[[LOOP_VAR]], %[[STEP_ONE_2]] : i32
+! CHECK: %[[LOOP_VAR_NEXT:.*]] = arith.addi %[[LOOP_VAR]], %[[STEP_ONE_2]] overflow<nsw> : i32
! CHECK: fir.store %[[LOOP_VAR_NEXT]] to %[[LOOP_VAR_REF]] : !fir.ref<i32>
! CHECK: cf.br ^[[HEADER]]
! CHECK: ^[[EXIT]]:
! CHECK: return
-! NSW-LABEL: simple_unstructured
-! NSW: %[[TRIP_VAR_REF:.*]] = fir.alloca i32
-! NSW: %[[LOOP_VAR_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsimple_unstructuredEi"}
-! NSW: %[[ONE:.*]] = arith.constant 1 : i32
-! NSW: %[[HUNDRED:.*]] = arith.constant 100 : i32
-! NSW: %[[STEP_ONE:.*]] = arith.constant 1 : i32
-! NSW: %[[TMP1:.*]] = arith.subi %[[HUNDRED]], %[[ONE]] : i32
-! NSW: %[[TMP2:.*]] = arith.addi %[[TMP1]], %[[STEP_ONE]] : i32
-! NSW: %[[TRIP_COUNT:.*]] = arith.divsi %[[TMP2]], %[[STEP_ONE]] : i32
-! NSW: fir.store %[[TRIP_COUNT]] to %[[TRIP_VAR_REF]] : !fir.ref<i32>
-! NSW: fir.store %[[ONE]] to %[[LOOP_VAR_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[HEADER:.*]]
-! NSW: ^[[HEADER]]:
-! NSW: %[[TRIP_VAR:.*]] = fir.load %[[TRIP_VAR_REF]] : !fir.ref<i32>
-! NSW: %[[ZERO:.*]] = arith.constant 0 : i32
-! NSW: %[[COND:.*]] = arith.cmpi sgt, %[[TRIP_VAR]], %[[ZERO]] : i32
-! NSW: cf.cond_br %[[COND]], ^[[BODY:.*]], ^[[EXIT:.*]]
-! NSW: ^[[BODY]]:
-! NSW: %[[TRIP_VAR:.*]] = fir.load %[[TRIP_VAR_REF]] : !fir.ref<i32>
-! NSW: %[[ONE_1:.*]] = arith.constant 1 : i32
-! NSW: %[[TRIP_VAR_NEXT:.*]] = arith.subi %[[TRIP_VAR]], %[[ONE_1]] : i32
-! NSW: fir.store %[[TRIP_VAR_NEXT]] to %[[TRIP_VAR_REF]] : !fir.ref<i32>
-! NSW: %[[LOOP_VAR:.*]] = fir.load %[[LOOP_VAR_REF]] : !fir.ref<i32>
-! NSW: %[[STEP_ONE_2:.*]] = arith.constant 1 : i32
-! NSW: %[[LOOP_VAR_NEXT:.*]] = arith.addi %[[LOOP_VAR]], %[[STEP_ONE_2]] overflow<nsw> : i32
-! NSW: fir.store %[[LOOP_VAR_NEXT]] to %[[LOOP_VAR_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[HEADER]]
-! NSW: ^[[EXIT]]:
-! NSW: return
+! NO-NSW-LABEL: simple_unstructured
+! NO-NSW: %[[TRIP_VAR_REF:.*]] = fir.alloca i32
+! NO-NSW: %[[LOOP_VAR_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsimple_unstructuredEi"}
+! NO-NSW: %[[ONE:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[HUNDRED:.*]] = arith.constant 100 : i32
+! NO-NSW: %[[STEP_ONE:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[TMP1:.*]] = arith.subi %[[HUNDRED]], %[[ONE]] : i32
+! NO-NSW: %[[TMP2:.*]] = arith.addi %[[TMP1]], %[[STEP_ONE]] : i32
+! NO-NSW: %[[TRIP_COUNT:.*]] = arith.divsi %[[TMP2]], %[[STEP_ONE]] : i32
+! NO-NSW: fir.store %[[TRIP_COUNT]] to %[[TRIP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: fir.store %[[ONE]] to %[[LOOP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[HEADER:.*]]
+! NO-NSW: ^[[HEADER]]:
+! NO-NSW: %[[TRIP_VAR:.*]] = fir.load %[[TRIP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: %[[ZERO:.*]] = arith.constant 0 : i32
+! NO-NSW: %[[COND:.*]] = arith.cmpi sgt, %[[TRIP_VAR]], %[[ZERO]] : i32
+! NO-NSW: cf.cond_br %[[COND]], ^[[BODY:.*]], ^[[EXIT:.*]]
+! NO-NSW: ^[[BODY]]:
+! NO-NSW: %[[TRIP_VAR:.*]] = fir.load %[[TRIP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: %[[ONE_1:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[TRIP_VAR_NEXT:.*]] = arith.subi %[[TRIP_VAR]], %[[ONE_1]] : i32
+! NO-NSW: fir.store %[[TRIP_VAR_NEXT]] to %[[TRIP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: %[[LOOP_VAR:.*]] = fir.load %[[LOOP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: %[[STEP_ONE_2:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[LOOP_VAR_NEXT:.*]] = arith.addi %[[LOOP_VAR]], %[[STEP_ONE_2]] : i32
+! NO-NSW: fir.store %[[LOOP_VAR_NEXT]] to %[[LOOP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[HEADER]]
+! NO-NSW: ^[[EXIT]]:
+! NO-NSW: return
! Test an unstructured loop with a step. Mostly similar to the previous one.
! Only difference is a non-unit step.
@@ -108,41 +108,41 @@ subroutine simple_unstructured_with_step()
! CHECK: fir.store %[[TRIP_VAR_NEXT]] to %[[TRIP_VAR_REF]] : !fir.ref<i32>
! CHECK: %[[LOOP_VAR:.*]] = fir.load %[[LOOP_VAR_REF]] : !fir.ref<i32>
! CHECK: %[[STEP_2:.*]] = arith.constant 2 : i32
-! CHECK: %[[LOOP_VAR_NEXT:.*]] = arith.addi %[[LOOP_VAR]], %[[STEP_2]] : i32
+! CHECK: %[[LOOP_VAR_NEXT:.*]] = arith.addi %[[LOOP_VAR]], %[[STEP_2]] overflow<nsw> : i32
! CHECK: fir.store %[[LOOP_VAR_NEXT]] to %[[LOOP_VAR_REF]] : !fir.ref<i32>
! CHECK: cf.br ^[[HEADER]]
! CHECK: ^[[EXIT]]:
! CHECK: return
-! NSW-LABEL: simple_unstructured_with_step
-! NSW: %[[TRIP_VAR_REF:.*]] = fir.alloca i32
-! NSW: %[[LOOP_VAR_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsimple_unstructured_with_stepEi"}
-! NSW: %[[ONE:.*]] = arith.constant 1 : i32
-! NSW: %[[HUNDRED:.*]] = arith.constant 100 : i32
-! NSW: %[[STEP:.*]] = arith.constant 2 : i32
-! NSW: %[[TMP1:.*]] = arith.subi %[[HUNDRED]], %[[ONE]] : i32
-! NSW: %[[TMP2:.*]] = arith.addi %[[TMP1]], %[[STEP]] : i32
-! NSW: %[[TRIP_COUNT:.*]] = arith.divsi %[[TMP2]], %[[STEP]] : i32
-! NSW: fir.store %[[TRIP_COUNT]] to %[[TRIP_VAR_REF]] : !fir.ref<i32>
-! NSW: fir.store %[[ONE]] to %[[LOOP_VAR_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[HEADER:.*]]
-! NSW: ^[[HEADER]]:
-! NSW: %[[TRIP_VAR:.*]] = fir.load %[[TRIP_VAR_REF]] : !fir.ref<i32>
-! NSW: %[[ZERO:.*]] = arith.constant 0 : i32
-! NSW: %[[COND:.*]] = arith.cmpi sgt, %[[TRIP_VAR]], %[[ZERO]] : i32
-! NSW: cf.cond_br %[[COND]], ^[[BODY:.*]], ^[[EXIT:.*]]
-! NSW: ^[[BODY]]:
-! NSW: %[[TRIP_VAR:.*]] = fir.load %[[TRIP_VAR_REF]] : !fir.ref<i32>
-! NSW: %[[ONE_1:.*]] = arith.constant 1 : i32
-! NSW: %[[TRIP_VAR_NEXT:.*]] = arith.subi %[[TRIP_VAR]], %[[ONE_1]] : i32
-! NSW: fir.store %[[TRIP_VAR_NEXT]] to %[[TRIP_VAR_REF]] : !fir.ref<i32>
-! NSW: %[[LOOP_VAR:.*]] = fir.load %[[LOOP_VAR_REF]] : !fir.ref<i32>
-! NSW: %[[STEP_2:.*]] = arith.constant 2 : i32
-! NSW: %[[LOOP_VAR_NEXT:.*]] = arith.addi %[[LOOP_VAR]], %[[STEP_2]] overflow<nsw> : i32
-! NSW: fir.store %[[LOOP_VAR_NEXT]] to %[[LOOP_VAR_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[HEADER]]
-! NSW: ^[[EXIT]]:
-! NSW: return
+! NO-NSW-LABEL: simple_unstructured_with_step
+! NO-NSW: %[[TRIP_VAR_REF:.*]] = fir.alloca i32
+! NO-NSW: %[[LOOP_VAR_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsimple_unstructured_with_stepEi"}
+! NO-NSW: %[[ONE:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[HUNDRED:.*]] = arith.constant 100 : i32
+! NO-NSW: %[[STEP:.*]] = arith.constant 2 : i32
+! NO-NSW: %[[TMP1:.*]] = arith.subi %[[HUNDRED]], %[[ONE]] : i32
+! NO-NSW: %[[TMP2:.*]] = arith.addi %[[TMP1]], %[[STEP]] : i32
+! NO-NSW: %[[TRIP_COUNT:.*]] = arith.divsi %[[TMP2]], %[[STEP]] : i32
+! NO-NSW: fir.store %[[TRIP_COUNT]] to %[[TRIP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: fir.store %[[ONE]] to %[[LOOP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[HEADER:.*]]
+! NO-NSW: ^[[HEADER]]:
+! NO-NSW: %[[TRIP_VAR:.*]] = fir.load %[[TRIP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: %[[ZERO:.*]] = arith.constant 0 : i32
+! NO-NSW: %[[COND:.*]] = arith.cmpi sgt, %[[TRIP_VAR]], %[[ZERO]] : i32
+! NO-NSW: cf.cond_br %[[COND]], ^[[BODY:.*]], ^[[EXIT:.*]]
+! NO-NSW: ^[[BODY]]:
+! NO-NSW: %[[TRIP_VAR:.*]] = fir.load %[[TRIP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: %[[ONE_1:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[TRIP_VAR_NEXT:.*]] = arith.subi %[[TRIP_VAR]], %[[ONE_1]] : i32
+! NO-NSW: fir.store %[[TRIP_VAR_NEXT]] to %[[TRIP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: %[[LOOP_VAR:.*]] = fir.load %[[LOOP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: %[[STEP_2:.*]] = arith.constant 2 : i32
+! NO-NSW: %[[LOOP_VAR_NEXT:.*]] = arith.addi %[[LOOP_VAR]], %[[STEP_2]] : i32
+! NO-NSW: fir.store %[[LOOP_VAR_NEXT]] to %[[LOOP_VAR_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[HEADER]]
+! NO-NSW: ^[[EXIT]]:
+! NO-NSW: return
! Test a three nested unstructured loop. Three nesting is the basic case where
! we have loops that are neither innermost or outermost.
@@ -215,7 +215,7 @@ subroutine nested_unstructured()
! CHECK: fir.store %[[TRIP_VAR_K_NEXT]] to %[[TRIP_VAR_K_REF]] : !fir.ref<i32>
! CHECK: %[[LOOP_VAR_K:.*]] = fir.load %[[LOOP_VAR_K_REF]] : !fir.ref<i32>
! CHECK: %[[K_STEP_2:.*]] = arith.constant 1 : i32
-! CHECK: %[[LOOP_VAR_K_NEXT:.*]] = arith.addi %[[LOOP_VAR_K]], %[[K_STEP_2]] : i32
+! CHECK: %[[LOOP_VAR_K_NEXT:.*]] = arith.addi %[[LOOP_VAR_K]], %[[K_STEP_2]] overflow<nsw> : i32
! CHECK: fir.store %[[LOOP_VAR_K_NEXT]] to %[[LOOP_VAR_K_REF]] : !fir.ref<i32>
! CHECK: cf.br ^[[HEADER_K]]
! CHECK: ^[[EXIT_K]]:
@@ -225,7 +225,7 @@ subroutine nested_unstructured()
! CHECK: fir.store %[[TRIP_VAR_J_NEXT]] to %[[TRIP_VAR_J_REF]] : !fir.ref<i32>
! CHECK: %[[LOOP_VAR_J:.*]] = fir.load %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
! CHECK: %[[J_STEP_2:.*]] = arith.constant 1 : i32
-! CHECK: %[[LOOP_VAR_J_NEXT:.*]] = arith.addi %[[LOOP_VAR_J]], %[[J_STEP_2]] : i32
+! CHECK: %[[LOOP_VAR_J_NEXT:.*]] = arith.addi %[[LOOP_VAR_J]], %[[J_STEP_2]] overflow<nsw> : i32
! CHECK: fir.store %[[LOOP_VAR_J_NEXT]] to %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
! CHECK: cf.br ^[[HEADER_J]]
! CHECK: ^[[EXIT_J]]:
@@ -235,95 +235,95 @@ subroutine nested_unstructured()
! CHECK: fir.store %[[TRIP_VAR_I_NEXT]] to %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
! CHECK: %[[LOOP_VAR_I:.*]] = fir.load %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
! CHECK: %[[I_STEP_2:.*]] = arith.constant 1 : i32
-! CHECK: %[[LOOP_VAR_I_NEXT:.*]] = arith.addi %[[LOOP_VAR_I]], %[[I_STEP_2]] : i32
+! CHECK: %[[LOOP_VAR_I_NEXT:.*]] = arith.addi %[[LOOP_VAR_I]], %[[I_STEP_2]] overflow<nsw> : i32
! CHECK: fir.store %[[LOOP_VAR_I_NEXT]] to %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
! CHECK: cf.br ^[[HEADER_I]]
! CHECK: ^[[EXIT_I]]:
! CHECK: return
-! NSW-LABEL: nested_unstructured
-! NSW: %[[TRIP_VAR_K_REF:.*]] = fir.alloca i32
-! NSW: %[[TRIP_VAR_J_REF:.*]] = fir.alloca i32
-! NSW: %[[TRIP_VAR_I_REF:.*]] = fir.alloca i32
-! NSW: %[[LOOP_VAR_I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFnested_unstructuredEi"}
-! NSW: %[[LOOP_VAR_J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFnested_unstructuredEj"}
-! NSW: %[[LOOP_VAR_K_REF:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFnested_unstructuredEk"}
-! NSW: %[[I_START:.*]] = arith.constant 1 : i32
-! NSW: %[[I_END:.*]] = arith.constant 100 : i32
-! NSW: %[[I_STEP:.*]] = arith.constant 1 : i32
-! NSW: %[[TMP1:.*]] = arith.subi %[[I_END]], %[[I_START]] : i32
-! NSW: %[[TMP2:.*]] = arith.addi %[[TMP1]], %[[I_STEP]] : i32
-! NSW: %[[TRIP_COUNT_I:.*]] = arith.divsi %[[TMP2]], %[[I_STEP]] : i32
-! NSW: fir.store %[[TRIP_COUNT_I]] to %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: fir.store %[[I_START]] to %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[HEADER_I:.*]]
-! NSW: ^[[HEADER_I]]:
-! NSW: %[[TRIP_VAR_I:.*]] = fir.load %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: %[[ZERO_1:.*]] = arith.constant 0 : i32
-! NSW: %[[COND_I:.*]] = arith.cmpi sgt, %[[TRIP_VAR_I]], %[[ZERO_1]] : i32
-! NSW: cf.cond_br %[[COND_I]], ^[[BODY_I:.*]], ^[[EXIT_I:.*]]
-! NSW: ^[[BODY_I]]:
-! NSW: %[[J_START:.*]] = arith.constant 1 : i32
-! NSW: %[[J_END:.*]] = arith.constant 200 : i32
-! NSW: %[[J_STEP:.*]] = arith.constant 1 : i32
-! NSW: %[[TMP3:.*]] = arith.subi %[[J_END]], %[[J_START]] : i32
-! NSW: %[[TMP4:.*]] = arith.addi %[[TMP3]], %[[J_STEP]] : i32
-! NSW: %[[TRIP_COUNT_J:.*]] = arith.divsi %[[TMP4]], %[[J_STEP]] : i32
-! NSW: fir.store %[[TRIP_COUNT_J]] to %[[TRIP_VAR_J_REF]] : !fir.ref<i32>
-! NSW: fir.store %[[J_START]] to %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[HEADER_J:.*]]
-! NSW: ^[[HEADER_J]]:
-! NSW: %[[TRIP_VAR_J:.*]] = fir.load %[[TRIP_VAR_J_REF]] : !fir.ref<i32>
-! NSW: %[[ZERO_2:.*]] = arith.constant 0 : i32
-! NSW: %[[COND_J:.*]] = arith.cmpi sgt, %[[TRIP_VAR_J]], %[[ZERO_2]] : i32
-! NSW: cf.cond_br %[[COND_J]], ^[[BODY_J:.*]], ^[[EXIT_J:.*]]
-! NSW: ^[[BODY_J]]:
-! NSW: %[[K_START:.*]] = arith.constant 1 : i32
-! NSW: %[[K_END:.*]] = arith.constant 300 : i32
-! NSW: %[[K_STEP:.*]] = arith.constant 1 : i32
-! NSW: %[[TMP3:.*]] = arith.subi %[[K_END]], %[[K_START]] : i32
-! NSW: %[[TMP4:.*]] = arith.addi %[[TMP3]], %[[K_STEP]] : i32
-! NSW: %[[TRIP_COUNT_K:.*]] = arith.divsi %[[TMP4]], %[[K_STEP]] : i32
-! NSW: fir.store %[[TRIP_COUNT_K]] to %[[TRIP_VAR_K_REF]] : !fir.ref<i32>
-! NSW: fir.store %[[K_START]] to %[[LOOP_VAR_K_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[HEADER_K:.*]]
-! NSW: ^[[HEADER_K]]:
-! NSW: %[[TRIP_VAR_K:.*]] = fir.load %[[TRIP_VAR_K_REF]] : !fir.ref<i32>
-! NSW: %[[ZERO_2:.*]] = arith.constant 0 : i32
-! NSW: %[[COND_K:.*]] = arith.cmpi sgt, %[[TRIP_VAR_K]], %[[ZERO_2]] : i32
-! NSW: cf.cond_br %[[COND_K]], ^[[BODY_K:.*]], ^[[EXIT_K:.*]]
-! NSW: ^[[BODY_K]]:
-! NSW: %[[TRIP_VAR_K:.*]] = fir.load %[[TRIP_VAR_K_REF]] : !fir.ref<i32>
-! NSW: %[[ONE_1:.*]] = arith.constant 1 : i32
-! NSW: %[[TRIP_VAR_K_NEXT:.*]] = arith.subi %[[TRIP_VAR_K]], %[[ONE_1]] : i32
-! NSW: fir.store %[[TRIP_VAR_K_NEXT]] to %[[TRIP_VAR_K_REF]] : !fir.ref<i32>
-! NSW: %[[LOOP_VAR_K:.*]] = fir.load %[[LOOP_VAR_K_REF]] : !fir.ref<i32>
-! NSW: %[[K_STEP_2:.*]] = arith.constant 1 : i32
-! NSW: %[[LOOP_VAR_K_NEXT:.*]] = arith.addi %[[LOOP_VAR_K]], %[[K_STEP_2]] overflow<nsw> : i32
-! NSW: fir.store %[[LOOP_VAR_K_NEXT]] to %[[LOOP_VAR_K_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[HEADER_K]]
-! NSW: ^[[EXIT_K]]:
-! NSW: %[[TRIP_VAR_J:.*]] = fir.load %[[TRIP_VAR_J_REF]] : !fir.ref<i32>
-! NSW: %[[ONE_1:.*]] = arith.constant 1 : i32
-! NSW: %[[TRIP_VAR_J_NEXT:.*]] = arith.subi %[[TRIP_VAR_J]], %[[ONE_1]] : i32
-! NSW: fir.store %[[TRIP_VAR_J_NEXT]] to %[[TRIP_VAR_J_REF]] : !fir.ref<i32>
-! NSW: %[[LOOP_VAR_J:.*]] = fir.load %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
-! NSW: %[[J_STEP_2:.*]] = arith.constant 1 : i32
-! NSW: %[[LOOP_VAR_J_NEXT:.*]] = arith.addi %[[LOOP_VAR_J]], %[[J_STEP_2]] overflow<nsw> : i32
-! NSW: fir.store %[[LOOP_VAR_J_NEXT]] to %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[HEADER_J]]
-! NSW: ^[[EXIT_J]]:
-! NSW: %[[TRIP_VAR_I:.*]] = fir.load %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: %[[ONE_1:.*]] = arith.constant 1 : i32
-! NSW: %[[TRIP_VAR_I_NEXT:.*]] = arith.subi %[[TRIP_VAR_I]], %[[ONE_1]] : i32
-! NSW: fir.store %[[TRIP_VAR_I_NEXT]] to %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: %[[LOOP_VAR_I:.*]] = fir.load %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: %[[I_STEP_2:.*]] = arith.constant 1 : i32
-! NSW: %[[LOOP_VAR_I_NEXT:.*]] = arith.addi %[[LOOP_VAR_I]], %[[I_STEP_2]] overflow<nsw> : i32
-! NSW: fir.store %[[LOOP_VAR_I_NEXT]] to %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[HEADER_I]]
-! NSW: ^[[EXIT_I]]:
-! NSW: return
+! NO-NSW-LABEL: nested_unstructured
+! NO-NSW: %[[TRIP_VAR_K_REF:.*]] = fir.alloca i32
+! NO-NSW: %[[TRIP_VAR_J_REF:.*]] = fir.alloca i32
+! NO-NSW: %[[TRIP_VAR_I_REF:.*]] = fir.alloca i32
+! NO-NSW: %[[LOOP_VAR_I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFnested_unstructuredEi"}
+! NO-NSW: %[[LOOP_VAR_J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFnested_unstructuredEj"}
+! NO-NSW: %[[LOOP_VAR_K_REF:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFnested_unstructuredEk"}
+! NO-NSW: %[[I_START:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[I_END:.*]] = arith.constant 100 : i32
+! NO-NSW: %[[I_STEP:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[TMP1:.*]] = arith.subi %[[I_END]], %[[I_START]] : i32
+! NO-NSW: %[[TMP2:.*]] = arith.addi %[[TMP1]], %[[I_STEP]] : i32
+! NO-NSW: %[[TRIP_COUNT_I:.*]] = arith.divsi %[[TMP2]], %[[I_STEP]] : i32
+! NO-NSW: fir.store %[[TRIP_COUNT_I]] to %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: fir.store %[[I_START]] to %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[HEADER_I:.*]]
+! NO-NSW: ^[[HEADER_I]]:
+! NO-NSW: %[[TRIP_VAR_I:.*]] = fir.load %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: %[[ZERO_1:.*]] = arith.constant 0 : i32
+! NO-NSW: %[[COND_I:.*]] = arith.cmpi sgt, %[[TRIP_VAR_I]], %[[ZERO_1]] : i32
+! NO-NSW: cf.cond_br %[[COND_I]], ^[[BODY_I:.*]], ^[[EXIT_I:.*]]
+! NO-NSW: ^[[BODY_I]]:
+! NO-NSW: %[[J_START:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[J_END:.*]] = arith.constant 200 : i32
+! NO-NSW: %[[J_STEP:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[TMP3:.*]] = arith.subi %[[J_END]], %[[J_START]] : i32
+! NO-NSW: %[[TMP4:.*]] = arith.addi %[[TMP3]], %[[J_STEP]] : i32
+! NO-NSW: %[[TRIP_COUNT_J:.*]] = arith.divsi %[[TMP4]], %[[J_STEP]] : i32
+! NO-NSW: fir.store %[[TRIP_COUNT_J]] to %[[TRIP_VAR_J_REF]] : !fir.ref<i32>
+! NO-NSW: fir.store %[[J_START]] to %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[HEADER_J:.*]]
+! NO-NSW: ^[[HEADER_J]]:
+! NO-NSW: %[[TRIP_VAR_J:.*]] = fir.load %[[TRIP_VAR_J_REF]] : !fir.ref<i32>
+! NO-NSW: %[[ZERO_2:.*]] = arith.constant 0 : i32
+! NO-NSW: %[[COND_J:.*]] = arith.cmpi sgt, %[[TRIP_VAR_J]], %[[ZERO_2]] : i32
+! NO-NSW: cf.cond_br %[[COND_J]], ^[[BODY_J:.*]], ^[[EXIT_J:.*]]
+! NO-NSW: ^[[BODY_J]]:
+! NO-NSW: %[[K_START:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[K_END:.*]] = arith.constant 300 : i32
+! NO-NSW: %[[K_STEP:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[TMP3:.*]] = arith.subi %[[K_END]], %[[K_START]] : i32
+! NO-NSW: %[[TMP4:.*]] = arith.addi %[[TMP3]], %[[K_STEP]] : i32
+! NO-NSW: %[[TRIP_COUNT_K:.*]] = arith.divsi %[[TMP4]], %[[K_STEP]] : i32
+! NO-NSW: fir.store %[[TRIP_COUNT_K]] to %[[TRIP_VAR_K_REF]] : !fir.ref<i32>
+! NO-NSW: fir.store %[[K_START]] to %[[LOOP_VAR_K_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[HEADER_K:.*]]
+! NO-NSW: ^[[HEADER_K]]:
+! NO-NSW: %[[TRIP_VAR_K:.*]] = fir.load %[[TRIP_VAR_K_REF]] : !fir.ref<i32>
+! NO-NSW: %[[ZERO_2:.*]] = arith.constant 0 : i32
+! NO-NSW: %[[COND_K:.*]] = arith.cmpi sgt, %[[TRIP_VAR_K]], %[[ZERO_2]] : i32
+! NO-NSW: cf.cond_br %[[COND_K]], ^[[BODY_K:.*]], ^[[EXIT_K:.*]]
+! NO-NSW: ^[[BODY_K]]:
+! NO-NSW: %[[TRIP_VAR_K:.*]] = fir.load %[[TRIP_VAR_K_REF]] : !fir.ref<i32>
+! NO-NSW: %[[ONE_1:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[TRIP_VAR_K_NEXT:.*]] = arith.subi %[[TRIP_VAR_K]], %[[ONE_1]] : i32
+! NO-NSW: fir.store %[[TRIP_VAR_K_NEXT]] to %[[TRIP_VAR_K_REF]] : !fir.ref<i32>
+! NO-NSW: %[[LOOP_VAR_K:.*]] = fir.load %[[LOOP_VAR_K_REF]] : !fir.ref<i32>
+! NO-NSW: %[[K_STEP_2:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[LOOP_VAR_K_NEXT:.*]] = arith.addi %[[LOOP_VAR_K]], %[[K_STEP_2]] : i32
+! NO-NSW: fir.store %[[LOOP_VAR_K_NEXT]] to %[[LOOP_VAR_K_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[HEADER_K]]
+! NO-NSW: ^[[EXIT_K]]:
+! NO-NSW: %[[TRIP_VAR_J:.*]] = fir.load %[[TRIP_VAR_J_REF]] : !fir.ref<i32>
+! NO-NSW: %[[ONE_1:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[TRIP_VAR_J_NEXT:.*]] = arith.subi %[[TRIP_VAR_J]], %[[ONE_1]] : i32
+! NO-NSW: fir.store %[[TRIP_VAR_J_NEXT]] to %[[TRIP_VAR_J_REF]] : !fir.ref<i32>
+! NO-NSW: %[[LOOP_VAR_J:.*]] = fir.load %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
+! NO-NSW: %[[J_STEP_2:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[LOOP_VAR_J_NEXT:.*]] = arith.addi %[[LOOP_VAR_J]], %[[J_STEP_2]] : i32
+! NO-NSW: fir.store %[[LOOP_VAR_J_NEXT]] to %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[HEADER_J]]
+! NO-NSW: ^[[EXIT_J]]:
+! NO-NSW: %[[TRIP_VAR_I:.*]] = fir.load %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: %[[ONE_1:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[TRIP_VAR_I_NEXT:.*]] = arith.subi %[[TRIP_VAR_I]], %[[ONE_1]] : i32
+! NO-NSW: fir.store %[[TRIP_VAR_I_NEXT]] to %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: %[[LOOP_VAR_I:.*]] = fir.load %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: %[[I_STEP_2:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[LOOP_VAR_I_NEXT:.*]] = arith.addi %[[LOOP_VAR_I]], %[[I_STEP_2]] : i32
+! NO-NSW: fir.store %[[LOOP_VAR_I_NEXT]] to %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[HEADER_I]]
+! NO-NSW: ^[[EXIT_I]]:
+! NO-NSW: return
! Test the existence of a structured loop inside an unstructured loop.
! Only minimal checks are inserted for the structured loop.
@@ -359,9 +359,9 @@ subroutine nested_structured_in_unstructured()
! CHECK-SAME: %{{.*}} to %{{.*}} step %[[ST:[^ ]*]]
! CHECK-SAME: iter_args(%[[J_IV:.*]] = %{{.*}}) -> (index, i32) {
! CHECK: fir.store %[[J_IV]] to %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
-! CHECK: %[[J_INDEX_NEXT:.*]] = arith.addi %[[J_INDEX]], %[[ST]] : index
+! CHECK: %[[J_INDEX_NEXT:.*]] = arith.addi %[[J_INDEX]], %[[ST]] overflow<nsw> : index
! CHECK: %[[LOOP_VAR_J:.*]] = fir.load %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
-! CHECK: %[[LOOP_VAR_J_NEXT:.*]] = arith.addi %[[LOOP_VAR_J]], %{{[^ ]*}} : i32
+! CHECK: %[[LOOP_VAR_J_NEXT:.*]] = arith.addi %[[LOOP_VAR_J]], %{{[^ ]*}} overflow<nsw> : i32
! CHECK: }
! CHECK: %[[TRIP_VAR_I:.*]] = fir.load %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
! CHECK: %[[C1_3:.*]] = arith.constant 1 : i32
@@ -369,47 +369,47 @@ subroutine nested_structured_in_unstructured()
! CHECK: fir.store %[[TRIP_VAR_I_NEXT]] to %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
! CHECK: %[[LOOP_VAR_I:.*]] = fir.load %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
! CHECK: %[[I_STEP_2:.*]] = arith.constant 1 : i32
-! CHECK: %[[LOOP_VAR_I_NEXT:.*]] = arith.addi %[[LOOP_VAR_I]], %[[I_STEP_2]] : i32
+! CHECK: %[[LOOP_VAR_I_NEXT:.*]] = arith.addi %[[LOOP_VAR_I]], %[[I_STEP_2]] overflow<nsw> : i32
! CHECK: fir.store %[[LOOP_VAR_I_NEXT]] to %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
! CHECK: cf.br ^[[HEADER]]
! CHECK: ^[[EXIT]]:
! CHECK: return
-! NSW-LABEL: nested_structured_in_unstructured
-! NSW: %[[TRIP_VAR_I_REF:.*]] = fir.alloca i32
-! NSW: %[[LOOP_VAR_I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFnested_structured_in_unstructuredEi"}
-! NSW: %[[LOOP_VAR_J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFnested_structured_in_unstructuredEj"}
-! NSW: %[[I_START:.*]] = arith.constant 1 : i32
-! NSW: %[[I_END:.*]] = arith.constant 100 : i32
-! NSW: %[[I_STEP:.*]] = arith.constant 1 : i32
-! NSW: %[[TMP1:.*]] = arith.subi %[[I_END]], %[[I_START]] : i32
-! NSW: %[[TMP2:.*]] = arith.addi %[[TMP1]], %[[I_STEP]] : i32
-! NSW: %[[TRIP_COUNT:.*]] = arith.divsi %[[TMP2]], %[[I_STEP]] : i32
-! NSW: fir.store %[[TRIP_COUNT]] to %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: fir.store %[[I_START]] to %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[HEADER:.*]]
-! NSW: ^[[HEADER]]:
-! NSW: %[[TRIP_VAR:.*]] = fir.load %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: %[[ZERO:.*]] = arith.constant 0 : i32
-! NSW: %[[COND:.*]] = arith.cmpi sgt, %[[TRIP_VAR]], %[[ZERO]] : i32
-! NSW: cf.cond_br %[[COND]], ^[[BODY:.*]], ^[[EXIT:.*]]
-! NSW: ^[[BODY]]:
-! NSW: %{{.*}} = fir.do_loop %[[J_INDEX:[^ ]*]] =
-! NSW-SAME: %{{.*}} to %{{.*}} step %[[ST:[^ ]*]]
-! NSW-SAME: iter_args(%[[J_IV:.*]] = %{{.*}}) -> (index, i32) {
-! NSW: fir.store %[[J_IV]] to %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
-! NSW: %[[J_INDEX_NEXT:.*]] = arith.addi %[[J_INDEX]], %[[ST]] overflow<nsw> : index
-! NSW: %[[LOOP_VAR_J:.*]] = fir.load %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
-! NSW: %[[LOOP_VAR_J_NEXT:.*]] = arith.addi %[[LOOP_VAR_J]], %{{[^ ]*}} overflow<nsw> : i32
-! NSW: }
-! NSW: %[[TRIP_VAR_I:.*]] = fir.load %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: %[[C1_3:.*]] = arith.constant 1 : i32
-! NSW: %[[TRIP_VAR_I_NEXT:.*]] = arith.subi %[[TRIP_VAR_I]], %[[C1_3]] : i32
-! NSW: fir.store %[[TRIP_VAR_I_NEXT]] to %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: %[[LOOP_VAR_I:.*]] = fir.load %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: %[[I_STEP_2:.*]] = arith.constant 1 : i32
-! NSW: %[[LOOP_VAR_I_NEXT:.*]] = arith.addi %[[LOOP_VAR_I]], %[[I_STEP_2]] overflow<nsw> : i32
-! NSW: fir.store %[[LOOP_VAR_I_NEXT]] to %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[HEADER]]
-! NSW: ^[[EXIT]]:
-! NSW: return
+! NO-NSW-LABEL: nested_structured_in_unstructured
+! NO-NSW: %[[TRIP_VAR_I_REF:.*]] = fir.alloca i32
+! NO-NSW: %[[LOOP_VAR_I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFnested_structured_in_unstructuredEi"}
+! NO-NSW: %[[LOOP_VAR_J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFnested_structured_in_unstructuredEj"}
+! NO-NSW: %[[I_START:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[I_END:.*]] = arith.constant 100 : i32
+! NO-NSW: %[[I_STEP:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[TMP1:.*]] = arith.subi %[[I_END]], %[[I_START]] : i32
+! NO-NSW: %[[TMP2:.*]] = arith.addi %[[TMP1]], %[[I_STEP]] : i32
+! NO-NSW: %[[TRIP_COUNT:.*]] = arith.divsi %[[TMP2]], %[[I_STEP]] : i32
+! NO-NSW: fir.store %[[TRIP_COUNT]] to %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: fir.store %[[I_START]] to %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[HEADER:.*]]
+! NO-NSW: ^[[HEADER]]:
+! NO-NSW: %[[TRIP_VAR:.*]] = fir.load %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: %[[ZERO:.*]] = arith.constant 0 : i32
+! NO-NSW: %[[COND:.*]] = arith.cmpi sgt, %[[TRIP_VAR]], %[[ZERO]] : i32
+! NO-NSW: cf.cond_br %[[COND]], ^[[BODY:.*]], ^[[EXIT:.*]]
+! NO-NSW: ^[[BODY]]:
+! NO-NSW: %{{.*}} = fir.do_loop %[[J_INDEX:[^ ]*]] =
+! NO-NSW-SAME: %{{.*}} to %{{.*}} step %[[ST:[^ ]*]]
+! NO-NSW-SAME: iter_args(%[[J_IV:.*]] = %{{.*}}) -> (index, i32) {
+! NO-NSW: fir.store %[[J_IV]] to %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
+! NO-NSW: %[[J_INDEX_NEXT:.*]] = arith.addi %[[J_INDEX]], %[[ST]] : index
+! NO-NSW: %[[LOOP_VAR_J:.*]] = fir.load %[[LOOP_VAR_J_REF]] : !fir.ref<i32>
+! NO-NSW: %[[LOOP_VAR_J_NEXT:.*]] = arith.addi %[[LOOP_VAR_J]], %{{[^ ]*}} : i32
+! NO-NSW: }
+! NO-NSW: %[[TRIP_VAR_I:.*]] = fir.load %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: %[[C1_3:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[TRIP_VAR_I_NEXT:.*]] = arith.subi %[[TRIP_VAR_I]], %[[C1_3]] : i32
+! NO-NSW: fir.store %[[TRIP_VAR_I_NEXT]] to %[[TRIP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: %[[LOOP_VAR_I:.*]] = fir.load %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: %[[I_STEP_2:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[LOOP_VAR_I_NEXT:.*]] = arith.addi %[[LOOP_VAR_I]], %[[I_STEP_2]] : i32
+! NO-NSW: fir.store %[[LOOP_VAR_I_NEXT]] to %[[LOOP_VAR_I_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[HEADER]]
+! NO-NSW: ^[[EXIT]]:
+! NO-NSW: return
diff --git a/flang/test/Lower/goto-do-body.f90 b/flang/test/Lower/goto-do-body.f90
index 910e55f1839fd2..89e4a7a64a87ba 100644
--- a/flang/test/Lower/goto-do-body.f90
+++ b/flang/test/Lower/goto-do-body.f90
@@ -48,7 +48,7 @@ subroutine sub1()
! CHECK: fir.store %[[TMP8]] to %[[TRIP]] : !fir.ref<i32>
! CHECK: %[[TMP9:.*]] = fir.load %[[I]] : !fir.ref<i32>
! CHECK: %[[C1_4:.*]] = arith.constant 1 : i32
-! CHECK: %[[TMP10:.*]] = arith.addi %[[TMP9]], %[[C1_4]] : i32
+! CHECK: %[[TMP10:.*]] = arith.addi %[[TMP9]], %[[C1_4]] overflow<nsw> : i32
! CHECK: fir.store %[[TMP10]] to %[[I]] : !fir.ref<i32>
! CHECK: cf.br ^[[HEADER]]
end do
@@ -115,7 +115,7 @@ subroutine sub2()
! CHECK: fir.store %[[TMP10]] to %[[TRIP]] : !fir.ref<i32>
! CHECK: %[[TMP11:.*]] = fir.load %[[I]] : !fir.ref<i32>
! CHECK: %[[STEP_VAL:.*]] = fir.load %[[STEP_VAR]] : !fir.ref<i32>
-! CHECK: %[[TMP12:.*]] = arith.addi %[[TMP11]], %[[STEP_VAL]] : i32
+! CHECK: %[[TMP12:.*]] = arith.addi %[[TMP11]], %[[STEP_VAL]] overflow<nsw> : i32
! CHECK: fir.store %[[TMP12]] to %[[I]] : !fir.ref<i32>
! CHECK: cf.br ^[[HEADER]]
end do
diff --git a/flang/test/Lower/host-associated.f90 b/flang/test/Lower/host-associated.f90
index 67465f5a7073d4..adf1a78ed430e6 100644
--- a/flang/test/Lower/host-associated.f90
+++ b/flang/test/Lower/host-associated.f90
@@ -1,5 +1,5 @@
! Test internal procedure host association lowering.
-! RUN: bbc -hlfir=false %s -o - | FileCheck %s
+! RUN: bbc -hlfir=false -fwrapv %s -o - | FileCheck %s
! -----------------------------------------------------------------------------
! Test non character intrinsic scalars
diff --git a/flang/test/Lower/infinite_loop.f90 b/flang/test/Lower/infinite_loop.f90
index 6942dda8d7a23a..8ce6dc6f2d5feb 100644
--- a/flang/test/Lower/infinite_loop.f90
+++ b/flang/test/Lower/infinite_loop.f90
@@ -1,6 +1,6 @@
! RUN: bbc -emit-fir -hlfir=false -o - %s | FileCheck %s
! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -o - %s | FileCheck %s
-! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -flang-experimental-integer-overflow -o - %s | FileCheck %s --check-prefix=NSW
+! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fwrapv -o - %s | FileCheck %s --check-prefix=NO-NSW
! Tests for infinite loop.
@@ -96,10 +96,10 @@ subroutine structured_loop_in_infinite(i)
! CHECK-SAME: %[[C1_INDEX]] to %[[C10_INDEX]] step %[[C1_1]]
! CHECK-SAME: iter_args(%[[J_IV:.*]] = %[[J_LB]]) -> (index, i32) {
! CHECK: fir.store %[[J_IV]] to %[[J_REF]] : !fir.ref<i32>
-! CHECK: %[[J_NEXT:.*]] = arith.addi %[[J]], %[[C1_1]] : index
+! CHECK: %[[J_NEXT:.*]] = arith.addi %[[J]], %[[C1_1]] overflow<nsw> : index
! CHECK: %[[J_STEPCAST:.*]] = fir.convert %[[C1_1]] : (index) -> i32
! CHECK: %[[J_IVLOAD:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
-! CHECK: %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST]] : i32
+! CHECK: %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST]] overflow<nsw> : i32
! CHECK: fir.result %[[J_NEXT]], %[[J_IVINC]] : index, i32
! CHECK: }
! CHECK: fir.store %[[J_FINAL]]#1 to %[[J_REF]] : !fir.ref<i32>
@@ -107,38 +107,38 @@ subroutine structured_loop_in_infinite(i)
! CHECK: ^[[RETURN]]:
! CHECK: return
-! NSW-LABEL: structured_loop_in_infinite
-! NSW-SAME: %[[I_REF:.*]]: !fir.ref<i32>
-! NSW: %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFstructured_loop_in_infiniteEj"}
-! NSW: cf.br ^[[BODY1:.*]]
-! NSW: ^[[BODY1]]:
-! NSW: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
-! NSW: %[[C100:.*]] = arith.constant 100 : i32
-! NSW: %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C100]] : i32
-! NSW: cf.cond_br %[[COND]], ^[[EXIT:.*]], ^[[BODY2:.*]]
-! NSW: ^[[EXIT]]:
-! NSW: cf.br ^[[RETURN:.*]]
-! NSW: ^[[BODY2:.*]]:
-! NSW: %[[C1:.*]] = arith.constant 1 : i32
-! NSW: %[[C1_INDEX:.*]] = fir.convert %[[C1]] : (i32) -> index
-! NSW: %[[C10:.*]] = arith.constant 10 : i32
-! NSW: %[[C10_INDEX:.*]] = fir.convert %[[C10]] : (i32) -> index
-! NSW: %[[C1_1:.*]] = arith.constant 1 : index
-! NSW: %[[J_LB:.*]] = fir.convert %[[C1_INDEX]] : (index) -> i32
-! NSW: %[[J_FINAL:.*]]:2 = fir.do_loop %[[J:[^ ]*]] =
-! NSW-SAME: %[[C1_INDEX]] to %[[C10_INDEX]] step %[[C1_1]]
-! NSW-SAME: iter_args(%[[J_IV:.*]] = %[[J_LB]]) -> (index, i32) {
-! NSW: fir.store %[[J_IV]] to %[[J_REF]] : !fir.ref<i32>
-! NSW: %[[J_NEXT:.*]] = arith.addi %[[J]], %[[C1_1]] overflow<nsw> : index
-! NSW: %[[J_STEPCAST:.*]] = fir.convert %[[C1_1]] : (index) -> i32
-! NSW: %[[J_IVLOAD:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
-! NSW: %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST]] overflow<nsw> : i32
-! NSW: fir.result %[[J_NEXT]], %[[J_IVINC]] : index, i32
-! NSW: }
-! NSW: fir.store %[[J_FINAL]]#1 to %[[J_REF]] : !fir.ref<i32>
-! NSW: cf.br ^[[BODY1]]
-! NSW: ^[[RETURN]]:
-! NSW: return
+! NO-NSW-LABEL: structured_loop_in_infinite
+! NO-NSW-SAME: %[[I_REF:.*]]: !fir.ref<i32>
+! NO-NSW: %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFstructured_loop_in_infiniteEj"}
+! NO-NSW: cf.br ^[[BODY1:.*]]
+! NO-NSW: ^[[BODY1]]:
+! NO-NSW: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
+! NO-NSW: %[[C100:.*]] = arith.constant 100 : i32
+! NO-NSW: %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C100]] : i32
+! NO-NSW: cf.cond_br %[[COND]], ^[[EXIT:.*]], ^[[BODY2:.*]]
+! NO-NSW: ^[[EXIT]]:
+! NO-NSW: cf.br ^[[RETURN:.*]]
+! NO-NSW: ^[[BODY2:.*]]:
+! NO-NSW: %[[C1:.*]] = arith.constant 1 : i32
+! NO-NSW: %[[C1_INDEX:.*]] = fir.convert %[[C1]] : (i32) -> index
+! NO-NSW: %[[C10:.*]] = arith.constant 10 : i32
+! NO-NSW: %[[C10_INDEX:.*]] = fir.convert %[[C10]] : (i32) -> index
+! NO-NSW: %[[C1_1:.*]] = arith.constant 1 : index
+! NO-NSW: %[[J_LB:.*]] = fir.convert %[[C1_INDEX]] : (index) -> i32
+! NO-NSW: %[[J_FINAL:.*]]:2 = fir.do_loop %[[J:[^ ]*]] =
+! NO-NSW-SAME: %[[C1_INDEX]] to %[[C10_INDEX]] step %[[C1_1]]
+! NO-NSW-SAME: iter_args(%[[J_IV:.*]] = %[[J_LB]]) -> (index, i32) {
+! NO-NSW: fir.store %[[J_IV]] to %[[J_REF]] : !fir.ref<i32>
+! NO-NSW: %[[J_NEXT:.*]] = arith.addi %[[J]], %[[C1_1]] : index
+! NO-NSW: %[[J_STEPCAST:.*]] = fir.convert %[[C1_1]] : (index) -> i32
+! NO-NSW: %[[J_IVLOAD:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
+! NO-NSW: %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST]] : i32
+! NO-NSW: fir.result %[[J_NEXT]], %[[J_IVINC]] : index, i32
+! NO-NSW: }
+! NO-NSW: fir.store %[[J_FINAL]]#1 to %[[J_REF]] : !fir.ref<i32>
+! NO-NSW: cf.br ^[[BODY1]]
+! NO-NSW: ^[[RETURN]]:
+! NO-NSW: return
subroutine empty_infinite_in_while(i)
integer :: i
diff --git a/flang/test/Lower/io-implied-do-fixes.f90 b/flang/test/Lower/io-implied-do-fixes.f90
index a6c115fa80ded1..0180c9f31e2f69 100644
--- a/flang/test/Lower/io-implied-do-fixes.f90
+++ b/flang/test/Lower/io-implied-do-fixes.f90
@@ -1,5 +1,5 @@
! RUN: bbc --use-desc-for-alloc=false -emit-fir -hlfir=false %s -o - | FileCheck %s
-! RUN: bbc --use-desc-for-alloc=false -emit-fir -hlfir=false -integer-overflow %s -o - | FileCheck %s --check-prefix=NSW
+! RUN: bbc --use-desc-for-alloc=false -emit-fir -hlfir=false -fwrapv %s -o - | FileCheck %s --check-prefix=NO-NSW
! UNSUPPORTED: system-windows
! CHECK-LABEL: func @_QPido1
@@ -8,23 +8,23 @@
! CHECK: %[[J_VAL_FINAL:.*]] = fir.do_loop %[[J_VAL:.*]] = %{{.*}} to %{{.*}} step %{{.*}} -> index {
! CHECK: %[[J_VAL_CVT1:.*]] = fir.convert %[[J_VAL]] : (index) -> i32
! CHECK: fir.store %[[J_VAL_CVT1]] to %[[J_ADDR]] : !fir.ptr<i32>
-! CHECK: %[[J_VAL_NEXT:.*]] = arith.addi %[[J_VAL]], %{{[^ ]*}} : index
+! CHECK: %[[J_VAL_NEXT:.*]] = arith.addi %[[J_VAL]], %{{[^ ]*}} overflow<nsw> : index
! CHECK: fir.result %[[J_VAL_NEXT]] : index
! CHECK: }
! CHECK: %[[J_VAL_CVT2:.*]] = fir.convert %[[J_VAL_FINAL]] : (index) -> i32
! CHECK: fir.store %[[J_VAL_CVT2]] to %[[J_ADDR]] : !fir.ptr<i32>
-! NSW-LABEL: func @_QPido1
-! NSW: %[[J_REF_ADDR:.*]] = fir.alloca !fir.ptr<i32> {uniq_name = "_QFido1Eiptr.addr"}
-! NSW: %[[J_ADDR:.*]] = fir.load %[[J_REF_ADDR]] : !fir.ref<!fir.ptr<i32>>
-! NSW: %[[J_VAL_FINAL:.*]] = fir.do_loop %[[J_VAL:.*]] = %{{.*}} to %{{.*}} step %{{.*}} -> index {
-! NSW: %[[J_VAL_CVT1:.*]] = fir.convert %[[J_VAL]] : (index) -> i32
-! NSW: fir.store %[[J_VAL_CVT1]] to %[[J_ADDR]] : !fir.ptr<i32>
-! NSW: %[[J_VAL_NEXT:.*]] = arith.addi %[[J_VAL]], %{{[^ ]*}} overflow<nsw> : index
-! NSW: fir.result %[[J_VAL_NEXT]] : index
-! NSW: }
-! NSW: %[[J_VAL_CVT2:.*]] = fir.convert %[[J_VAL_FINAL]] : (index) -> i32
-! NSW: fir.store %[[J_VAL_CVT2]] to %[[J_ADDR]] : !fir.ptr<i32>
+! NO-NSW-LABEL: func @_QPido1
+! NO-NSW: %[[J_REF_ADDR:.*]] = fir.alloca !fir.ptr<i32> {uniq_name = "_QFido1Eiptr.addr"}
+! NO-NSW: %[[J_ADDR:.*]] = fir.load %[[J_REF_ADDR]] : !fir.ref<!fir.ptr<i32>>
+! NO-NSW: %[[J_VAL_FINAL:.*]] = fir.do_loop %[[J_VAL:.*]] = %{{.*}} to %{{.*}} step %{{.*}} -> index {
+! NO-NSW: %[[J_VAL_CVT1:.*]] = fir.convert %[[J_VAL]] : (index) -> i32
+! NO-NSW: fir.store %[[J_VAL_CVT1]] to %[[J_ADDR]] : !fir.ptr<i32>
+! NO-NSW: %[[J_VAL_NEXT:.*]] = arith.addi %[[J_VAL]], %{{[^ ]*}} : index
+! NO-NSW: fir.result %[[J_VAL_NEXT]] : index
+! NO-NSW: }
+! NO-NSW: %[[J_VAL_CVT2:.*]] = fir.convert %[[J_VAL_FINAL]] : (index) -> i32
+! NO-NSW: fir.store %[[J_VAL_CVT2]] to %[[J_ADDR]] : !fir.ptr<i32>
subroutine ido1
integer, pointer :: iptr
integer, target :: itgt
@@ -38,23 +38,23 @@ subroutine ido1
! CHECK: %[[J_VAL_FINAL:.*]] = fir.do_loop %[[J_VAL:.*]] = %{{.*}} to %{{.*}} step %{{.*}} -> index {
! CHECK: %[[J_VAL_CVT1:.*]] = fir.convert %[[J_VAL]] : (index) -> i32
! CHECK: fir.store %[[J_VAL_CVT1]] to %[[J_ADDR]] : !fir.heap<i32>
-! CHECK: %[[J_VAL_NEXT:.*]] = arith.addi %[[J_VAL]], %{{[^ ]*}} : index
+! CHECK: %[[J_VAL_NEXT:.*]] = arith.addi %[[J_VAL]], %{{[^ ]*}} overflow<nsw> : index
! CHECK: fir.result %[[J_VAL_NEXT]] : index
! CHECK: }
! CHECK: %[[J_VAL_CVT2:.*]] = fir.convert %[[J_VAL_FINAL]] : (index) -> i32
! CHECK: fir.store %[[J_VAL_CVT2]] to %[[J_ADDR]] : !fir.heap<i32>
-! NSW-LABEL: func @_QPido2
-! NSW: %[[J_REF_ADDR:.*]] = fir.alloca !fir.heap<i32> {uniq_name = "_QFido2Eiptr.addr"}
-! NSW: %[[J_ADDR:.*]] = fir.load %[[J_REF_ADDR]] : !fir.ref<!fir.heap<i32>>
-! NSW: %[[J_VAL_FINAL:.*]] = fir.do_loop %[[J_VAL:.*]] = %{{.*}} to %{{.*}} step %{{.*}} -> index {
-! NSW: %[[J_VAL_CVT1:.*]] = fir.convert %[[J_VAL]] : (index) -> i32
-! NSW: fir.store %[[J_VAL_CVT1]] to %[[J_ADDR]] : !fir.heap<i32>
-! NSW: %[[J_VAL_NEXT:.*]] = arith.addi %[[J_VAL]], %{{[^ ]*}} overflow<nsw> : index
-! NSW: fir.result %[[J_VAL_NEXT]] : index
-! NSW: }
-! NSW: %[[J_VAL_CVT2:.*]] = fir.convert %[[J_VAL_FINAL]] : (index) -> i32
-! NSW: fir.store %[[J_VAL_CVT2]] to %[[J_ADDR]] : !fir.heap<i32>
+! NO-NSW-LABEL: func @_QPido2
+! NO-NSW: %[[J_REF_ADDR:.*]] = fir.alloca !fir.heap<i32> {uniq_name = "_QFido2Eiptr.addr"}
+! NO-NSW: %[[J_ADDR:.*]] = fir.load %[[J_REF_ADDR]] : !fir.ref<!fir.heap<i32>>
+! NO-NSW: %[[J_VAL_FINAL:.*]] = fir.do_loop %[[J_VAL:.*]] = %{{.*}} to %{{.*}} step %{{.*}} -> index {
+! NO-NSW: %[[J_VAL_CVT1:.*]] = fir.convert %[[J_VAL]] : (index) -> i32
+! NO-NSW: fir.store %[[J_VAL_CVT1]] to %[[J_ADDR]] : !fir.heap<i32>
+! NO-NSW: %[[J_VAL_NEXT:.*]] = arith.addi %[[J_VAL]], %{{[^ ]*}} : index
+! NO-NSW: fir.result %[[J_VAL_NEXT]] : index
+! NO-NSW: }
+! NO-NSW: %[[J_VAL_CVT2:.*]] = fir.convert %[[J_VAL_FINAL]] : (index) -> i32
+! NO-NSW: fir.store %[[J_VAL_CVT2]] to %[[J_ADDR]] : !fir.heap<i32>
subroutine ido2
integer, allocatable :: iptr
allocate(iptr)
@@ -69,27 +69,27 @@ subroutine ido2
! CHECK: fir.store %[[J_VAL_CVT1]] to %[[J_ADDR]] : !fir.heap<i32>
! CHECK: %[[RES:.*]] = fir.if %[[OK]] -> (i1) {
! CHECK: }
-! CHECK: %[[J_VAL_INC:.*]] = arith.addi %[[J_VAL]], %{{[^ ]*}} : index
+! CHECK: %[[J_VAL_INC:.*]] = arith.addi %[[J_VAL]], %{{[^ ]*}} overflow<nsw> : index
! CHECK: %[[J_VAL_NEXT:.*]] = arith.select %[[RES]], %[[J_VAL_INC]], %[[J_VAL]] : index
! CHECK: fir.result %[[J_VAL_NEXT]], %[[RES]] : index, i1
! CHECK: }
! CHECK: %[[J_VAL_CVT2:.*]] = fir.convert %[[J_VAL_FINAL]]#0 : (index) -> i32
! CHECK: fir.store %[[J_VAL_CVT2]] to %[[J_ADDR]] : !fir.heap<i32
-! NSW-LABEL: func @_QPido3
-! NSW: %[[J_REF_ADDR:.*]] = fir.alloca !fir.heap<i32> {uniq_name = "_QFido3Ej.addr"}
-! NSW: %[[J_ADDR:.*]] = fir.load %[[J_REF_ADDR]] : !fir.ref<!fir.heap<i32>>
-! NSW: %[[J_VAL_FINAL:.*]]:2 = fir.iterate_while (%[[J_VAL:.*]] = %{{.*}} to %{{.*}} step %{{.*}}) and (%[[OK:.*]] = {{.*}}) -> (index, i1) {
-! NSW: %[[J_VAL_CVT1:.*]] = fir.convert %[[J_VAL]] : (index) -> i32
-! NSW: fir.store %[[J_VAL_CVT1]] to %[[J_ADDR]] : !fir.heap<i32>
-! NSW: %[[RES:.*]] = fir.if %[[OK]] -> (i1) {
-! NSW: }
-! NSW: %[[J_VAL_INC:.*]] = arith.addi %[[J_VAL]], %{{[^ ]*}} overflow<nsw> : index
-! NSW: %[[J_VAL_NEXT:.*]] = arith.select %[[RES]], %[[J_VAL_INC]], %[[J_VAL]] : index
-! NSW: fir.result %[[J_VAL_NEXT]], %[[RES]] : index, i1
-! NSW: }
-! NSW: %[[J_VAL_CVT2:.*]] = fir.convert %[[J_VAL_FINAL]]#0 : (index) -> i32
-! NSW: fir.store %[[J_VAL_CVT2]] to %[[J_ADDR]] : !fir.heap<i32
+! NO-NSW-LABEL: func @_QPido3
+! NO-NSW: %[[J_REF_ADDR:.*]] = fir.alloca !fir.heap<i32> {uniq_name = "_QFido3Ej.addr"}
+! NO-NSW: %[[J_ADDR:.*]] = fir.load %[[J_REF_ADDR]] : !fir.ref<!fir.heap<i32>>
+! NO-NSW: %[[J_VAL_FINAL:.*]]:2 = fir.iterate_while (%[[J_VAL:.*]] = %{{.*}} to %{{.*}} step %{{.*}}) and (%[[OK:.*]] = {{.*}}) -> (index, i1) {
+! NO-NSW: %[[J_VAL_CVT1:.*]] = fir.convert %[[J_VAL]] : (index) -> i32
+! NO-NSW: fir.store %[[J_VAL_CVT1]] to %[[J_ADDR]] : !fir.heap<i32>
+! NO-NSW: %[[RES:.*]] = fir.if %[[OK]] -> (i1) {
+! NO-NSW: }
+! NO-NSW: %[[J_VAL_INC:.*]] = arith.addi %[[J_VAL]], %{{[^ ]*}} : index
+! NO-NSW: %[[J_VAL_NEXT:.*]] = arith.select %[[RES]], %[[J_VAL_INC]], %[[J_VAL]] : index
+! NO-NSW: fir.result %[[J_VAL_NEXT]], %[[RES]] : index, i1
+! NO-NSW: }
+! NO-NSW: %[[J_VAL_CVT2:.*]] = fir.convert %[[J_VAL_FINAL]]#0 : (index) -> i32
+! NO-NSW: fir.store %[[J_VAL_CVT2]] to %[[J_ADDR]] : !fir.heap<i32
subroutine ido3
integer, allocatable :: j
allocate(j)
diff --git a/flang/test/Lower/loops2.f90 b/flang/test/Lower/loops2.f90
index 0a587234a991b6..60a6bf6c531197 100644
--- a/flang/test/Lower/loops2.f90
+++ b/flang/test/Lower/loops2.f90
@@ -107,7 +107,7 @@ subroutine test_pointer_unstructured_loop()
! CHECK: ^bb4:
! CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_3]] : !fir.ptr<i32>
! CHECK: %[[VAL_21:.*]] = arith.constant 1 : i32
-! CHECK: %[[VAL_22:.*]] = arith.addi %[[VAL_20]], %[[VAL_21]] : i32
+! CHECK: %[[VAL_22:.*]] = arith.addi %[[VAL_20]], %[[VAL_21]] overflow<nsw> : i32
! CHECK: fir.store %[[VAL_22]] to %[[VAL_3]] : !fir.ptr<i32>
! CHECK: br ^bb1
! CHECK: ^bb5:
diff --git a/flang/test/Lower/mixed_loops.f90 b/flang/test/Lower/mixed_loops.f90
index 1aa0225129bed6..991fd7aa82bb95 100644
--- a/flang/test/Lower/mixed_loops.f90
+++ b/flang/test/Lower/mixed_loops.f90
@@ -53,7 +53,7 @@ subroutine while_inside_do_loop
! CHECK: fir.store %[[TDEC]] to %[[T_REF]]
! CHECK: %[[I3:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
! CHECK: %[[C1_2:.*]] = arith.constant 1 : i32
- ! CHECK: %[[IINC:.*]] = arith.addi %[[I3]], %[[C1_2]] : i32
+ ! CHECK: %[[IINC:.*]] = arith.addi %[[I3]], %[[C1_2]] overflow<nsw> : i32
! CHECK: fir.store %[[IINC]] to %[[I_REF]] : !fir.ref<i32>
! CHECK: br ^[[HDR1]]
end do
@@ -100,10 +100,10 @@ subroutine do_inside_while_loop
! CHECK-DAG: %[[C2:.*]] = arith.constant 2 : i32
! CHECK: %[[JINC:.*]] = arith.muli %[[C2]], %[[J2]] : i32
! CHECK: fir.store %[[JINC]] to %[[J_REF]] : !fir.ref<i32>
- ! CHECK: %[[IINC:.*]] = arith.addi %[[IDX]], %[[C1]] : index
+ ! CHECK: %[[IINC:.*]] = arith.addi %[[IDX]], %[[C1]] overflow<nsw> : index
! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[C1]] : (index) -> i32
! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
- ! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i32
+ ! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] overflow<nsw> : i32
! CHECK: fir.result %[[IINC]], %[[I_IVINC]] : index, i32
do i=8,13
j=j*2
diff --git a/flang/test/Lower/vector-subscript-io.f90 b/flang/test/Lower/vector-subscript-io.f90
index d298609269dae9..9448e30280504b 100644
--- a/flang/test/Lower/vector-subscript-io.f90
+++ b/flang/test/Lower/vector-subscript-io.f90
@@ -30,7 +30,7 @@ subroutine simple(x, y)
! CHECK: %[[VAL_19:.*]] = fir.array_coor %[[VAL_20]](%[[VAL_10]]) {{\[}}%[[VAL_11]]] %[[VAL_18]] : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>, !fir.slice<1>, index) -> !fir.ref<i32>
! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_19]] : (!fir.ref<i32>) -> !fir.ref<i64>
! CHECK: %[[VAL_22:.*]] = fir.call @_FortranAioInputInteger(%[[VAL_9]], %[[VAL_21]], %[[VAL_3]]) {{.*}}: (!fir.ref<i8>, !fir.ref<i64>, i32) -> i1
-! CHECK: %[[VAL_23:.*]] = arith.addi %[[VAL_12]], %[[VAL_6]] : index
+! CHECK: %[[VAL_23:.*]] = arith.addi %[[VAL_12]], %[[VAL_6]] overflow<nsw> : index
! CHECK: %[[VAL_24:.*]] = arith.subi %[[VAL_13]], %[[VAL_6]] : index
! CHECK: cf.br ^bb1(%[[VAL_23]], %[[VAL_24]] : index, index)
! CHECK: ^bb3:
@@ -79,7 +79,7 @@ integer function get_substcript()
! CHECK: %[[VAL_49:.*]] = fir.convert %[[VAL_48]] : (i32) -> index
! CHECK: %[[VAL_50:.*]] = fir.array_coor %[[VAL_51]] {{\[}}%[[VAL_42]]] %[[VAL_46]], %[[VAL_49]] : (!fir.box<!fir.array<?x?xf32>>, !fir.slice<2>, index, index) -> !fir.ref<f32>
! CHECK: %[[VAL_52:.*]] = fir.call @_FortranAioInputReal32(%[[VAL_34]], %[[VAL_50]]) {{.*}}: (!fir.ref<i8>, !fir.ref<f32>) -> i1
-! CHECK: %[[VAL_53:.*]] = arith.addi %[[VAL_43]], %[[VAL_30]] : index
+! CHECK: %[[VAL_53:.*]] = arith.addi %[[VAL_43]], %[[VAL_30]] overflow<nsw> : index
! CHECK: %[[VAL_54:.*]] = arith.subi %[[VAL_44]], %[[VAL_30]] : index
! CHECK: cf.br ^bb1(%[[VAL_53]], %[[VAL_54]] : index, index)
! CHECK: ^bb3:
@@ -122,7 +122,7 @@ subroutine with_assumed_shapes(x, y)
! CHECK: %[[VAL_77:.*]] = fir.array_coor %[[VAL_78]] {{\[}}%[[VAL_70]]] %[[VAL_76]] : (!fir.box<!fir.array<?xi32>>, !fir.slice<1>, index) -> !fir.ref<i32>
! CHECK: %[[VAL_79:.*]] = fir.convert %[[VAL_77]] : (!fir.ref<i32>) -> !fir.ref<i64>
! CHECK: %[[VAL_80:.*]] = fir.call @_FortranAioInputInteger(%[[VAL_67]], %[[VAL_79]], %[[VAL_62]]) {{.*}}: (!fir.ref<i8>, !fir.ref<i64>, i32) -> i1
-! CHECK: %[[VAL_81:.*]] = arith.addi %[[VAL_71]], %[[VAL_64]] : index
+! CHECK: %[[VAL_81:.*]] = arith.addi %[[VAL_71]], %[[VAL_64]] overflow<nsw> : index
! CHECK: %[[VAL_82:.*]] = arith.subi %[[VAL_72]], %[[VAL_64]] : index
! CHECK: cf.br ^bb1(%[[VAL_81]], %[[VAL_82]] : index, index)
! CHECK: ^bb3:
@@ -162,7 +162,7 @@ subroutine lower_bounds(x, y)
! CHECK: %[[VAL_107:.*]] = fir.array_coor %[[VAL_108]](%[[VAL_97]]) {{\[}}%[[VAL_99]]] %[[VAL_91]], %[[VAL_106]] : (!fir.ref<!fir.array<4x6xi32>>, !fir.shapeshift<2>, !fir.slice<2>, index, index) -> !fir.ref<i32>
! CHECK: %[[VAL_109:.*]] = fir.convert %[[VAL_107]] : (!fir.ref<i32>) -> !fir.ref<i64>
! CHECK: %[[VAL_110:.*]] = fir.call @_FortranAioInputInteger(%[[VAL_96]], %[[VAL_109]], %[[VAL_90]]) {{.*}}: (!fir.ref<i8>, !fir.ref<i64>, i32) -> i1
-! CHECK: %[[VAL_111:.*]] = arith.addi %[[VAL_100]], %[[VAL_93]] : index
+! CHECK: %[[VAL_111:.*]] = arith.addi %[[VAL_100]], %[[VAL_93]] overflow<nsw> : index
! CHECK: %[[VAL_112:.*]] = arith.subi %[[VAL_101]], %[[VAL_93]] : index
! CHECK: cf.br ^bb1(%[[VAL_111]], %[[VAL_112]] : index, index)
! CHECK: ^bb3:
@@ -202,11 +202,11 @@ subroutine two_vectors(x, y1, y2)
! CHECK: %[[VAL_138:.*]] = fir.convert %[[VAL_137]] : (i32) -> index
! CHECK: %[[VAL_139:.*]] = fir.array_coor %[[VAL_140]](%[[VAL_123]]) {{\[}}%[[VAL_124]]] %[[VAL_134]], %[[VAL_138]] : (!fir.ref<!fir.array<4x4xf32>>, !fir.shape<2>, !fir.slice<2>, index, index) -> !fir.ref<f32>
! CHECK: %[[VAL_141:.*]] = fir.call @_FortranAioInputReal32(%[[VAL_122]], %[[VAL_139]]) {{.*}}: (!fir.ref<i8>, !fir.ref<f32>) -> i1
-! CHECK: %[[VAL_142:.*]] = arith.addi %[[VAL_128]], %[[VAL_119]] : index
+! CHECK: %[[VAL_142:.*]] = arith.addi %[[VAL_128]], %[[VAL_119]] overflow<nsw> : index
! CHECK: %[[VAL_143:.*]] = arith.subi %[[VAL_129]], %[[VAL_119]] : index
! CHECK: cf.br ^bb2(%[[VAL_142]], %[[VAL_143]] : index, index)
! CHECK: ^bb4:
-! CHECK: %[[VAL_144:.*]] = arith.addi %[[VAL_125]], %[[VAL_119]] : index
+! CHECK: %[[VAL_144:.*]] = arith.addi %[[VAL_125]], %[[VAL_119]] overflow<nsw> : index
! CHECK: %[[VAL_145:.*]] = arith.subi %[[VAL_126]], %[[VAL_119]] : index
! CHECK: cf.br ^bb1(%[[VAL_144]], %[[VAL_145]] : index, index)
! CHECK: ^bb5:
@@ -245,11 +245,11 @@ subroutine triplets_and_vector(x, y)
! CHECK: %[[VAL_169:.*]] = fir.array_coor %[[VAL_170]](%[[VAL_157]]) {{\[}}%[[VAL_158]]] %[[VAL_162]], %[[VAL_168]] : (!fir.ref<!fir.array<4x4x!fir.complex<4>>>, !fir.shape<2>, !fir.slice<2>, index, index) -> !fir.ref<!fir.complex<4>>
! CHECK: %[[VAL_171:.*]] = fir.convert %[[VAL_169]] : (!fir.ref<!fir.complex<4>>) -> !fir.ref<f32>
! CHECK: %[[VAL_172:.*]] = fir.call @_FortranAioInputComplex32(%[[VAL_156]], %[[VAL_171]]) {{.*}}: (!fir.ref<i8>, !fir.ref<f32>) -> i1
-! CHECK: %[[VAL_173:.*]] = arith.addi %[[VAL_162]], %[[VAL_153]] : index
+! CHECK: %[[VAL_173:.*]] = arith.addi %[[VAL_162]], %[[VAL_153]] overflow<nsw> : index
! CHECK: %[[VAL_174:.*]] = arith.subi %[[VAL_163]], %[[VAL_153]] : index
! CHECK: cf.br ^bb2(%[[VAL_173]], %[[VAL_174]] : index, index)
! CHECK: ^bb4:
-! CHECK: %[[VAL_175:.*]] = arith.addi %[[VAL_159]], %[[VAL_153]] : index
+! CHECK: %[[VAL_175:.*]] = arith.addi %[[VAL_159]], %[[VAL_153]] overflow<nsw> : index
! CHECK: %[[VAL_176:.*]] = arith.subi %[[VAL_160]], %[[VAL_153]] : index
! CHECK: cf.br ^bb1(%[[VAL_175]], %[[VAL_176]] : index, index)
! CHECK: ^bb5:
@@ -287,7 +287,7 @@ subroutine simple_char(x, y)
! CHECK: %[[VAL_200:.*]] = fir.convert %[[VAL_199]] : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<i8>
! CHECK: %[[VAL_201:.*]] = fir.convert %[[VAL_184]]#1 : (index) -> i64
! CHECK: %[[VAL_202:.*]] = fir.call @_FortranAioInputAscii(%[[VAL_189]], %[[VAL_200]], %[[VAL_201]]) {{.*}}: (!fir.ref<i8>, !fir.ref<i8>, i64) -> i1
-! CHECK: %[[VAL_203:.*]] = arith.addi %[[VAL_192]], %[[VAL_183]] : index
+! CHECK: %[[VAL_203:.*]] = arith.addi %[[VAL_192]], %[[VAL_183]] overflow<nsw> : index
! CHECK: %[[VAL_204:.*]] = arith.subi %[[VAL_193]], %[[VAL_183]] : index
! CHECK: cf.br ^bb1(%[[VAL_203]], %[[VAL_204]] : index, index)
! CHECK: ^bb3:
@@ -333,7 +333,7 @@ subroutine substring(x, y, i, j)
! CHECK: %[[VAL_238:.*]] = fir.convert %[[VAL_233]] : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<i8>
! CHECK: %[[VAL_239:.*]] = fir.convert %[[VAL_237]] : (index) -> i64
! CHECK: %[[VAL_240:.*]] = fir.call @_FortranAioInputAscii(%[[VAL_213]], %[[VAL_238]], %[[VAL_239]]) {{.*}}: (!fir.ref<i8>, !fir.ref<i8>, i64) -> i1
-! CHECK: %[[VAL_241:.*]] = arith.addi %[[VAL_221]], %[[VAL_210]] : index
+! CHECK: %[[VAL_241:.*]] = arith.addi %[[VAL_221]], %[[VAL_210]] overflow<nsw> : index
! CHECK: %[[VAL_242:.*]] = arith.subi %[[VAL_222]], %[[VAL_210]] : index
! CHECK: cf.br ^bb1(%[[VAL_241]], %[[VAL_242]] : index, index)
! CHECK: ^bb3:
@@ -366,7 +366,7 @@ subroutine complex_part(z, y)
! CHECK: %[[VAL_260:.*]] = fir.convert %[[VAL_259]] : (i32) -> index
! CHECK: %[[VAL_261:.*]] = fir.array_coor %[[VAL_262]] {{\[}}%[[VAL_254]]] %[[VAL_260]] : (!fir.box<!fir.array<?x!fir.complex<4>>>, !fir.slice<1>, index) -> !fir.ref<f32>
! CHECK: %[[VAL_263:.*]] = fir.call @_FortranAioInputReal32(%[[VAL_251]], %[[VAL_261]]) {{.*}}: (!fir.ref<i8>, !fir.ref<f32>) -> i1
-! CHECK: %[[VAL_264:.*]] = arith.addi %[[VAL_255]], %[[VAL_248]] : index
+! CHECK: %[[VAL_264:.*]] = arith.addi %[[VAL_255]], %[[VAL_248]] overflow<nsw> : index
! CHECK: %[[VAL_265:.*]] = arith.subi %[[VAL_256]], %[[VAL_248]] : index
! CHECK: cf.br ^bb1(%[[VAL_264]], %[[VAL_265]] : index, index)
! CHECK: ^bb3:
@@ -414,7 +414,7 @@ subroutine simple_derived(x, y)
! CHECK: %[[VAL_288:.*]] = fir.embox %[[VAL_286]] : (!fir.ref<!fir.type<_QMderived_typesTt{i:i32,c:!fir.char<1,2>}>>) -> !fir.box<!fir.type<_QMderived_typesTt{i:i32,c:!fir.char<1,2>}>>
! CHECK: %[[VAL_289:.*]] = fir.convert %[[VAL_288]] : (!fir.box<!fir.type<_QMderived_typesTt{i:i32,c:!fir.char<1,2>}>>) -> !fir.box<none>
! CHECK: %[[VAL_290:.*]] = fir.call @_FortranAioInputDerivedType(%[[VAL_276]], %[[VAL_289]], {{.*}}) {{.*}}: (!fir.ref<i8>, !fir.box<none>, !fir.ref<none>) -> i1
-! CHECK: %[[VAL_291:.*]] = arith.addi %[[VAL_279]], %[[VAL_273]] : index
+! CHECK: %[[VAL_291:.*]] = arith.addi %[[VAL_279]], %[[VAL_273]] overflow<nsw> : index
! CHECK: %[[VAL_292:.*]] = arith.subi %[[VAL_280]], %[[VAL_273]] : index
! CHECK: cf.br ^bb1(%[[VAL_291]], %[[VAL_292]] : index, index)
! CHECK: ^bb3:
@@ -463,11 +463,11 @@ subroutine with_path(b, i)
! CHECK: %[[VAL_325:.*]] = fir.array_coor %[[VAL_326:.*]](%[[VAL_313]]) {{\[}}%[[VAL_315]]] %[[VAL_301]], %[[VAL_324]], %[[VAL_316]] : (!fir.box<!fir.array<?x?x?x!fir.type<_QMderived_typesTt2{a:!fir.array<5x5x!fir.type<_QMderived_typesTt{i:i32,c:!fir.char<1,2>}>>}>>>, !fir.shift<3>, !fir.slice<3>, index, index, index) -> !fir.ref<i32>
! CHECK: %[[VAL_327:.*]] = fir.convert %[[VAL_325]] : (!fir.ref<i32>) -> !fir.ref<i64>
! CHECK: %[[VAL_328:.*]] = fir.call @_FortranAioInputInteger(%[[VAL_308]], %[[VAL_327]], %[[VAL_302]]) {{.*}}: (!fir.ref<i8>, !fir.ref<i64>, i32) -> i1
-! CHECK: %[[VAL_329:.*]] = arith.addi %[[VAL_319]], %[[VAL_305]] : index
+! CHECK: %[[VAL_329:.*]] = arith.addi %[[VAL_319]], %[[VAL_305]] overflow<nsw> : index
! CHECK: %[[VAL_330:.*]] = arith.subi %[[VAL_320]], %[[VAL_305]] : index
! CHECK: cf.br ^bb2(%[[VAL_329]], %[[VAL_330]] : index, index)
! CHECK: ^bb4:
-! CHECK: %[[VAL_331:.*]] = arith.addi %[[VAL_316]], %[[VAL_305]] : index
+! CHECK: %[[VAL_331:.*]] = arith.addi %[[VAL_316]], %[[VAL_305]] overflow<nsw> : index
! CHECK: %[[VAL_332:.*]] = arith.subi %[[VAL_317]], %[[VAL_305]] : index
! CHECK: cf.br ^bb1(%[[VAL_331]], %[[VAL_332]] : index, index)
! CHECK: ^bb5:
@@ -505,7 +505,7 @@ subroutine simple_iostat(x, y, j, stat)
! CHECK: %[[VAL_355:.*]] = fir.convert %[[VAL_354]] : (i32) -> index
! CHECK: %[[VAL_356:.*]] = fir.array_coor %[[VAL_357]] {{\[}}%[[VAL_347]]] %[[VAL_355]] : (!fir.box<!fir.array<?xf32>>, !fir.slice<1>, index) -> !fir.ref<f32>
! CHECK: %[[VAL_358:.*]] = fir.call @_FortranAioInputReal32(%[[VAL_343]], %[[VAL_356]]) {{.*}}: (!fir.ref<i8>, !fir.ref<f32>) -> i1
-! CHECK: %[[VAL_359:.*]] = arith.addi %[[VAL_349]], %[[VAL_338]] : index
+! CHECK: %[[VAL_359:.*]] = arith.addi %[[VAL_349]], %[[VAL_338]] overflow<nsw> : index
! CHECK: cf.br ^bb1(%[[VAL_359]], %[[VAL_358]] : index, i1)
! CHECK: ^bb3:
! CHECK: cf.cond_br %[[VAL_350]], ^bb4, ^bb5
@@ -568,10 +568,10 @@ subroutine iostat_in_io_loop(k, j, stat)
! CHECK: %[[VAL_399:.*]] = fir.array_coor %[[VAL_400]](%[[VAL_387]]) {{\[}}%[[VAL_389]]] %[[VAL_394]], %[[VAL_398]] : (!fir.ref<!fir.array<3x5xi32>>, !fir.shape<2>, !fir.slice<2>, index, index) -> !fir.ref<i32>
! CHECK: %[[VAL_401:.*]] = fir.convert %[[VAL_399]] : (!fir.ref<i32>) -> !fir.ref<i64>
! CHECK: %[[VAL_402:.*]] = fir.call @_FortranAioInputInteger(%[[VAL_378]], %[[VAL_401]], %[[VAL_374]]) {{.*}}: (!fir.ref<i8>, !fir.ref<i64>, i32) -> i1
-! CHECK: %[[VAL_403:.*]] = arith.addi %[[VAL_390]], %[[VAL_371]] : index
+! CHECK: %[[VAL_403:.*]] = arith.addi %[[VAL_390]], %[[VAL_371]] overflow<nsw> : index
! CHECK: cf.br ^bb4(%[[VAL_403]], %[[VAL_402]] : index, i1)
! CHECK: ^bb6(%[[VAL_404:.*]]: i1):
-! CHECK: %[[VAL_405:.*]] = arith.addi %[[VAL_380]], %[[VAL_371]] : index
+! CHECK: %[[VAL_405:.*]] = arith.addi %[[VAL_380]], %[[VAL_371]] overflow<nsw> : index
! CHECK: cf.br ^bb1(%[[VAL_405]], %[[VAL_404]] : index, i1)
! CHECK: ^bb7:
! CHECK: %[[VAL_406:.*]] = fir.convert %[[VAL_380]] : (index) -> i32
diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index dcff4503f16571..32102a15126c63 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -227,10 +227,10 @@ static llvm::cl::opt<std::string>
llvm::cl::desc("Override host target triple"),
llvm::cl::init(""));
-static llvm::cl::opt<bool>
- setNSW("integer-overflow",
- llvm::cl::desc("add nsw flag to internal operations"),
- llvm::cl::init(false));
+static llvm::cl::opt<bool> integerWrapAround(
+ "fwrapv",
+ llvm::cl::desc("Treat signed integer overflow as two's complement"),
+ llvm::cl::init(false));
#define FLANG_EXCLUDE_CODEGEN
#include "flang/Tools/CLOptions.inc"
@@ -371,7 +371,7 @@ static llvm::LogicalResult convertFortranSourceToMLIR(
Fortran::lower::LoweringOptions loweringOptions{};
loweringOptions.setNoPPCNativeVecElemOrder(enableNoPPCNativeVecElemOrder);
loweringOptions.setLowerToHighLevelFIR(useHLFIR || emitHLFIR);
- loweringOptions.setNSWOnLoopVarInc(setNSW);
+ loweringOptions.setIntegerWrapAround(integerWrapAround);
std::vector<Fortran::lower::EnvironmentDefault> envDefaults = {};
constexpr const char *tuneCPU = "";
auto burnside = Fortran::lower::LoweringBridge::create(
@@ -456,7 +456,7 @@ static llvm::LogicalResult convertFortranSourceToMLIR(
// Add O2 optimizer pass pipeline.
MLIRToLLVMPassPipelineConfig config(llvm::OptimizationLevel::O2);
- config.NSWOnLoopVarInc = setNSW;
+ config.NSWOnLoopVarInc = !integerWrapAround;
fir::registerDefaultInlinerPass(config);
fir::createDefaultFIROptimizerPassPipeline(pm, config);
}
More information about the cfe-commits
mailing list