Skip to content

Commit ad86b77

Browse files
committed
[flang] enable loop-interchange at O3, O2, and Os
1 parent c6d051a commit ad86b77

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

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

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

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)