[LLVMdev] Overflow trap

Peter S. Housel housel at acm.org
Mon Aug 9 10:44:31 PDT 2010

Several instruction set architectures include arithmetic operations that can
trap on overflow, or support this feature with a separate
trap-on-overflow-flag instruction (such as the x86 INTO instruction).

I am adding a back-end to the Open Dylan compiler to generate LLVM IR. The
original back-end, which generates x86 machine code, makes use of the INTO
instruction, and the runtime turns the resulting INT 4 into a language-level
exception. In order to support this not-uncommon requirement using LLVM, I
see three alternatives:

1. Add llvm.sadd.with.overflow.trap.*, . intrinsics corresponding to the
current llvm.sadd.with.overflow.*, . intrinsics to LLVM and the current code

2. Add a single llvm.trap.overflow intrinsic to LLVM and the current code
generators, and ensure that the code generators can generate the proper
arithmetic-with-overflow-trap or trap-on-overflow-flag instruction when it
is executed conditionally based on the output of one of the
llvm.sadd.with.overflow.* etc. intrinsics.

3. Don't try to solve this problem for LLVM in general but use inline
assembly for these few operations in my back-end.

Which alternative should I pursue? The third is obviously the easiest for
me, but other LLVM users would benefit from the other two.


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

More information about the llvm-dev mailing list