-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Introduce -fexperimental-loop-fuse to clang and flang #142686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
be9eb6a
ea7ccc2
d1a5ac3
ae25025
7a9780f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1671,6 +1671,11 @@ void CompilerInvocationBase::GenerateCodeGenArgs(const CodeGenOptions &Opts, | |
else | ||
GenerateArg(Consumer, OPT_fno_loop_interchange); | ||
|
||
if (Opts.FuseLoops) | ||
GenerateArg(Consumer, OPT_fexperimental_loop_fusion); | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If OPT_fno_experimental_loop_fusion is not a cc1 option, the else branch will not be needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for letting me know! |
||
GenerateArg(Consumer, OPT_fno_experimental_loop_fusion); | ||
|
||
if (!Opts.BinutilsVersion.empty()) | ||
GenerateArg(Consumer, OPT_fbinutils_version_EQ, Opts.BinutilsVersion); | ||
|
||
|
@@ -1991,6 +1996,8 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, | |
(Opts.OptimizationLevel > 1)); | ||
Opts.InterchangeLoops = | ||
Args.hasFlag(OPT_floop_interchange, OPT_fno_loop_interchange, false); | ||
Opts.FuseLoops = Args.hasFlag(OPT_fexperimental_loop_fusion, | ||
OPT_fno_experimental_loop_fusion, false); | ||
Opts.BinutilsVersion = | ||
std::string(Args.getLastArgValue(OPT_fbinutils_version_EQ)); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
! RUN: %flang -### -S -fexperimental-loop-fusion %s 2>&1 | FileCheck -check-prefix=CHECK-LOOP-FUSE %s | ||
! RUN: %flang -### -S -fno-experimental-loop-fusion %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-FUSE %s | ||
! RUN: %flang -### -S -O0 %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-FUSE %s | ||
! RUN: %flang -### -S -O1 %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-FUSE %s | ||
! RUN: %flang -### -S -O2 %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-FUSE %s | ||
! RUN: %flang -### -S -O3 %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-FUSE %s | ||
! RUN: %flang -### -S -Os %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-FUSE %s | ||
! RUN: %flang -### -S -Oz %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-FUSE %s | ||
! CHECK-LOOP-FUSE: "-fexperimental-loop-fusion" | ||
! CHECK-NO-LOOP-FUSE-NOT: "-fexperimental-loop-fusion" | ||
! RUN: %flang_fc1 -emit-llvm -O2 -fexperimental-loop-fusion -mllvm -print-pipeline-passes -o /dev/null %s 2>&1 | FileCheck -check-prefix=CHECK-LOOP-FUSE-PASS %s | ||
! RUN: %flang_fc1 -emit-llvm -O2 -fno-experimental-loop-fusion -mllvm -print-pipeline-passes -o /dev/null %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-FUSE-PASS %s | ||
! CHECK-LOOP-FUSE-PASS: loop-fusion | ||
! CHECK-NO-LOOP-FUSE-PASS-NOT: loop-fusion | ||
|
||
program test | ||
end program |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,7 @@ | |
#include "llvm/Transforms/Scalar/LoopDeletion.h" | ||
#include "llvm/Transforms/Scalar/LoopDistribute.h" | ||
#include "llvm/Transforms/Scalar/LoopFlatten.h" | ||
#include "llvm/Transforms/Scalar/LoopFuse.h" | ||
#include "llvm/Transforms/Scalar/LoopIdiomRecognize.h" | ||
#include "llvm/Transforms/Scalar/LoopInstSimplify.h" | ||
#include "llvm/Transforms/Scalar/LoopInterchange.h" | ||
|
@@ -204,6 +205,10 @@ static cl::opt<bool> | |
EnableLoopInterchange("enable-loopinterchange", cl::init(false), cl::Hidden, | ||
cl::desc("Enable the LoopInterchange Pass")); | ||
|
||
static cl::opt<bool> EnableLoopFusion("enable-loopfusion", cl::init(false), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't quite understand why you want to add both a clang flag and an opt flag. But if that's the intention, On the other hand, options defined in But again, I'm not sure why clang/flang flags are really needed. Why isn't the opt flag sufficient? IMHO, at the very least, you should clarify the reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I said, I am taking over this patch from Sebastian. Your comment makes me think. The primary purpose of this patch is to user-facing option to allow turning fusion on or off. Not everyone is aware of the options provided by developer tools like opt. I see the precedence in the code. In
Having I can remove the change from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I didn't really understand what you meant... There is a clang option
I didn't mean it is redundant. It might be useful if we want to turn on/off the loop-fusion via opt command. What I meant is, if you also want to add both clang/flang and opt options, then you should move EnableFusion into proper place (maybe it is At the moment, I don’t have any strong objections to adding experimental flags to clang, although I'm not sure if there's an existing policy on clang side for such cases. |
||
cl::Hidden, | ||
cl::desc("Enable the LoopFuse Pass")); | ||
|
||
static cl::opt<bool> EnableUnrollAndJam("enable-unroll-and-jam", | ||
cl::init(false), cl::Hidden, | ||
cl::desc("Enable Unroll And Jam Pass")); | ||
|
@@ -313,6 +318,7 @@ PipelineTuningOptions::PipelineTuningOptions() { | |
SLPVectorization = false; | ||
LoopUnrolling = true; | ||
LoopInterchange = EnableLoopInterchange; | ||
LoopFusion = EnableLoopFusion; | ||
ForgetAllSCEVInLoopUnroll = ForgetSCEVInLoopUnroll; | ||
LicmMssaOptCap = SetLicmMssaOptCap; | ||
LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap; | ||
|
@@ -1548,6 +1554,11 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level, | |
if (PTO.LoopInterchange) | ||
LPM.addPass(LoopInterchangePass()); | ||
|
||
// FIXME: This may not be the right place in the pipeline. | ||
// We need to have the data to support the right place. | ||
if (PTO.LoopFusion) | ||
OptimizePM.addPass(LoopFusePass()); | ||
|
||
OptimizePM.addPass(createFunctionToLoopPassAdaptor( | ||
std::move(LPM), /*UseMemorySSA=*/false, /*UseBlockFrequencyInfo=*/false)); | ||
|
||
|
@@ -2355,4 +2366,4 @@ AAManager PassBuilder::buildDefaultAAPipeline() { | |
bool PassBuilder::isInstrumentedPGOUse() const { | ||
return (PGOOpt && PGOOpt->Action == PGOOptions::IRUse) || | ||
!UseCtxProfile.empty(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use
OptInCC1FFlag
so that the negative form is not aclang -cc1
option.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done