[LLVMdev] How to add a trivial LLVM intrinsic

Matt Renzelmann mjr at cs.wisc.edu
Tue Jun 23 14:13:39 PDT 2009


As an experiment, I'm simply trying to add a trivial intrinsic to LLVM, but
I'm having trouble, which suggests that I'm overlooking the obvious ;)
Platform is GCC-4.2.4/LLVM from SVN/x86.

First, I've read the page here about 10 times, so I'll speculate that my
reading comprehension is lacking:

Code I've added to the bottom of the llvm/include/llvm/Intrinsics.td file:
def int_test_intrinsic :

Code I've added to visitBuiltinCall in
  case Intrinsic::test_intrinsic:
    return true;

I've not added any code to llvm/lib/Target/X86 because when I did, I
received a tablegen error.  I think I'm not understanding the difference
between an intrinsic that maps directly to a single machine instruction, and
a more complex intrinsic that invokes a C function.

In particular, I tried adding:
def int_test_and_clear_bit : X86Inst;

to the end of X86.td, but that resulted in a tablegen compilation error.

Code I've added to the end of LowerIntrinsicCall in
  case Intrinsic::test_intrinsic:

Note that the intent is to make this intrinsic a NOOP, just as an

But alas, the following trivial test program does not work:

#include <stdio.h>

int llvm_test_intrinsic(int) asm ("llvm.test.intrinsic");

int bar (int blah) {
    return llvm_test_intrinsic (blah);

int main() {
    int x = 3;
    bar (x);
    return 0;
After invoking:
llvm-gcc -g test.c -o test.native
The compiler returns:
cc1: Function.cpp:323: unsigned int llvm::Function::getIntrinsicID(bool)
const: Assertion `noAssert && "Invalid LLVM intrinsic name"' failed.
test.c:24: internal compiler error: Aborted
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://developer.apple.com/bugreporter> for instructions.

So, it's clear I'm missing something, or lots of things.  Any help would be
appreciated :)  I'm sure this is easy.

Thanks and regards,

More information about the llvm-dev mailing list