Commit Graph

18467 Commits

Author SHA1 Message Date
Duraid Madina
85d5f6067d clean up some warnings
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21590 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 11:57:39 +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
Chris Lattner
cd4b7a4454 Test the noreturn function optimization
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21586 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 04:51:01 +00:00
Reid Spencer
ff1c9e2147 Add the simplify-libcalls pass.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21585 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 02:22:47 +00:00
Andrew Lenharth
4430e3a4a8 A first step towards being able to do more interesting things with the nightly tester data. Moreinteresting things will come soon, so tune in
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21584 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-27 02:13:20 +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
Chris Lattner
c915108e1d no parens
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21577 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 22:57:07 +00:00
Chris Lattner
695b78b5f7 update some paths
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21576 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 22:56: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
a8d451e1d4 Convert the remainder of the intrinsic function prototypes to "declare"
form from the "call" form.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21573 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 20:50:44 +00:00
Reid Spencer
d462235968 Use the declare syntax not the call syntax for intrinsic prototypes so
the uninitiated reader is not confused.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21572 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 20:41:16 +00:00
Chris Lattner
3f80a38859 don't let Reid build void*'s :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21571 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 20:03:33 +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
Reid Spencer
7b7adcffa7 Add a test case for MemMove.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21568 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 19:05:51 +00:00
Reid Spencer
c662bc71df Result of strlen is size_t which is either uint or ulong, not int.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21567 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 19:04:46 +00:00
Chris Lattner
318c149823 Make interval partition print correctly, patch contributed by
Vladimir Prus!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21566 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 14:48:28 +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
Duraid Madina
4706c0395b constmul bugfix: multiply by 27611 was broken
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21564 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 09:42:50 +00:00
Duraid Madina
3b84bac3ef clean up the code! (oops) lots more cleaning left, however.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21563 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 08:43:47 +00:00
Reid Spencer
20754ac069 * Merge get_GVInitializer and getCharArrayLength into a single function
named getConstantStringLength. This is the common part of StrCpy and
  StrLen optimizations and probably several others, yet to be written. It
  performs all the validity checks for looking at constant arrays that are
  supposed to be null-terminated strings and then computes the actual
  length of the string.
* Implement the MemCpyOptimization class. This just turns memcpy of 1, 2, 4
  and 8 byte data blocks that are properly aligned on those boundaries into
  a load and a store. Much more could be done here but alignment
  restrictions and lack of knowledge of the target instruction set prevent
  use from doing significantly more. That will have to be delegated to the
  code generators as they lower llvm.memcpy calls.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21562 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 07:45:18 +00:00
Reid Spencer
4ac0f21f7a Add a new test case for the llvm.memcpy simplification case.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21561 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 07:40:40 +00:00
Duraid Madina
b2322561cb * Add code to reduce multiplies by constant integers to shifts, adds and
subtracts. This is a very rough and nasty implementation of Lefevre's
  "pattern finding" algorithm. With a few small changes though, it should
  end up beating most other methods in common use, regardless of the size
  of the constant (currently, it's often one or two shifts worse)

  TODO: rewrite it so it's not hideously ugly (this is a translation from
        perl, which doesn't help ;)
        bypass most of it for multiplies by 2^n+1
	(eventually) teach it that some combinations of shift+add are
	cheaper than others (e.g. shladd on ia64, scaled adds on alpha)
	get it to try multiple booth encodings in search of the cheapest
	routine
	make it work for negative constants

  This is hacked up as a DAG->DAG transform, so once I clean it up I hope
  it'll be pulled out of here and put somewhere else. The only thing backends
  should really have to worry about for now is where to draw the line
  between using this code vs. going ahead and doing an integer multiply
  anyway.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21560 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 07:23:02 +00:00
Reid Spencer
912401c3f6 * Implement StrLenOptimization
* Factor out commonalities between StrLenOptimization and StrCatOptimization
* Make sure that signatures return sbyte* not void*


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21559 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 05:24:00 +00:00
Reid Spencer
8fe86dde1c * Add a test case for StrLenOptimization
* Rename ExitInMain and StrCat tests so they don't have the date the
  regression was entered since they are feature tests, not regressions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21558 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 05:22:38 +00:00
Reid Spencer
43e0baece3 Incorporate feedback from Chris:
* Change signatures of OptimizeCall and ValidateCalledFunction so they are
  non-const, allowing the optimization object to be modified. This is in
  support of caching things used across multiple calls.
* Provide two functions for constructing and caching function types
* Modify the StrCatOptimization to cache Function objects for strlen and
  llvm.memcpy so it doesn't regenerate them on each call site. Make sure
  these are invalidated each time we start the pass.
* Handle both a GEP Instruction and a GEP ConstantExpr
* Add additional checks to make sure we really are dealing with an arary of
  sbyte and that all the element initializers are ConstantInt or
  ConstantExpr that reduce to ConstantInt.
* Make sure the GlobalVariable is constant!
* Don't use ConstantArray::getString as it can fail and it doesn't give us
  the right thing. We must check for null bytes in the middle of the array.
* Use llvm.memcpy instead of memcpy so we can factor alignment into it.
* Don't use void* types in signatures, replace with sbyte* instead.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21555 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 03:26:15 +00:00
Jeff Cohen
c8beae2b6d Add SimplyLibCalls.cpp to VC++ build
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21554 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 02:57:49 +00:00
Reid Spencer
c89c36323b Fix RUN: line to not always pass.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21553 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 02:33:25 +00:00
Chris Lattner
d36f979085 Fold (X > -1) | (Y > -1) --> (X&Y > -1)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21552 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 01:18:33 +00:00
Reid Spencer
855adb1ac4 Changes due to code review and new implementation:
* Don't use std::string for the function names, const char* will suffice
* Allow each CallOptimizer to validate the function signature before
  doing anything
* Repeatedly loop over the functions until an iteration produces
  no more optimizations. This allows one optimization to insert a
  call that is optimized by another optimization.
* Implement the ConstantArray portion of the StrCatOptimization
* Provide a template for the MemCpyOptimization
* Make ExitInMainOptimization split the block, not delete everything
  after the return instruction.
(This covers revision 1.3 and 1.4, as the 1.3 comments were botched)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21548 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 21:20:38 +00:00
Chris Lattner
229ab2e7b2 implement some more logical compares with constants, so that:
int foo1(int x, int y) {
  int t1 = x >= 0;
  int t2 = y >= 0;
  return t1 & t2;
}
int foo2(int x, int y) {
  int t1 = x == -1;
  int t2 = y == -1;
  return t1 & t2;
}

produces:

_foo1:
        or r2, r4, r3
        srwi r2, r2, 31
        xori r3, r2, 1
        blr
_foo2:
        and r2, r4, r3
        addic r2, r2, 1
        li r2, 0
        addze r3, r2
        blr

instead of:

_foo1:
        srwi r2, r4, 31
        xori r2, r2, 1
        srwi r3, r3, 31
        xori r3, r3, 1
        and r3, r2, r3
        blr
_foo2:
        addic r2, r4, 1
        li r2, 0
        addze r2, r2
        addic r3, r3, 1
        li r3, 0
        addze r3, r3
        and r3, r2, r3
        blr


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21547 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 21:20:28 +00:00
Reid Spencer
6cc0311c6d Lots of changes based on review and new functionality:
* Use a 


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21546 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 21:11:48 +00:00
Reid Spencer
8b9f9b3d60 Update the test case to handle a few more (degenerate) cases and remove
the restriction that it is an XFAIL because it now passes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21545 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 21:08:34 +00:00
Chris Lattner
6ea9279304 Codegen x < 0 | y < 0 as (x|y) < 0. This allows us to compile this to:
_foo:
        or r2, r4, r3
        srwi r3, r2, 31
        blr

instead of:

_foo:
        srwi r2, r4, 31
        srwi r3, r3, 31
        or r3, r2, r3
        blr


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21544 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 21:03:25 +00:00
Chris Lattner
91bd25d9df Make dominates(A,B) work with post dominators. Patch contributed by
Naveen Neelakantam, thanks!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21543 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 20:50:33 +00:00
Tanya Lattner
14fc5c1c05 Added question about turning off all optimizations. I think this has been asked once or twice.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21542 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 20:36:56 +00:00
Chris Lattner
a70b66d49e implement getelementptr.ll:test10
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21541 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 20:17:30 +00:00
Chris Lattner
e3194645fc rename fn
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21540 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 20:17:16 +00:00
Chris Lattner
27b8598c97 new testcase
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21539 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 20:17:00 +00:00
Chris Lattner
a1198b5254 Correctly handle global-argument aliases induced in main
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21537 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 19:16:31 +00:00
Chris Lattner
63320cc841 Don't mess up SCC traversal when a node has null edges out of it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21536 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 19:16:17 +00:00
Chris Lattner
69c11bb285 document 'opaque' types
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21535 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 17:34:15 +00:00
Chris Lattner
0f876db7d5 Add feedback from Vikram
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21534 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 15:47:57 +00:00