Create an Add Instruction in LLVM IR

I want to create an add instruction that takes two constant operands at the LLVM IR level. I use the IRBuilder class, but nothing happens. Here is part of the runOnFunction() method of my function pass:


LLVMContext &Context = F.getContext();
IRBuilder<> builder(&Instruction);
Value *Lef = ConstantInt::get(Type::getInt32Ty(Context), 4);
Value *Rig = ConstantInt::get(Type::getInt32Ty(Context), 5);
Value *Result = builder.CreateAdd(Lef, Rig);

It seems that the problem is with the ConstantInt::get() function. Any idea?

By default IRBuilder uses ConstantFolder to fold your constant add instruction. In order to disable this, use IRBuilder<NoFolder>

Zhang

Thanks! It worked!