[LLVMdev] Spills and values present in both registers & stack

Taral taralx at gmail.com
Fri Jul 29 16:07:14 PDT 2011


On Thu, Jul 28, 2011 at 4:05 PM, David Blaikie <dblaikie at gmail.com> wrote:
> I'm not the most familiar with this sort of thing - but a small
> example (of llvm bitcode) & the optimization flags you used, etc,
> might be helpful (& I might be able to have a go at explaining it, if
> no one else does).

The actual C code is shorter. (You'll have to unwrap the lines.) Bonus
points if you can identify the algorithm. }:>

#include <stdint.h>
typedef unsigned int uint128_t __attribute__((mode(TI)));

typedef struct{
    uint64_t l[5];
} s;

void f(s * restrict r, const s * restrict x, const s * restrict y) {
    uint128_t t[5] = {0, 0, 0, 0, 0};
    #define BODY(i,j) { int i_ = i < j ? i : j; int j_ = i < j ? j :
i; uint128_t m = (uint128_t) x->l[i_] * (y->l[j_] * (i + j > 4 ? 19 :
1)); if (i + j > 4) { t[i + j - 5] += m; } else { t[i + j] += m; } }
    #define LOOP(i) BODY(i, 0); BODY(i, 1); BODY(i, 2); BODY(i, 3); BODY(i, 4);
    LOOP(0); LOOP(1); LOOP(2); LOOP(3); LOOP(4);
    #define FOLD1(i) r->l[i] = ((uint64_t) t[i] & (1LL << 51) - 1) +
(i == 0 ? 19 : 1) * (uint64_t)(t[(i + 4) % 5] >> 51)
    FOLD1(0); FOLD1(1); FOLD1(2); FOLD1(3); FOLD1(4);
    #define FOLD2(i) r->l[(i + 1) % 5] += (i == 4 ? 19 : 1) * (r->l[i]
>> 51); r->l[i] &= (1LL << 51) - 1;
    FOLD2(0); FOLD2(1); FOLD2(2); FOLD2(3); FOLD2(4);
}

% clang -O4 -S -o f.l f.c
% llc -O3 --pre-RA-sched=list-hybrid --regalloc=pbqp -o f.s f.l

-- 
Taral <taralx at gmail.com>
"Please let me know if there's any further trouble I can give you."
    -- Unknown




More information about the llvm-dev mailing list