James Courtier-Dutton
2013-Aug-18 17:14 UTC
[LLVMdev] Clarification regarding the LLVM IR.
Hi, Looking at the documents, it looks like all instructions, e.g. ADD, SUB work only on labels/registers and constants. e.g. %1 = add nsw i32 %value, 291 The only instructions that can work on the values on the stack or on the heap are LOAD and STORE. So the following is not possible: %local = alloca i32, align 4 %1 = add nsw i32* %local, 291 Is the above correct? Kind Regards James -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130818/f4622ed1/attachment.html>
Hi James,> The only instructions that can work on the values on the stack or on the > heap are LOAD and STORE.That's more or less true. If your variable is in memory then you have to load it before doing operations and store it back afterwards. There are one or two other instructions that can perform loads and stores though (atomicrmw, certain intrinsics, ...).> %local = alloca i32, align 4 > %1 = add nsw i32* %local, 291To add 291 to this local variable you'd write: %curVal = load i32* %local %newVal = add i32 %curVal, 291 store i32 %newVal, i32* %local Optimizations (one called mem2reg in the first instance) will normally get rid of the implied inefficiency in loading and storing everything. Tim.
Seemingly Similar Threads
- [LLVMdev] Proposal: "load linked" and "store conditional" atomic instructions
- [LLVMdev] Proposal: "load linked" and "store conditional" atomic instructions
- [LLVMdev] Floating point atomic load and add
- [LLVMdev] Keeping Clang from changing function calls to IR operations: cmpxchg
- RFC: Atomic LL/SC loops in LLVM revisited