[LLVMdev] precondition suggestion to LLVM

Niko Zarzani koni10 at hotmail.it
Mon Oct 22 20:44:17 PDT 2012


I think that the __builtin_expect() can only to give hints for better performing branch predicitions.I was thinking about another kind of situation. Usually if I have a function like this (this is only a simple example):
int foo(int x, int y){
  if (x > 0 and y>0){      return x*y;  }  else {      return 0;  }
}

and the compiler knows that the precondition of the function are (x > 0 && y>0) then it can compile it by simply consider it:
int foo(int x, int y){
   return x*y;
}
I know it could be dangerous because maybe it will not handle unexpected behavior, but I was wondering if by using some directive like a:
#pragma assert( (x > 0 && y>0) )  /* I know it does not exist pragma assert */
maybe by knowing it the compiler may skip branches or optimize computations (for example if the precondition tell that x==0, and there is a sum or multiplication with x as an operand it can simplify them) in the function code.
Thank you for helping me,
Niko Zarzani
> Date: Tue, 23 Oct 2012 05:06:06 +0200
> Subject: Re: [LLVMdev] precondition suggestion to LLVM
> From: maemarcus at gmail.com
> To: koni10 at hotmail.it
> CC: llvmdev at cs.uiuc.edu
> 
> Hi Niko,
> 
> Do you mean branch prediction, i.e. __builtin_expect [1]? Many
> compilers support it, I think clang (LLVM's C/C++ frontend) is among
> them.
> 
> - D.
> 
> [1] http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
> 
> 2012/10/23 Niko Zarzani <koni10 at hotmail.it>:
> > Hi all,
> > Is there any way to tell LLVM some additional information about the
> > variables in the code in order to make better optimization?
> > For example, if my function has a certain precondition (such as x>0) then it
> > will be possible to better optimize the code given that information (which
> > the compiler does not know).
> > I am new in this field and I don't know if there are ways to tell the
> > compiler preconditions (such as by using some preprocessing directives).
> > Thank you in advance,
> > Niko Zarzani
> >
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> >
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121023/4eb3c238/attachment.html>


More information about the llvm-dev mailing list