<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.3.2">
</HEAD>
<BODY>
I've been working on some basic library call optimizations, the SimplifyLibCalls pass (lib/Transforms/IPO/SimplifyLibCalls.cpp). Tonight I conjured up a list of the potential libcall simplifications that could be done. There's a lot of them. I could use some help if anyone wants to pitch in.  The individual optimizations are self-contained and fairly straight forward to write. They range from easy to tough.  Anyone wanting to get their feet wet in LLVM optimization passes might find this an interesting place to start.  Anyway, is a list of what needs be done:  Please let me know if (a) you're going to write one of these transforms (so we don't duplicate efforts), (b) you don't understand one of them or (c) you find a bug in one of them. <BR>
<BR>
Thanks,<BR>
<BR>
Reid<BR>
<BR>
 abs:<BR>
   * abs(cnst) -> cnst'<BR>
<BR>
 atan:<BR>
   * atan(0.0) -> 0.0<BR>
   * atan(1.0) -> pi/4<BR>
<BR>
 cbrt:<BR>
   * cbrt(constant) -> constant'<BR>
   * cbrt(expN(X))  -> expN(x/3)<BR>
   * cbrt(sqrt(x))  -> pow(x,1/6)<BR>
   * cbrt(sqrt(x))  -> pow(x,1/9)<BR>
<BR>
 ceil, ceilf, ceill:<BR>
   * ceil(constant) -> constant'<BR>
<BR>
 cos, cosf, cosl:<BR>
   * cos(0.0) -> 1.0<BR>
   * cox(-x)  -> cos(x)<BR>
<BR>
 exp, expf, expl:<BR>
   * exp(0.0)     -> 1.0<BR>
   * exp(int)     -> contant'<BR>
   * exp(log(x))  -> x<BR>
<BR>
 fabs, fabsf, fabsl:<BR>
   * fabs(cnst)    -> cnst'<BR>
<BR>
 ffs, ffsl, ffsll:<BR>
   * ffs(cnst)     -> cnst'<BR>
<BR>
 floor, floorf, floorl:<BR>
   * floor(cnst) -> cnst'<BR>
<BR>
 fprintf:<BR>
   * fprintf(file,fmt) -> fputs(fmt,file) <BR>
       (if fmt is constant and constains no % characters)<BR>
   * fprintf(file,"%s",str) -> fputs(orig,str)<BR>
       (only if the fprintf result is not used)<BR>
   * fprintf(file,"%c",chr) -> fputc(chr,file)<BR>
<BR>
 fputs: (only if the result is not used)<BR>
   * fputs("",F) -> noop<BR>
   * fputs(s,F)  -> fputc(s[0],F)        (if s is constant and strlen(s) == 1)<BR>
   * fputs(s,F)  -> fwrite(s, 1, len, F) (if s is constant and strlen(s) > 1)<BR>
<BR>
 isascii:<BR>
   * isascii(c)    -> ((c & ~0x7f) == 0)<BR>
   <BR>
 isdigit:<BR>
   * isdigit(c)    -> (unsigned)(c) - '0' <= 9<BR>
<BR>
 log, logf, logl:<BR>
   * log(1.0)      -> 0.0<BR>
   * log(exp(x))   -> x<BR>
   * log(x**y)     -> y*log(x)<BR>
   * log(exp(y))   -> y*log(e)<BR>
   * log(exp2(y))  -> y*log(2)<BR>
   * log(exp10(y)) -> y*log(10)<BR>
   * log(sqrt(x))  -> 0.5*log(x)<BR>
   * log(pow(x,y)) -> y*log(x)<BR>
<BR>
 lround, lroundf, lroundl:<BR>
   * lround(cnst) -> cnst'<BR>
<BR>
 memcmp:<BR>
   * memcmp(s1,s2,0) -> 0<BR>
   * memcmp(x,x,l)   -> 0<BR>
   * memcmp(x,y,l)   -> cnst<BR>
      (if all arguments are constant and strlen(x) <= l and strlen(y) <= l)<BR>
   * memcpy(x,y,1)   -> *x - *y<BR>
<BR>
 memcpy:<BR>
   * memcpy(d,s,0,a) -> d<BR>
<BR>
 memmove:<BR>
   * memmove(d,s,l,a) -> memcpy(d,s,l,a) <BR>
       (if s is a global constant array)<BR>
<BR>
 memset:<BR>
   * memset(s,c,0) -> noop<BR>
   * memset(s,c,n) -> store s, c<BR>
      (for n=1,2,4,8)<BR>
<BR>
 pow, powf, powl:<BR>
   * pow(1.0,y)     -> 1.0<BR>
   * pow(x,0.0)     -> 1.0<BR>
   * pow(x,1.0)     -> x<BR>
   * pow(x,-1.0)    -> 1.0/x<BR>
   * pow(x,0.5)     -> sqrt(x)<BR>
   * pow(cst1,cst2) -> const1**const2<BR>
   * pow(exp(x),y)  -> exp(x*y)<BR>
   * pow(sqrt(x),y) -> pow(x,y*0.5)<BR>
   * pow(pow(x,y),z)-> pow(x,y*z)<BR>
<BR>
 puts:<BR>
   * puts("") -> fputc("\n",stdout) (how do we get "stdout"?)<BR>
<BR>
 round, roundf, roundl:<BR>
   * round(cnst) -> cnst'<BR>
<BR>
 signbit:<BR>
   * signbit(cnst) -> cnst'<BR>
   * signbit(nncst) -> 0 (if pstv is a non-negative constant)<BR>
<BR>
 sin, sinf, sinl:<BR>
   * sin(0.0) -> 0.0<BR>
<BR>
 sprintf:<BR>
   * sprintf(dest,fmt) -> strcpy(dest,fmt) <BR>
       (if fmt is constant and constains no % characters)<BR>
   * sprintf(dest,"%s",orig) -> strcpy(dest,orig)<BR>
       (only if the sprintf result is not used)<BR>
<BR>
 sqrt, sqrtf, sqrtl:<BR>
   * sqrt(cnst) -> cnst'<BR>
   * sqrt(expN(x))  -> expN(x*0.5)<BR>
   * sqrt(Nroot(x)) -> pow(x,1/(2*N))<BR>
   * sqrt(pow(x,y)) -> pow(|x|,y*0.5)<BR>
<BR>
 strchr, strrchr:<BR>
   * strchr(s,c)  -> offset_of_in(c,s)<BR>
      (if c is a constant integer and s is a constant string)<BR>
   * strrchr(s,c) -> reverse_offset_of_in(c,s)<BR>
      (if c is a constant integer and s is a constant string)<BR>
   * strrchr(s1,0) -> strchr(s1,0)<BR>
<BR>
 strcmp:<BR>
   * strcmp(x,x)  -> 0<BR>
   * strcmp(x,"") -> *x<BR>
   * strcmp("",x) -> *x<BR>
   * strcmp(x,y)  -> cnst  (if both x and y are constant strings)<BR>
<BR>
 strncat:<BR>
   * strncat(x,y,0) -> x<BR>
   * strncat(x,y,0) -> x (if strlen(y) = 0)<BR>
   * strncat(x,y,l) -> strcat(x,y) (if y and l are constants an l > strlen(y))<BR>
<BR>
 strncmp:<BR>
   * strncmp(x,y,0)   -> 0<BR>
   * strncmp(x,x,l)   -> 0<BR>
   * strncmp(x,"",l)  -> *x<BR>
   * strncmp("",x,l)  -> *x<BR>
   * strncmp(x,y,1)   -> *x - *y<BR>
<BR>
 strncpy:<BR>
   * strncpy(d,s,0) -> d<BR>
   * strncpy(d,s,l) -> memcpy(d,s,l,1)<BR>
      (if s and l are constants)<BR>
<BR>
 strpbrk:<BR>
   * strpbrk(s,a) -> offset_in_for(s,a)<BR>
      (if s and a are both constant strings)<BR>
   * strpbrk(s,"") -> 0<BR>
   * strpbrk(s,a) -> strchr(s,a[0]) (if a is constant string of length 1)<BR>
<BR>
 strspn, strcspn:<BR>
   * strspn(s,a)   -> const_int (if both args are constant)<BR>
   * strspn("",a)  -> 0<BR>
   * strspn(s,"")  -> 0<BR>
   * strcspn(s,a)  -> const_int (if both args are constant)<BR>
   * strcspn("",a) -> 0<BR>
   * strcspn(s,"") -> strlen(a)<BR>
<BR>
 strstr:<BR>
   * strstr(x,x)  -> x<BR>
   * strstr(s1,s2) -> offset_of_s2_in(s1)  <BR>
       (if s1 and s2 are constant strings)<BR>
    <BR>
 tan, tanf, tanl:<BR>
   * tan(0.0)     -> 0.0<BR>
   * tan(atan(x)) -> x<BR>
 <BR>
 toascii:<BR>
   * toascii(c)   -> (c & 0x7f)<BR>
<BR>
 trunc, truncf, truncl:<BR>
   * trunc(cnst) -> cnst'<BR>
<BR>
 
</BODY>
</HTML>