Robert Sandra
2013-Feb-22 21:16 UTC
[LLVMdev] Does LLVM optimize variable to constant value in the compiling time?
Considering the following codes: int x = 21; if(x > 20) { p = &C; } else { p = &E; } I looked into the bitcode that LLVM generates, it still considers the 'else' branch, which will be never reached during the runtime. Thanks, Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130222/47e98f03/attachment.html>
Caldarale, Charles R
2013-Feb-22 21:25 UTC
[LLVMdev] Does LLVM optimize variable to constant value in the compiling time?
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > On Behalf Of Robert Sandra > Subject: [LLVMdev] Does LLVM optimize variable to constant value in the compiling time?> Considering the following codes:> int x = 21; > if(x > 20) { > p = &C; > } else { > p = &E; > }> I looked into the bitcode that LLVM generates, it still considers the 'else' > branch, which will be never reached during the runtime.What version of LLVM? What happens if you enable optimization? - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
Dmitri Gribenko
2013-Feb-22 21:26 UTC
[LLVMdev] Does LLVM optimize variable to constant value in the compiling time?
On Fri, Feb 22, 2013 at 11:16 PM, Robert Sandra <robert.sandra0712 at gmail.com> wrote:> Considering the following codes: > > int x = 21; > > if(x > 20) { > > p = &C; > > } else { > > p = &E; > > } > > > I looked into the bitcode that LLVM generates, it still considers the 'else' > branch, which will be never reached during the runtime.Did you turn on the optimization? Dmitri -- main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
Robert Sandra
2013-Feb-22 21:41 UTC
[LLVMdev] Does LLVM optimize variable to constant value in the compiling time?
By optimization, do you mean enable the optimization whiling building llvm or use optimization flag while using clang command to get the bitcode file? In my case, I disable the optimization when I built llvm, and I use the following command to get the bitcode: clang -O0 -emit-llvm hello.c -c -o hello.bc To run the pass: opt -load ../../../Debug+Asserts/lib/Hello.so -hello < hello.bc > /dev/null The llvm version I am using is 3.3svn. Thanks. On Fri, Feb 22, 2013 at 4:25 PM, Caldarale, Charles R < Chuck.Caldarale at unisys.com> wrote:> > From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > > On Behalf Of Robert Sandra > > Subject: [LLVMdev] Does LLVM optimize variable to constant value in the > compiling time? > > > Considering the following codes: > > > int x = 21; > > if(x > 20) { > > p = &C; > > } else { > > p = &E; > > } > > > I looked into the bitcode that LLVM generates, it still considers the > 'else' > > branch, which will be never reached during the runtime. > > What version of LLVM? What happens if you enable optimization? > > - Chuck > > > THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY > MATERIAL and is thus for use only by the intended recipient. If you > received this in error, please contact the sender and delete the e-mail and > its attachments from all computers. > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130222/ce91adf8/attachment.html>
Anton Korobeynikov
2013-Feb-22 21:46 UTC
[LLVMdev] Does LLVM optimize variable to constant value in the compiling time?
Hello> I looked into the bitcode that LLVM generates, it still considers the 'else' > branch, which will be never reached during the runtime.Have you forgotten about -O2 option? Here we go: $ cat test.c int C; int E; int* foo() { int*p; int x = 21; if(x > 20) { p = &C; } else { p = &E; } return p; } $ clang -S -O2 test.c -emit-llvm -o - ; ModuleID = 'test.c' target datalayout "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.7.0" @C = common global i32 0, align 4 @E = common global i32 0, align 4 define i32* @foo() nounwind uwtable readnone ssp { ret i32* @C } -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Possibly Parallel Threads
- [LLVMdev] Does LLVM optimize variable to constant value in the compiling time?
- [LLVMdev] Does LLVM optimize variable to constant value in the compiling time?
- [LLVMdev] One question about two passes interaction
- [LLVMdev] One question about two passes interaction
- Query: SELECT "INBOX" permission denied