[llvm-dev] Automatically scaled offset Load/stores for arrays
Tim Northover via llvm-dev
llvm-dev at lists.llvm.org
Wed Jul 6 10:58:18 PDT 2016
On 6 July 2016 at 10:36, Dilan Manatunga via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> I have a question on how I would support load/store instructions where the
> offset is automatically scaled by the type. Simply put, any array index
> would be scaled by the width, so that there no longer needs to be a separate.
This is a reasonably common pattern. Typically earlier LLVM passes
(Loop Strength Reduction in particular) wrangle equivalent induction
variables and offsets into what's best for your machine (using
callbacks like TargetTransformInfo::getScalingFactorCost by the looks
In this case, I'd expect that after setting scale-4 to free and
scale-1 to expensive it will produce something like
%ptr = %arr_ptr + 4 * %i
%a = load i32 %ptr
%x = %x + %a
%i = %i + 1
At that point you have the much simpler task of looking for patterns
like "(load (add $base, (mul $offset, 4)))" during ISel. Quite a few
other targets do this (they usually find it's actually simpler to do
it in C++ using ComplexPatterns, see AArch64's "SelectAddrModeXRO"
functions for example).
Let me know if I've been unclear anywhere.
More information about the llvm-dev