[llvm-dev] Optimised stack direction?
Tim Northover via llvm-dev
llvm-dev at lists.llvm.org
Tue Jun 25 05:22:15 PDT 2019
Hi Samuel,
On Tue, 25 Jun 2019 at 12:39, Samuel Williams via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> Why does LLVM struggle to optimize the following stack direction check?
Probably because it's a niche operation. You can't rely on x and y
being laid out in any particular order even during multiple calls to
stack_direction within a single compilation, so there's really not
much you can do with such a comparison. That makes it a rare case.
On the LLVM side, the optimization isn't something that would happen
naturally through generic analyses so someone would have to sit down
specifically to write it into LLVM; and no-one has.
The only way I can think of to reliably detect the direction is using
an __attribute__((noinline)) function to compare locals from two
different, nested frames (even that's iffy though on a semantic
level). If there turned out to be a compelling enough use-case, an
intrinsic could be added to get the result more efficiently.
Cheers.
Tim.
More information about the llvm-dev
mailing list