[llvm-dev] multiprecision add/sub

Stephen Canon via llvm-dev llvm-dev at lists.llvm.org
Wed Feb 15 14:28:47 PST 2017


On Feb 15, 2017, at 2:22 PM, Bagel via llvm-dev <llvm-dev at lists.llvm.org> wrote:

> I suggest that LLVM needs intrinsics for add/sub with carry, e.g.
> 
>  declare {T, i1} @llvm.addc.T(T %a, T %b, i1 c)
> 
> The current multiprecision clang intrinsics example:
>  void foo(unsigned *x, unsigned *y, unsigned *z)
>  { unsigned carryin = 0;
>    unsigned carryout;
>    z[0] = __builtin_addc(x[0], y[0], carryin, &carryout);
>    carryin = carryout;
>    z[1] = __builtin_addc(x[1], y[1], carryin, &carryout);
>    carryin = carryout;
>    z[2] = __builtin_addc(x[2], y[2], carryin, &carryout);
>    carryin = carryout;
>    z[3] = __builtin_addc(x[3], y[3], carryin, &carryout);
>  }
> uses the LLVM intrinsic "llvm.uadd.with.overflow" and generates
> horrible code that doesn't use the "adc" x86 instruction.
> 
> What is the current thinking on improving multiprecision arithmetic?

Why do you think this requires new intrinsics instead of teaching the optimizer what to do with the existing intrinsics?

– Steve


More information about the llvm-dev mailing list