[LLVMdev] Checked arithmetic
Duncan Sands
baldrick at free.fr
Wed Mar 26 07:07:16 PDT 2008
Hi,
> There would appear to be three approaches:
>
> 1. Introduce a CC register class into the IR. This seems to be a
> fairly major overhaul.
>
> 2. Introduce a set of scalar and fp computation quasi-instructions
> that accept the same arguments as their computational counterparts,
> but produce *only* the condition code. For example:
>
> add i32 ... produces result
> add_cc i32 ... produces condition codes
>
> Once this exists, re-combine the instructions in the back end with
> peepholes.
>
> 3. Handle CC as a black magic special case, which at least has the
> merit of tradition. :-)
4. Do arithmetic in a type with one more bit. For example, suppose you
want to know if an i32 add "x+y" will overflow. Extend x and y to 33
bit integers, and do an i33 add. Inspect the upper bit to see if it
overflowed. Truncate to 32 bits to get the result. Probably codegen
can be taught to implement this as a 32 bit add + inspection of the CC.
Ciao,
Duncan.
PS: In order for codegen to be able to handle i33, you need to turn
on the new LegalizeTypes infrastructure.
More information about the llvm-dev
mailing list