Skip to content

Commit 2723e8a

Browse files
committed
Reland "[flang] Integrate the option -flang-experimental-integer-overflow into -fno-wrapv"
This relands #110063.
1 parent eb49788 commit 2723e8a

40 files changed

+119
-676
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6836,10 +6836,6 @@ def flang_deprecated_no_hlfir : Flag<["-"], "flang-deprecated-no-hlfir">,
68366836
Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
68376837
HelpText<"Do not use HLFIR lowering (deprecated)">;
68386838

6839-
def flang_experimental_integer_overflow : Flag<["-"], "flang-experimental-integer-overflow">,
6840-
Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
6841-
HelpText<"Add nsw flag to internal operations such as do-variable increment (experimental)">;
6842-
68436839
//===----------------------------------------------------------------------===//
68446840
// FLangOption + CoreOption + NoXarchOption
68456841
//===----------------------------------------------------------------------===//

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ void Flang::addCodegenOptions(const ArgList &Args,
148148

149149
Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
150150
options::OPT_flang_deprecated_no_hlfir,
151-
options::OPT_flang_experimental_integer_overflow,
152151
options::OPT_fno_ppc_native_vec_elem_order,
153152
options::OPT_fppc_native_vec_elem_order});
154153
}

flang/include/flang/Lower/LoweringOptions.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,5 @@ ENUM_LOWERINGOPT(Underscoring, unsigned, 1, 1)
3838
/// (i.e. wraps around as two's complement). Off by default.
3939
ENUM_LOWERINGOPT(IntegerWrapAround, unsigned, 1, 0)
4040

41-
/// If true, add nsw flags to loop variable increments.
42-
/// Off by default.
43-
/// TODO: integrate this option with the above
44-
ENUM_LOWERINGOPT(NSWOnLoopVarInc, unsigned, 1, 0)
45-
4641
#undef LOWERINGOPT
4742
#undef ENUM_LOWERINGOPT

flang/include/flang/Optimizer/Transforms/Passes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace fir {
6666
std::unique_ptr<mlir::Pass> createAffineDemotionPass();
6767
std::unique_ptr<mlir::Pass>
6868
createArrayValueCopyPass(fir::ArrayValueCopyOptions options = {});
69-
std::unique_ptr<mlir::Pass> createCFGConversionPassWithNSW();
69+
std::unique_ptr<mlir::Pass> createCFGConversionPassWithoutNSW();
7070
std::unique_ptr<mlir::Pass> createMemDataFlowOptPass();
7171
std::unique_ptr<mlir::Pass> createPromoteToAffinePass();
7272
std::unique_ptr<mlir::Pass>
@@ -83,7 +83,7 @@ createVScaleAttrPass(std::pair<unsigned, unsigned> vscaleAttr);
8383

8484
void populateCfgConversionRewrites(mlir::RewritePatternSet &patterns,
8585
bool forceLoopToExecuteOnce = false,
86-
bool setNSW = false);
86+
bool setNSW = true);
8787

8888
// declarative passes
8989
#define GEN_PASS_REGISTRATION

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def CFGConversion : Pass<"cfg-conversion"> {
153153
/*default=*/"false",
154154
"force the body of a loop to execute at least once">,
155155
Option<"setNSW", "set-nsw", "bool",
156-
/*default=*/"false",
156+
/*default=*/"true",
157157
"set nsw on loop variable increment">
158158
];
159159
}

flang/include/flang/Tools/CrossToolHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks {
122122
bool NoSignedZerosFPMath =
123123
false; ///< Set no-signed-zeros-fp-math attribute for functions.
124124
bool UnsafeFPMath = false; ///< Set unsafe-fp-math attribute for functions.
125-
bool NSWOnLoopVarInc = false; ///< Add nsw flag to loop variable increments.
125+
bool NSWOnLoopVarInc = true; ///< Add nsw flag to loop variable increments.
126126
bool EnableOpenMP = false; ///< Enable OpenMP lowering.
127127
};
128128

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,12 +1362,6 @@ bool CompilerInvocation::createFromArgs(
13621362
invoc.loweringOpts.setNoPPCNativeVecElemOrder(true);
13631363
}
13641364

1365-
// -flang-experimental-integer-overflow
1366-
if (args.hasArg(
1367-
clang::driver::options::OPT_flang_experimental_integer_overflow)) {
1368-
invoc.loweringOpts.setNSWOnLoopVarInc(true);
1369-
}
1370-
13711365
// Preserve all the remark options requested, i.e. -Rpass, -Rpass-missed or
13721366
// -Rpass-analysis. This will be used later when processing and outputting the
13731367
// remarks generated by LLVM in ExecuteCompilerInvocation.cpp.

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,8 @@ void CodeGenAction::generateLLVMIR() {
836836
Fortran::common::LanguageFeature::OpenMP))
837837
config.EnableOpenMP = true;
838838

839-
if (ci.getInvocation().getLoweringOpts().getNSWOnLoopVarInc())
840-
config.NSWOnLoopVarInc = true;
839+
if (ci.getInvocation().getLoweringOpts().getIntegerWrapAround())
840+
config.NSWOnLoopVarInc = false;
841841

842842
// Create the pass pipeline
843843
fir::createMLIRToLLVMPassPipeline(pm, config, getCurrentFile());

flang/lib/Lower/Bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
23302330
assert(!incrementLoopNestInfo.empty() && "empty loop nest");
23312331
mlir::Location loc = toLocation();
23322332
mlir::arith::IntegerOverflowFlags flags{};
2333-
if (getLoweringOptions().getNSWOnLoopVarInc())
2333+
if (!getLoweringOptions().getIntegerWrapAround())
23342334
flags = bitEnumSet(flags, mlir::arith::IntegerOverflowFlags::nsw);
23352335
auto iofAttr = mlir::arith::IntegerOverflowFlagsAttr::get(
23362336
builder->getContext(), flags);

flang/lib/Lower/IO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ static void genIoLoop(Fortran::lower::AbstractConverter &converter,
929929
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
930930
mlir::Location loc = converter.getCurrentLocation();
931931
mlir::arith::IntegerOverflowFlags flags{};
932-
if (converter.getLoweringOptions().getNSWOnLoopVarInc())
932+
if (!converter.getLoweringOptions().getIntegerWrapAround())
933933
flags = bitEnumSet(flags, mlir::arith::IntegerOverflowFlags::nsw);
934934
auto iofAttr =
935935
mlir::arith::IntegerOverflowFlagsAttr::get(builder.getContext(), flags);

0 commit comments

Comments
 (0)