[llvm-dev] Code generation option for wide integers on x86_64?

Riyaz Puthiyapurayil via llvm-dev llvm-dev at lists.llvm.org
Mon Aug 17 13:35:02 PDT 2020


I do not mind using dedicated libraries for wide integers (in fact, I mentioned that in my email below).

But the question is whether I should do that when lowering from the front-end representation to LLVM IR or at first use the LLVM IR integer representation, run machine independent transformation passes and then prior to running the code gen passes, convert the wide integers to an alternative representation and convert all operations on them to library calls?

If latter, how would I go about doing that? Create 'alloca' for the wide integers, bit cast and store them to stack and call the library functions? I don't know if there is a way to get rid of unnecessary alloca's. For example, if these wide integers are already in memory; it is a waste to load them from memory and copy them to stack; the address of the original location could be passed to the library.

Or lowering to library calls from the front-end representation, the better alternative?

/Riyaz

From: Eli Friedman <efriedma at quicinc.com>
Sent: Monday, August 17, 2020 12:08 PM
To: Riyaz Puthiyapurayil <riyaz at synopsys.com>; llvm-dev at lists.llvm.org
Subject: RE: [llvm-dev] Code generation option for wide integers on x86_64?

If you're dealing with integers that wide, I'd recommend avoiding the builtin IR integers.  There are dedicated libraries for wide integers; the most well-known is probably GMP.

-Eli

From: llvm-dev <llvm-dev-bounces at lists.llvm.org<mailto:llvm-dev-bounces at lists.llvm.org>> On Behalf Of Riyaz Puthiyapurayil via llvm-dev
Sent: Monday, August 17, 2020 11:54 AM
To: llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>>
Subject: [EXT] [llvm-dev] Code generation option for wide integers on x86_64?

Is there an existing option in X86_64 target code generator to emit a loop for the following code:

define i4096 @add(i4096 %a, i4096 %b) alwaysinline {
    %c = add i4096 %a, %b
    ret i4096 %c
}

instead of:

     movq %rdi, %rax
     addq 96(%rsp), %rsi
     adcq 104(%rsp), %rdx
     movq %rdx, 8(%rdi)
     movq %rsi, (%rdi)
     adcq 112(%rsp), %rcx
     movq %rcx, 16(%rdi)
     adcq 120(%rsp), %r8
     movq %r8, 24(%rdi)
     adcq 128(%rsp), %r9
     movq %r9, 32(%rdi)
     movq 8(%rsp), %rcx
     adcq 136(%rsp), %rcx
     movq %rcx, 40(%rdi)
     movq 16(%rsp), %rcx
           :
     :
     :

What is the best strategy for lowering wide integer types/operations on x86_64 without causing code blow up? Should we the code run through a custom pass that replaces wide operations with a library function call (or alternatively a loop) before code generation? Is there any existing code that can be reused?

Is there any documentation that describe strategies for lowering from languages that support arbitrarily wide integers?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200817/f6aeb1ae/attachment.html>


More information about the llvm-dev mailing list