[llvm-dev] How to best deal with undesirable Induction Variable Simplification?
Danila Malyutin via llvm-dev
llvm-dev at lists.llvm.org
Fri Aug 9 08:27:38 PDT 2019
I see. So LSR could theoretically counteract undesirable Ind Var transformations but it's not implemented at the moment?
I think I've managed to come up with a small reproducer that can also exhibit similar problem on x86, here it is: https://godbolt.org/z/_wxzut
As you can see, when rewriteLoopExitValues is not disabled Clang generates worse code due to additional spills, because Ind Vars rewrites all exit values of 'a' to recompute it's value instead of reusing the value from the loop body. This requires extra registers for the new "a after the loop" value (since it's not simply reused) and also to store the new "offset", which leads to the extra spills since they all live across big loop body. When exit values are not rewritten 'a' stays in it's `r15d` register with no extra costs.
From: Finkel, Hal J. [mailto:hfinkel at anl.gov]
Sent: Thursday, August 8, 2019 21:24
To: Danila Malyutin <Danila.Malyutin at synopsys.com>
Subject: Re: [llvm-dev] How to best deal with undesirable Induction Variable Simplification?
Regarding the first case, this is certainly a problem that has come up before. As I recall, and I believe this is still true, LoopStrengthReduce, where we reason about induction variables while accounting for register pressure, won't currently add new PHIs. People have talked about extending LSR to consider adding new PHIs in the past.
Regarding the second case, could you post a more-detailed description? I don't quite understand the issue.
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory
From: llvm-dev <llvm-dev-bounces at lists.llvm.org<mailto:llvm-dev-bounces at lists.llvm.org>> on behalf of Danila Malyutin via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>>
Sent: Thursday, August 8, 2019 12:36 PM
To: llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org> <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>>
Subject: [llvm-dev] How to best deal with undesirable Induction Variable Simplification?
Recently I've come across two instances where Induction Variable Simplification lead to noticable performance regressions.
In one case, the removal of extra IV lead to the inability to reschedule instructions in a tight loop to reduce stalls. In that case, there were enough registers to spare, so using extra register for extra induction variable was preferable since it reduced dependencies in the loop.
In the second case, there was a big nested loop made even bigger after unswitching. However, the inner loop body was rather simple, of the form:
Due to unswitching there were several such loops each with the different number of p+=n ops, so when the IndVars pass rewrote all exit values, it added a lot of slightly different offsets to the main loop header that couldn't fit in the available registers which lead to unnecessary spills/reloads.
I am wondering what is the usual strategy for dealing with such "pessimizations"? Is it possible to somehow modify the IndVarSimplify pass to take those issues into account (for example, tell it that adding offset computation + gep is potentially more expensive than simply reusing last var from the loop) or should it be recovered in some later pass? If so, is there an easy way to revert IV elimination? Have anyone dealt with similar issues before?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev