-
Notifications
You must be signed in to change notification settings - Fork 12
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
Convert Loop Metadata to Asserts to help Loop rotation #227
base: aie-public
Are you sure you want to change the base?
Conversation
Only add assumption if the assumption at the first iteration can be guaranteed to be loop invariant. |
3909dd4
to
33c04f6
Compare
rebased to aie-public |
060a2a8
to
d244f5c
Compare
1e4b876
to
e8f1b47
Compare
Maybe you can fix the CI failure by running your test under x86? |
e8f1b47
to
f9835c9
Compare
I moved the pass between LICM and loop rotate, so that the loop invariance check is simplified and performed by LICM. This behavior is demonstrated by unittests. Additionally, the assumption is inserted into the Preheader, so that the loop header is not evaluated to true and converted into an endless loop. |
; NOTE: Example file for converting loop iter count to assumptions in the Loop | ||
; | ||
; RUN: opt -S -passes='loop-iter-count-assumptions' -verify-each < %s | FileCheck %s | ||
; RUN: opt -S -passes='loop-mssa(licm,loop-iter-count-assumptions)' -verify-each < %s | FileCheck %s --check-prefix=LICM |
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.
That's a really huge file now. I think the first RUN line isn't all that useful anymore, because your pass is now inserted after LICM in the pass pipeline. Testing it independently outside of its expected conditions doesn't show too much.
Maybe it would make sense to only keep:
opt -S -passes='loop-mssa(licm,loop-iter-count-assumptions)' -verify-each < %s | FileCheck %s --check-prefix=ASSUME
opt -S -passes='default<O2>' --enable-loop-iter-count-assumptions=1 -start-before='licm' -stop-after='loop-rotate' -verify-each -o - < %s | FileCheck %s --check-prefix=ROTATE
Nit: I would even only test loop-mssa(licm,loop-iter-count-assumptions)
in that file to keep it concise and easy to read. Then we can have a separate "integration test" which runs from licm
to loop-rotate
with one or two cases. But that's a personal preference at this point :)
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.
I wanted to have the end to end test, so that non-obvious errors get shown immediately, i.e. endless loops.
But sure, now that i am through the testing and know what the expected results are, I can remove it. The integration test is only interesting for edge cases, which would duplicates large parts of the unittest, which is the original reason I had them in the same file.
// return LHS | ||
Value *LHS = expandValueAtZeroIteration(LoopCmpInstr.getOperand(0), SE, | ||
Expander, &LoopCmpInstr); | ||
LHS = getLoopInvariant(LHS, DT, &CurrentLoop); |
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.
See my comment here https://github.com/Xilinx/llvm-aie/pull/227/files#r1869145688
I think it is a bit confusing that expandValueAtZeroIteration
potentially returns something that isn't the value at iteration 0. This LHS = getLoopInvariant(LHS, DT, &CurrentLoop);
should be inlined into expandValueAtZeroIteration
. If the latter cannot be sure that the returned value is exactly the one at iteration 0, it should return nullptr
.
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.
That is a more concise way of looking at expandValueAtZeroIteration
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.
I updated it accordingly.
f2d9afe
to
abe2846
Compare
clang/lib/Driver/ToolChains/AIE.cpp
Outdated
@@ -163,6 +163,9 @@ void AIEToolChain::addClangTargetOptions( | |||
|
|||
// Extend the max limit of the search depth in BasicAA | |||
CC1Args.append({"-mllvm", "-basic-aa-max-lookup-search-depth=10"}); | |||
|
|||
// enable Loop Iteration Count Assumptions |
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.
nit: Enable.
clang/lib/Driver/ToolChains/AIE.cpp
Outdated
@@ -163,6 +163,9 @@ void AIEToolChain::addClangTargetOptions( | |||
|
|||
// Extend the max limit of the search depth in BasicAA | |||
CC1Args.append({"-mllvm", "-basic-aa-max-lookup-search-depth=10"}); | |||
|
|||
// enable Loop Iteration Count Assumptions | |||
CC1Args.append({"-mllvm", "-enable-loop-iter-count-assumptions=1"}); |
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.
nit: it is better to use boolean because it is the correct type for the flag.
abe2846
to
0c6fa61
Compare
I also only lazily insert the Iteration 0 assumption so that the IR changes are minimal. QoR improves by 1.14% and program memory by 0.73%, when this pass is enabled vs with the builtin_assumes |
0c6fa61
to
6bf41ef
Compare
6bf41ef
to
d8d9dba
Compare
note the first commit will be removed once the ( #225 ) is merged
Please note: I am still going through QoR to make sure I am not introducing any functional errors.