Commit Graph

1914 Commits

Author SHA1 Message Date
Reid Spencer
789082af03 * Add two strlen optimizations:
strlen(x) != 0 -> *x != 0
    strlen(x) == 0 -> *x == 0
* Change nested statistics to use style of other LLVM statistics so that
  only the name of the optimization (simplify-libcalls) is used as the
  statistic name, and the description indicates which specific all is
  optimized. Cuts down on some redundancy and saves a few bytes of space.
* Make note of stpcpy optimization that could be done.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21766 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-07 20:15:59 +00:00
Reid Spencer
673c1a9170 Don't increment the counter unless the debug flag is set.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21762 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-07 04:59:45 +00:00
Chris Lattner
0975ed5f4e Convert shifts to muls to assist reassociation. This implements
Reassociate/shifttest.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21761 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-07 04:24:13 +00:00
Chris Lattner
08b43921e1 Simplify the code and rearrange it. No major functionality changes here.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21759 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-07 04:08:02 +00:00
Chris Lattner
3799ed83b4 BAD typeo which caused many testsuite failures last night. Note to self, do
not change code after testing it without retesting!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21741 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 17:13:16 +00:00
Chris Lattner
a9e9211bbb Preserve tail marker
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21737 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 06:48:21 +00:00
Chris Lattner
1b49141821 Implement Transforms/Inline/inline-tail.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21736 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 06:47:52 +00:00
Chris Lattner
1430ef134d preserve the tail marker
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21734 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 06:46:58 +00:00
Chris Lattner
19bdc03adc Wrap long lines
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21720 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 05:34:40 +00:00
Chris Lattner
ec710c5b12 DCE intrinsic instructions without side effects.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21719 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 05:27:34 +00:00
Chris Lattner
eabfa4787a Teach instcombine propagate zeroness through shl instructions, implementing
and.ll:test31


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21717 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 04:53:20 +00:00
Chris Lattner
d7115b01a0 Implement shift.ll:test23. If we are shifting right then immediately truncating
the result, turn signed shift rights into unsigned shift rights if possible.

This leads to later simplification and happens *often* in 176.gcc.  For example,
this testcase:

struct xxx { unsigned int code : 8; };
enum codes { A, B, C, D, E, F };
int foo(struct xxx *P) {
  if ((enum codes)P->code == A)
     bar();
}

used to be compiled to:

int %foo(%struct.xxx* %P) {
        %tmp.1 = getelementptr %struct.xxx* %P, int 0, uint 0           ; <uint*> [#uses=1]
        %tmp.2 = load uint* %tmp.1              ; <uint> [#uses=1]
        %tmp.3 = cast uint %tmp.2 to int                ; <int> [#uses=1]
        %tmp.4 = shl int %tmp.3, ubyte 24               ; <int> [#uses=1]
        %tmp.5 = shr int %tmp.4, ubyte 24               ; <int> [#uses=1]
        %tmp.6 = cast int %tmp.5 to sbyte               ; <sbyte> [#uses=1]
        %tmp.8 = seteq sbyte %tmp.6, 0          ; <bool> [#uses=1]
        br bool %tmp.8, label %then, label %UnifiedReturnBlock

Now it is compiled to:

        %tmp.1 = getelementptr %struct.xxx* %P, int 0, uint 0           ; <uint*> [#uses=1]
        %tmp.2 = load uint* %tmp.1              ; <uint> [#uses=1]
        %tmp.2 = cast uint %tmp.2 to sbyte              ; <sbyte> [#uses=1]
        %tmp.8 = seteq sbyte %tmp.2, 0          ; <bool> [#uses=1]
        br bool %tmp.8, label %then, label %UnifiedReturnBlock

which is the difference between this:

foo:
        subl $4, %esp
        movl 8(%esp), %eax
        movl (%eax), %eax
        shll $24, %eax
        sarl $24, %eax
        testb %al, %al
        jne .LBBfoo_2

and this:

foo:
        subl $4, %esp
        movl 8(%esp), %eax
        movl (%eax), %eax
        testb %al, %al
        jne .LBBfoo_2

This occurs 3243 times total in the External tests, 215x in povray,
6x in each f2c'd program, 1451x in 176.gcc, 7x in crafty, 20x in perl,
25x in gap, 3x in m88ksim, 25x in ijpeg.

Maybe this will cause a little jump on gcc tommorow :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21715 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 04:18:52 +00:00
Chris Lattner
7aed7ac5e1 Implement xor.ll:test22
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21713 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 02:07:39 +00:00
Chris Lattner
d152380ba8 implement and.ll:test30 and set.ll:test21
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21712 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 01:53:19 +00:00
Chris Lattner
828eeddb38 implement or.ll:test20
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21709 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 00:58:50 +00:00
Chris Lattner
3987abdfe3 Fix a bug compimling Ruby, fixing this testcase:
LowerSetJmp/2005-05-05-OldUses.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21696 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-05 15:47:43 +00:00
Chris Lattner
693787a5ec Instcombine: cast (X != 0) to int, cast (X == 1) to int -> X iff X has only the low bit set.
This implements set.ll:test20.

This triggers 2x on povray, 9x on mesa, 11x on gcc, 2x on crafty, 1x on eon,
6x on perlbmk and 11x on m88ksim.

It allows us to compile these two functions into the same code:

struct s { unsigned int bit : 1; };
unsigned foo(struct s *p) {
  if (p->bit)
    return 1;
  else
    return 0;
}
unsigned bar(struct s *p) { return p->bit; }


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21690 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-04 19:10:26 +00:00
Reid Spencer
cea6559f60 Implement the IsDigitOptimization for simplifying calls to the isdigit
library function:
  isdigit(chr) -> 0 or 1 if chr is constant
  isdigit(chr) -> chr - '0' <= 9 otherwise

Although there are many calls to isdigit in llvm-test, most of them are
compiled away by macros leaving only this:

2 MultiSource/Applications/hexxagon


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21688 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-04 18:58:28 +00:00
Reid Spencer
58b563ce43 * Correct the function prototypes for some of the functions to match the
actual spec (int -> uint)
* Add the ability to get/cache the strlen function prototype.
* Make sure generated values are appropriately named for debugging purposes
* Add the SPrintFOptimiation for 4 casts of sprintf optimization:
    sprintf(str,cstr) -> llvm.memcpy(str,cstr) (if cstr has no %)
    sprintf(str,"")   -> store sbyte 0, str
    sprintf(str,"%s",src) -> llvm.memcpy(str,src) (if src is constant)
    sprintf(str,"%c",chr) -> store chr, str   ; store sbyte 0, str+1

The sprintf optimization didn't fire as much as I had hoped:

  2 MultiSource/Applications/SPASS
  5 MultiSource/Benchmarks/McCat/18-imp
 22 MultiSource/Benchmarks/Prolangs-C/TimberWolfMC
  1 MultiSource/Benchmarks/Prolangs-C/assembler
  6 MultiSource/Benchmarks/Prolangs-C/unix-smail
  2 MultiSource/Benchmarks/mediabench/mpeg2/mpeg2dec


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21679 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-04 03:20:21 +00:00
Reid Spencer
21506ff821 Implement optimizations for the strchr and llvm.memset library calls.
Neither of these activated as many times as was hoped:

strchr:
9 MultiSource/Applications/siod
1 MultiSource/Applications/d
2 MultiSource/Prolangs-C/archie-client
1 External/SPEC/CINT2000/176.gcc/176.gcc

llvm.memset:
no hits


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21669 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-03 07:23:44 +00:00
Reid Spencer
9974ddab2b Avoid garbage output in the statistics display by ensuring that the
strings passed to Statistic's constructor are not destructable. The stats
are printed during static destruction and the SimplifyLibCalls module was
getting destructed before the statistics.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21661 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-03 02:54:54 +00:00
Reid Spencer
e6ec8cc8c6 Add the StrNCmpOptimization which is similar to strcmp.
Unfortunately, this optimization didn't trigger on any llvm-test tests.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21660 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-03 01:43:45 +00:00
Reid Spencer
a1b4390938 Implement the fprintf optimization which converts calls like this:
fprintf(F,"hello") -> fwrite("hello",strlen("hello"),1,F)
  fprintf(F,"%s","hello") -> fwrite("hello",strlen("hello"),1,F)
  fprintf(F,"%c",'x') -> fputc('c',F)

This optimization fires severals times in llvm-test:

313 MultiSource/Applications/Burg
302 MultiSource/Benchmarks/Prolangs-C/TimberWolfMC
189 MultiSource/Benchmarks/Prolangs-C/mybison
175 MultiSource/Benchmarks/Prolangs-C/football
130 MultiSource/Benchmarks/Prolangs-C/unix-tbl


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21657 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-02 23:59:26 +00:00
John Criswell
fe3706a12b Fixed a comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21653 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-02 14:47:42 +00:00
Chris Lattner
9fb25db11e Implement getelementptr.ll:test11
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21647 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-01 04:42:15 +00:00
Chris Lattner
37366c1ba8 Check for volatile loads only once.
Implement load.ll:test7


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21645 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-01 04:24:53 +00:00
Reid Spencer
63a7513ac1 Fix a comment that stated the wrong thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21638 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-30 06:45:47 +00:00
Reid Spencer
9f56b1feeb * Don't depend on "guessing" what a FILE* is, just require that the actual
type be obtained from a CallInst we're optimizing.
* Make it possible for getConstantStringLength to return the ConstantArray
  that it extracts in case the content is needed by an Optimization.
* Implement the strcmp optimization
* Implement the toascii optimization

This pass is now firing several to many times in the following MultiSource
tests:

Applications/Burg      -   7 (strcat,strcpy)
Applications/siod      -  13 (strcat,strcpy,strlen)
Applications/spiff     - 120 (exit,fputs,strcat,strcpy,strlen)
Applications/treecc    -  66 (exit,fputs,strcat,strcpy)
Applications/kimwitu++ -  34 (strcmp,strcpy,strlen)
Applications/SPASS     - 588 (exit,fputs,strcat,strcpy,strlen)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21626 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-30 03:17:54 +00:00
Reid Spencer
ff5525daf3 Implement the optimizations for "pow" and "fputs" library calls.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21618 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-29 09:39:47 +00:00
Reid Spencer
df4945bcb5 Remove optimizations that don't require both operands to be constant. These
are moved to simplify-libcalls pass.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21614 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-29 05:55:35 +00:00
Jeff Cohen
5882b92360 Consistently use 'class' to silence VC++
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21612 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-29 03:05:44 +00:00
Reid Spencer
1d3b71846b * Add constant folding for additional floating point library calls such as
sinh, cosh, etc.
* Make the name comparisons for the fp libcalls a little more efficient by
  switching on the first character of the name before doing comparisons.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21611 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-28 23:01:59 +00:00
Reid Spencer
5624c75f9f Remove from the TODO list those optimizations that are already handled by
constant folding implemented in lib/Transforms/Utils/Local.cpp.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21604 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-28 18:05:16 +00:00
Reid Spencer
8441a01146 Document additional libcall transformations that need to be written.
Help Wanted!

There's a lot of them to write.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21603 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-28 04:40:06 +00:00
Reid Spencer
716f49e5a2 Doxygenate.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21602 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 21:29:20 +00:00
Chris Lattner
209a0aea22 remove 'statement with no effect' warning
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21600 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 20:12:17 +00:00
Reid Spencer
3f7d8c65bb More Cleanup:
* Name the instructions by appending to name of original
* Factor common part out of a switch statement.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21597 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 17:46:54 +00:00
Reid Spencer
a16d5a5185 This is a cleanup commit:
* Correct stale documentation in a few places
* Re-order the file to better associate things and reduce line count
* Make the pass thread safe by caching the Function* objects needed by the
  optimizers in the pass object instead of globally.
* Provide the SimplifyLibCalls pass object to the optimizer classes so they
  can access cached Function* objects and TargetData info
* Make sure the pass resets its cache if the Module passed to runOnModule
  changes
* Rename CallOptimizer LibCallOptimization. All the classes are named
  *Optimization while the objects are *Optimizer.
* Don't cache Function* in the optimizer objects because they could be used
  by multiple PassManager's running in multiple threads
* Add an optimization for strcpy which is similar to strcat
* Add a "TODO" list at the end of the file for ideas on additional libcall
  optimizations that could be added (get ideas from other compilers).

Sorry for the huge diff. Its mostly reorganization of code. That won't
happen again as I believe the design and infrastructure for this pass is
now done or close to it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21589 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 07:54:40 +00:00
Chris Lattner
d651f441ae detect functions that never return, and turn the instruction following a
call to them into an 'unreachable' instruction.

This triggers a bunch of times, particularly on gcc:

gzip: 36
gcc: 601
eon: 12
bzip: 38


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21587 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 04:52:23 +00:00
Reid Spencer
026a87a868 Prefix the debug statistics so they group together.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21583 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 00:20:23 +00:00
Reid Spencer
1ea099c5fd In debug builds, make a statistic for each kind of call optimization. This
helps track down what gets triggered in the pass so its easier to identify
good test cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21582 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 00:05:45 +00:00
Chris Lattner
bc9fa589ef This analysis doesn't take 'throwing' into consideration, it looks at
'unwinding'


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21581 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 23:53:25 +00:00
Reid Spencer
0ddf0d6bec Fix up the debug statement to actually use a newline .. radical concept.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21580 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 23:07:08 +00:00
Reid Spencer
ef99ea318e Uh, this isn't argpromotion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21579 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 23:05:17 +00:00
Reid Spencer
8f13261863 Add some debugging output so we can tell which calls are getting triggered
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21578 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 23:02:16 +00:00
Reid Spencer
47a3785062 No, seriously folks, memcpy really does return void.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21575 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 22:49:48 +00:00
Reid Spencer
a525f6d8f5 memcpy returns void!!!!!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21574 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 22:46:23 +00:00
Reid Spencer
43fd4d077f Fix some bugs found by running on llvm-test:
* MemCpyOptimization can only be optimized if the 3rd and 4th arguments are
  constants and we weren't checking for that.
* The result of llvm.memcpy (and llvm.memmove) is void* not sbyte*, put in
  a cast.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21570 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 19:55:57 +00:00
Reid Spencer
fcbdb9c85b Changes From Review Feedback:
* Have the SimplifyLibCalls pass acquire the TargetData and pass it down to
  the optimization classes so they can use it to make better choices for
  the signatures of functions, etc.
* Rearrange the code a little so the utility functions are closer to their
  usage and keep the core of the pass near the top of the files.
* Adjust the StrLen pass to get/use the correct prototype depending on the
  TargetData::getIntPtrType() result. The result of strlen is size_t which
  could be either uint or ulong depending on the platform.
* Clean up some coding nits (cast vs. dyn_cast, remove redundant items from
  a switch, etc.)
* Implement the MemMoveOptimization as a twin of MemCpyOptimization (they
  only differ in name).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21569 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 19:13:17 +00:00
Chris Lattner
93b94a6ccf Fix the compile failures from last night.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21565 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 14:40:41 +00:00