Skip to content

Commit 9dc3774

Browse files
committed
[flang] enable loop-interchange at O3, O2, and Os
1 parent 46efee7 commit 9dc3774

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,3 +3149,16 @@ void tools::handleVectorizeSLPArgs(const ArgList &Args,
31493149
options::OPT_fno_slp_vectorize, EnableSLPVec))
31503150
CmdArgs.push_back("-vectorize-slp");
31513151
}
3152+
3153+
void tools::handleInterchangeLoopsArgs(const ArgList &Args,
3154+
ArgStringList &CmdArgs) {
3155+
// FIXME: instead of relying on shouldEnableVectorizerAtOLevel, we may want to
3156+
// implement a separate function to infer loop interchange from opt level.
3157+
// For now, enable loop-interchange at the same opt levels as loop-vectorize.
3158+
bool EnableInterchange = shouldEnableVectorizerAtOLevel(Args, false);
3159+
OptSpecifier InterchangeAliasOption =
3160+
EnableInterchange ? options::OPT_O_Group : options::OPT_floop_interchange;
3161+
if (Args.hasFlag(options::OPT_floop_interchange, InterchangeAliasOption,
3162+
options::OPT_fno_loop_interchange, EnableInterchange))
3163+
CmdArgs.push_back("-floop-interchange");
3164+
}

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ void renderCommonIntegerOverflowOptions(const llvm::opt::ArgList &Args,
259259
bool shouldEnableVectorizerAtOLevel(const llvm::opt::ArgList &Args,
260260
bool isSlpVec);
261261

262+
/// Enable -floop-interchange based on the optimization level selected.
263+
void handleInterchangeLoopsArgs(const llvm::opt::ArgList &Args,
264+
llvm::opt::ArgStringList &CmdArgs);
265+
262266
/// Enable -fvectorize based on the optimization level selected.
263267
void handleVectorizeLoopsArgs(const llvm::opt::ArgList &Args,
264268
llvm::opt::ArgStringList &CmdArgs);

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ void Flang::addCodegenOptions(const ArgList &Args,
152152
!stackArrays->getOption().matches(options::OPT_fno_stack_arrays))
153153
CmdArgs.push_back("-fstack-arrays");
154154

155-
Args.AddLastArg(CmdArgs, options::OPT_floop_interchange,
156-
options::OPT_fno_loop_interchange);
157-
155+
handleInterchangeLoopsArgs(Args, CmdArgs);
158156
handleVectorizeLoopsArgs(Args, CmdArgs);
159157
handleVectorizeSLPArgs(Args, CmdArgs);
160158

flang/docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ page](https://llvm.org/releases/).
3333
## New Compiler Flags
3434

3535
* -floop-interchange is now recognized by flang.
36+
* -floop-interchange is enabled by default at -O2 and above.
3637

3738
## Windows Support
3839

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
! RUN: %flang -### -S -floop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-LOOP-INTERCHANGE %s
22
! RUN: %flang -### -S -fno-loop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-INTERCHANGE %s
3+
! RUN: %flang -### -S -O0 %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-INTERCHANGE %s
4+
! RUN: %flang -### -S -O1 %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-INTERCHANGE %s
5+
! RUN: %flang -### -S -O2 %s 2>&1 | FileCheck -check-prefix=CHECK-LOOP-INTERCHANGE %s
6+
! RUN: %flang -### -S -O3 %s 2>&1 | FileCheck -check-prefix=CHECK-LOOP-INTERCHANGE %s
7+
! RUN: %flang -### -S -Os %s 2>&1 | FileCheck -check-prefix=CHECK-LOOP-INTERCHANGE %s
8+
! RUN: %flang -### -S -Oz %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-INTERCHANGE %s
39
! CHECK-LOOP-INTERCHANGE: "-floop-interchange"
4-
! CHECK-NO-LOOP-INTERCHANGE: "-fno-loop-interchange"
10+
! CHECK-NO-LOOP-INTERCHANGE-NOT: "-floop-interchange"
511

612
program test
713
end program

0 commit comments

Comments
 (0)