Journeyer J. Joh
2013-Jan-03 05:08 UTC
[LLVMdev] Does getelementptr get optimized in compile-time?
Hello List, I've got a question about getelementptr. I've been told that getelementptr is evaluated in compile-time NOT in run-time. So I tested it with clang web compiler below. http://llvm.org/demo/index.cgi But with LTO nor Standard, neither one optimize getelementptr out. Does getelementptr get evaluated in compile-time? Or doesn't it get executed in run-time? (I believed so. Now I am wondering.) Thank you in advance. -- ---------------------------------------- Journeyer J. Joh o o s a p r o g r a m m e r a t g m a i l d o t c o m ----------------------------------------
Duncan Sands
2013-Jan-03 08:50 UTC
[LLVMdev] Does getelementptr get optimized in compile-time?
Hi Journeyer, > I've got a question about getelementptr.> > I've been told that getelementptr is evaluated in compile-time NOT in run-time.this is impossible if the arguments are not constants. If they are constant, then the optimizers will turn a getelementptr instruction into a getelementptr constant expression (http://llvm.org/docs/LangRef.html#constant-expressions). Even so it usually isn't evaluable at compile time, since typically the pointer operand is a global variable for which the address is only known when the program loader loads the final executable into memory. If however the operands are all numerical values (eg the pointer operand is "null" and the others are numbers like "1") then it will be turned into a number by the optimizers. Ciao, Duncan.> > So I tested it with clang web compiler below. > http://llvm.org/demo/index.cgi > > But with LTO nor Standard, neither one optimize getelementptr out. > > Does getelementptr get evaluated in compile-time? > Or doesn't it get executed in run-time? (I believed so. Now I am wondering.) > > Thank you in advance. >
Journeyer J. Joh
2013-Jan-03 09:12 UTC
[LLVMdev] Does getelementptr get optimized in compile-time?
Hello Duncan Sands,> If however the operands are all numerical values (eg the pointer operand is "null" and the others are numbers like "1") then it will be turned into a number by the optimizers.I think my case is stated above among your answer. http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt There is a brief document about using getelmentptr trick above. And I was wondering something similar to this case. %Size = getelementptr %T* null, int 1 %SizeI = cast %T* %Size to uint I understood that for this case, getelementptr will be collapsed to a number during optimization. It is also explained in the brief document above. I didn't understood by the document at that time. OK. Thank you very much. I understood very well. Sincerely Journeyer 2013/1/3 Duncan Sands <baldrick at free.fr>:> Hi Journeyer, > > >> I've got a question about getelementptr. >> >> >> I've been told that getelementptr is evaluated in compile-time NOT in >> run-time. > > > this is impossible if the arguments are not constants. If they are > constant, > then the optimizers will turn a getelementptr instruction into a > getelementptr > constant expression > (http://llvm.org/docs/LangRef.html#constant-expressions). > Even so it usually isn't evaluable at compile time, since typically the > pointer > operand is a global variable for which the address is only known when the > program loader loads the final executable into memory. If however the > operands > are all numerical values (eg the pointer operand is "null" and the others > are > numbers like "1") then it will be turned into a number by the optimizers. > > Ciao, Duncan. > > >> >> So I tested it with clang web compiler below. >> http://llvm.org/demo/index.cgi >> >> But with LTO nor Standard, neither one optimize getelementptr out. >> >> Does getelementptr get evaluated in compile-time? >> Or doesn't it get executed in run-time? (I believed so. Now I am >> wondering.) >> >> Thank you in advance. >> > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-- ---------------------------------------- Journeyer J. Joh o o s a p r o g r a m m e r a t g m a i l d o t c o m ----------------------------------------
Seemingly Similar Threads
- [LLVMdev] Does getelementptr get optimized in compile-time?
- [LLVMdev] Does getelementptr get optimized in compile-time?
- [LLVMdev] Need some brief explanation about llvm::MemoryBuffer and llvm::SourceMgr
- [LLVMdev] Need some brief explanation about llvm::MemoryBuffer and llvm::SourceMgr
- [LLVMdev] git repository of the tutorial