Commit Graph

1793 Commits

Author SHA1 Message Date
Peter Collingbourne
8a70192b51 SimplifyCFG: Add Trunc, ZExt and SExt to the list of cheap instructions for phi node folding
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130526 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-29 18:47:25 +00:00
Devang Patel
81ad03c020 Remove DbgDeclare only if all uses are converted.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130431 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 20:32:02 +00:00
Jay Foad
ddcdcc8863 Remove unused STL header includes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130068 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-23 19:53:52 +00:00
Jay Foad
ec9186bcf9 PR9214: Convert Metadata API to use ArrayRef.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129932 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-21 19:59:31 +00:00
Jay Foad
1a0390253b Trivial simplification.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129759 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-19 15:23:29 +00:00
Chris Lattner
7a2bdde0a0 Fix a ton of comment typos found by codespell. Patch by
Luis Felipe Strano Moraes!



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129558 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-15 05:18:47 +00:00
Chris Lattner
3c6e746b5f rework FoldBranchToCommonDest to exit earlier when there is a bonus
instruction around, reducing work.

Greatly simplify handling of debug instructions.  There is no need to
build up a vector of them and then move them into the one predecessor
if we're processing a block.  Instead just rescan the block and *copy*
them into the pred.  If a block gets merged into multiple preds, this
will retain more debug info.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129502 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-14 02:44:53 +00:00
Chris Lattner
c8fbc34869 comment cleanup, use moveBefore instead of removeFromParent+insertBefore.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129319 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-11 23:24:57 +00:00
Jay Foad
562b84b3ae Don't include Operator.h from InstrTypes.h.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129271 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-11 09:35:34 +00:00
Devang Patel
60d490cdc7 Do not let debug info interfer with branch folding.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129114 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-07 23:11:25 +00:00
Devang Patel
949666ea16 While hoisting common code from if/else, hoist debug info intrinsics if they match.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129078 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-07 17:27:36 +00:00
Devang Patel
ae6c95b58e Simplify. isIdenticalToWhenDefined() checks opcode.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129041 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-07 00:30:15 +00:00
Devang Patel
d418194036 While folding branch to a common destination into a predecessor, copy dbg values also.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129035 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-06 22:37:20 +00:00
Eli Friedman
eeb7f4ce2d Attempt to fix breakage from r128782 reported by Francois Pichet on
llvm-commits.  (Not sure why it only breaks on Windows; maybe it has
something to do with the iterator representation...)



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128802 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-04 00:37:38 +00:00
Eli Friedman
71ad2c9eda PR9446: RecursivelyDeleteTriviallyDeadInstructions can delete the instruction
after the given instruction; make sure to handle that case correctly.
(It's difficult to trigger; the included testcase involves a dead 
block, but I don't think that's a requirement.) 

While I'm here, get rid of the unnecessary warning about
SimplifyInstructionsInBlock, since it should work correctly as far as I know.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128782 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-02 22:45:17 +00:00
Jay Foad
3ecfc861b4 Remove PHINode::reserveOperandSpace(). Instead, add a parameter to
PHINode::Create() giving the (known or expected) number of operands.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128537 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-30 11:28:46 +00:00
Jay Foad
d8b4fb4aab (Almost) always call reserveOperandSpace() on newly created PHINodes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128535 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-30 11:19:20 +00:00
Devang Patel
b99462117e Simplify.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128030 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-21 22:04:45 +00:00
Devang Patel
36fae67831 If an AllocaInst referred by DbgDeclareInst is used by a LoadInst then the LoadInst should also get a corresponding llvm.dbg.value intrinsic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127924 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-18 23:45:43 +00:00
Devang Patel
79fcad85a4 Remove dead code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127923 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-18 23:33:58 +00:00
Devang Patel
9c5822a966 Consider debug info intrinsics pointing to null value as dead instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127922 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-18 23:28:02 +00:00
Devang Patel
813c9a0f19 Try to not lose variable's debug info during instcombine.
This is done by lowering dbg.declare intrinsic into dbg.value intrinsic.
Radar 9143931.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127834 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-17 22:18:16 +00:00
Devang Patel
5ee20680c7 Refactor into a separate utility function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127832 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-17 21:58:19 +00:00
Cameron Zwarich
6e51c6ad9d Clean up something noticed by Fritz.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127684 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-15 18:42:33 +00:00
Cameron Zwarich
838b97edfa Do not add PHIs with no users when creating LCSSA form. Patch by Andrew Clinton.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127674 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-15 07:41:25 +00:00
Eli Friedman
b1a6eab655 PR9450: Make switch optimization in SimplifyCFG not dependent on the ordering
of pointers in an std::map.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127650 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-15 02:23:35 +00:00
Eli Friedman
2adc5b6a17 PR9420; an instruction before an unreachable is guaranteed not to have any
reachable uses, but there still might be uses in dead blocks.  Use the
standard solution of replacing all the uses with undef.  This is
a rare case because it's very sensitive to phase ordering in SimplifyCFG.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127299 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-09 00:48:33 +00:00
Jakob Stoklund Olesen
2bc2a08b1b DenseMap<uintptr_t,...> doesn't allow all values as keys.
Avoid colliding with the sentinels, hopefully unbreaking
llvm-gcc-x86_64-linux-selfhost.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126982 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-04 02:48:56 +00:00
Frits van Bommel
f7b2a9d7df Teach SimplifyCFG that (switch (select cond, X, Y)) is better expressed as a branch.
Based on a patch by Alistair Lynn.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126647 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-28 09:44:07 +00:00
Benjamin Kramer
278be783b5 Revert "SimplifyCFG: GEPs with just one non-constant index are also cheap."
Yes, there are other types than i8* and GEPs on them can produce an add+multiply.
We don't consider that cheap enough to be speculatively executed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126481 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-25 10:33:33 +00:00
Benjamin Kramer
9ae59e3444 SimplifyCFG: GEPs with just one non-constant index are also cheap.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126452 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-24 23:26:09 +00:00
Benjamin Kramer
9b61c550c2 SimplifyCFG: GEPs with constant indices are cheap enough to be executed unconditionally.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126445 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-24 22:46:11 +00:00
Devang Patel
afd0d0e8a7 Do not use DIFactory. Use DIBuilder.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126398 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-24 18:49:55 +00:00
Duncan Sands
2cfbf018a9 If the phi node was used by an unreachable instruction that ends up using
itself without going via a phi node then we could return false here in
spite of making a change.  Also, tweak the comment because this method
can (and always could) return true without deleting the original phi node.
For example, if the phi node was used by a read-only invoke instruction
which is used by another phi node phi2 which is only used by and only uses
the invoke, then phi2 would be deleted but not the invoke instruction and
not the original phi node.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126129 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-21 17:32:05 +00:00
Duncan Sands
b4098ba03d Simplify RecursivelyDeleteDeadPHINode. The only functionality change
should be that if the phi is used by a side-effect free instruction with
no uses then the phi and the instruction now get zapped (checked by the
unittest).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126124 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-21 16:27:36 +00:00
Nick Lewycky
eff5e69c82 Make RecursivelyDeleteDeadPHINode delete a phi node that has no users and add a
test for that. With this change, test/CodeGen/X86/codegen-dce.ll no longer finds
any instructions to DCE, so delete the test.

Also renamed J and JP to I and IP in RecursivelyDeleteDeadPHINode.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126088 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-20 18:05:56 +00:00
Nick Lewycky
1a4021a2be Teach RecursivelyDeleteDeadPHINodes to handle multiple self-references. Patch
by Andrew Clinton!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126077 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-20 08:38:20 +00:00
Chris Lattner
f5ebfb0d28 Don't unroll loops whose header block's address is taken.
This is part of a futile attempt to not "break" bizzaro
code like this:

 l1:
  printf("l1: %p\n", &&l1);
  ++x;

  if( x < 3 ) goto l1;


Previously we'd fold &&l1 to 1, which is fine per our semantics
but not helpful to the user.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125827 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-18 04:25:21 +00:00
Cameron Zwarich
4a60b932a2 Rename 'loopsimplify' to 'loop-simplify'.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125317 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-10 23:38:10 +00:00
Benjamin Kramer
33828bcb24 SimplifyCFG: Track the number of used icmps when turning a icmp chain into a switch. If we used only one icmp, don't turn it into a switch.
Also prevent the switch-to-icmp transform from creating identity adds, noticed by Marius Wachtler.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125056 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-07 22:37:28 +00:00
Benjamin Kramer
042b27f40e SimplifyCFG: Also transform switches that represent a range comparison but are not sorted into sub+icmp.
This transforms another 1000 switches in gcc.c.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124826 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-03 22:51:41 +00:00
Benjamin Kramer
56442dfdcf SimplifyCFG: Turn switches into sub+icmp+branch if possible.
This makes the job of the later optzn passes easier, allowing the vast amount of
icmp transforms to chew on it.

We transform 840 switches in gcc.c, leading to a 16k byte shrink of the resulting
binary on i386-linux.

The testcase from README.txt now compiles into
  decl  %edi
  cmpl  $3, %edi
  sbbl  %eax, %eax
  andl  $1, %eax
  ret

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124724 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-02 15:56:22 +00:00
Evan Cheng
c3f507f98a Re-apply r124518 with fix. Watch out for invalidated iterator.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124526 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-29 04:46:23 +00:00
Evan Cheng
b0a42fdb36 Revert r124518. It broke Linux self-host.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124522 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-29 02:43:04 +00:00
Evan Cheng
5e6940788f Re-commit r124462 with fixes. Tail recursion elim will now dup ret into unconditional predecessor to enable TCE on demand.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124518 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-29 01:29:26 +00:00
Evan Cheng
1b5c0cb71d Revert r124462. There are a few big regressions that I need to fix first.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124478 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-28 07:12:38 +00:00
Evan Cheng
40f64cb0de - Stop simplifycfg from duplicating "ret" instructions into unconditional
branches. PR8575, rdar://5134905, rdar://8911460.
- Allow codegen tail duplication to dup small return blocks after register
  allocation is done.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124462 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-28 02:19:21 +00:00
Chris Lattner
867be59684 fix PR9017, a bug where we'd assert when promoting in unreachable
code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124100 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-24 03:29:07 +00:00
Chris Lattner
51e62f0f73 fix PR9015, a crash linking recursive metadata.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124099 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-24 03:18:24 +00:00
Cameron Zwarich
491d8d4370 Convert two std::vectors to SmallVectors for a 3.4% speedup running -scalarrepl
on test-suite + SPEC2000 & SPEC2006.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124068 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-23 08:03:04 +00:00
Cameron Zwarich
59f5319719 Convert a std::map to a DenseMap for another 1.7% speedup on -scalarrepl.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123732 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-18 04:50:38 +00:00
Cameron Zwarich
443997de8b Make a std::vector a SmallVector<*, 32> like the other vectors in the same
function. This seems to be about a 1.5% speedup of -scalarrepl on test-suite
with SPEC2000 and SPEC2006.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123731 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-18 04:41:32 +00:00
Cameron Zwarich
301278719b Remove code for updating dominance frontiers and some outdated references to
dominance and post-dominance frontiers.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123725 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-18 04:11:31 +00:00
Cameron Zwarich
b1686c32fc Remove outdated references to dominance frontiers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123724 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-18 03:53:26 +00:00
Cameron Zwarich
419e8a6299 Roll r123609 back in with two changes that fix test failures with expensive
checks enabled:

1) Use '<' to compare integers in a comparison function rather than '<='.

2) Use the uniqued set DefBlocks rather than Info.DefiningBlocks to initialize
the priority queue.

The speedup of scalarrepl on test-suite + SPEC2000 + SPEC2006 is a bit less, at
just under 16% rather than 17%.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123662 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-17 17:38:41 +00:00
Cameron Zwarich
b1086a9c6d Roll out r123609 due to failures on the llvm-x86_64-linux-checks bot.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123618 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-17 07:26:51 +00:00
Cameron Zwarich
ebed6de7b1 Eliminate the use of dominance frontiers in PromoteMemToReg. In addition to
eliminating a potentially quadratic data structure, this also gives a 17%
speedup when running -scalarrepl on test-suite + SPEC2000 + SPEC2006. My initial
experiment gave a greater speedup around 25%, but I moved the dominator tree
level computation from dominator tree construction to PromoteMemToReg.

Since this approach to computing IDFs has a much lower overhead than the old
code using precomputed DFs, it is worth looking at using this new code for the
second scalarrepl pass as well.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123609 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-17 01:08:59 +00:00
Chris Lattner
deaf55f698 Generalize LoadAndStorePromoter a bit and switch LICM
to use it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123501 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-15 00:12:35 +00:00
Chris Lattner
a2d845a3ff Add a new LoadAndStorePromoter class, which implements the general
"promote a bunch of load and stores" logic, allowing the code to
be shared and reused.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123456 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-14 19:36:13 +00:00
Chris Lattner
70e5e222db indentation
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123426 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-14 04:23:53 +00:00
Jakob Stoklund Olesen
fbbd4abfe5 Fix a non-deterministic loop in llvm::MergeBlockIntoPredecessor.
DT->changeImmediateDominator() trivially ignores identity updates, so there is
really no need for the uniqueing provided by SmallPtrSet.

I expect this to fix PR8954.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123286 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-11 22:54:38 +00:00
Chris Lattner
f73b99ab43 this pass claims to preserve scev, make sure to tell it about deletions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123247 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-11 18:14:50 +00:00
Frits van Bommel
65fdded319 Factor the actual simplification out of SimplifyIndirectBrOnSelect and into a new helper function so it can be reused in e.g. an upcoming SimplifySwitchOnSelect.
No functional change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123234 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-11 12:52:11 +00:00
Chris Lattner
b6810991a9 when MergeBlockIntoPredecessor merges two blocks, update MemDep if it
is floating around in the ether.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123223 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-11 08:16:49 +00:00
Chris Lattner
b5b7997fd0 Fix FoldSingleEntryPHINodes to update memdep and AA when it deletes
phi nodes.  It is called from MergeBlockIntoPredecessor which is 
called from GVN, which claims to preserve these.

I'm skeptical that this is the actual problem behind PR8954, but
this is a stab in the right direction.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123222 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-11 08:13:40 +00:00
Chris Lattner
b298db7253 random cleanups
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123221 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-11 08:00:40 +00:00
Chris Lattner
dc85f8ab80 various code cleanups, enhance MergeBlockIntoPredecessor to preserve
loop info.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123074 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08 19:08:40 +00:00
Chris Lattner
b0433d4b2f reduce nesting.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123071 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08 18:47:43 +00:00
Cameron Zwarich
80f6a507d4 Make more passes preserve dominators (or state that they preserve dominators if
they all ready do). This removes two dominator recomputations prior to isel,
which is a 1% improvement in total llc time for 403.gcc.

The only potentially suspect thing is making GCStrategy recompute dominators if
it used a custom lowering strategy.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123064 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08 17:01:52 +00:00
Chris Lattner
b5fa5fcecc Revamp the ValueMapper interfaces in a couple ways:
1. Take a flags argument instead of a bool.  This makes
   it more clear to the reader what it is used for.
2. Add a flag that says that "remapping a value not in the
   map is ok".
3. Reimplement MapValue to share a bunch of code and be a lot
   more efficient.  For lookup failures, don't drop null values
   into the map.
4. Using the new flag a bunch of code can vaporize in LinkModules
   and LoopUnswitch, kill it.

No functionality change.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123058 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08 08:15:20 +00:00
Jay Foad
8f9ffbd056 Remove all uses of the "ugly" method BranchInst::setUnconditionalDest().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123025 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-07 20:25:56 +00:00
Duncan Sands
dc615e41b5 Speed up instsimplify by about 10-15% by not bothering to retry
InstructionSimplify on instructions that didn't change since the
last time round the loop.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122745 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-03 10:50:04 +00:00
Chris Lattner
9fc5cdf77c split dom frontier handling stuff out to its own DominanceFrontier header,
so that Dominators.h is *just* domtree.  Also prune #includes a bit.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122714 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-02 22:09:33 +00:00
Duncan Sands
67fb341f8b Fix PR8702 by not having LoopSimplify claim to preserve LCSSA form. As described
in the PR, the pass could break LCSSA form when inserting preheaders.  It probably
would be easy enough to fix this, but since currently we always go into LCSSA form
after running this pass, doing so is not urgent.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122695 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-02 13:38:21 +00:00
Duncan Sands
8a3d29cf10 Simplify this pass by using a depth-first iterator to ensure that all
operands are visited before the instructions themselves.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122647 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-31 17:49:05 +00:00
Duncan Sands
fea0b8b666 Zap dead instructions harder.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122645 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-31 16:17:54 +00:00
Benjamin Kramer
1928236514 Make a bunch of symbols internal.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122642 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-30 22:34:44 +00:00
Benjamin Kramer
def548f9a0 BuildLibCalls: Nuke EmitMemCpy, EmitMemMove and EmitMemSet. They are dead and superseded by IRBuilder.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122576 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-27 00:25:32 +00:00
Chris Lattner
ae47be1ea0 don't lose TD info
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122556 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-25 20:52:04 +00:00
Chris Lattner
7569d79de1 switch the inliner alignment enforcement stuff to use the
getOrEnforceKnownAlignment function, which simplifies the code
and makes it stronger.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122555 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-25 20:42:38 +00:00
Chris Lattner
687140c818 Move getOrEnforceKnownAlignment out of instcombine into Transforms/Utils.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122554 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-25 20:37:57 +00:00
Jeffrey Yasskin
8e68c38735 Change all self assignments X=X to (void)X, so that we can turn on a
new gcc warning that complains on self-assignments and
self-initializations.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122458 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-23 00:58:24 +00:00
Duncan Sands
1cd0f4637b Visit instructions deterministically. Use a FIFO so as to approximately
visit instructions before their uses, since InstructionSimplify does a
better job in that case.  All this prompted by Frits van Bommel.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122343 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-21 17:08:55 +00:00
Duncan Sands
e95cc25a22 If an instruction simplifies, try again to simplify any uses of it. This is
not very important since the pass is only used for testing, but it does make
it more realistic.  Suggested by Frits van Bommel.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122336 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-21 16:12:03 +00:00
Duncan Sands
69fdf876e1 Oops, forgot to add the pass itself!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122265 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-20 21:07:42 +00:00
Duncan Sands
43ff68ded0 Add a new convenience pass for testing InstructionSimplify. Previously
it could only be tested indirectly, via instcombine, gvn or some other
pass that makes use of InstructionSimplify, which means that testcases
had to be carefully contrived to dance around any other transformations
that that pass did.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122264 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-20 20:54:37 +00:00
Chris Lattner
0b66f63a26 when eliding a byval copy due to inlining a readonly function, we have
to make sure that the reused alloca has sufficient alignment.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122236 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-20 08:10:40 +00:00
Chris Lattner
e7ae705c32 pull byval processing out to its own helper function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122235 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-20 07:57:41 +00:00
Chris Lattner
018fb767b9 fix PR8769, a miscompilation by inliner when inlining a function with a byval
argument.  The generated alloca has to have at least the alignment of the
byval, if not, the client may be making assumptions that the new alloca won't
satisfy.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122234 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-20 07:45:28 +00:00
Chris Lattner
a37029cd24 simplify this a bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122156 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-18 20:22:49 +00:00
Benjamin Kramer
14c0987bd9 SimplifyCFG: Ranges can be larger than 64 bits. Fixes Release-selfhost build.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122054 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-17 10:48:14 +00:00
Chris Lattner
e27db74a60 improve switch formation to handle small range
comparisons formed by comparisons.  For example,
this:

void foo(unsigned x) {
  if (x == 0 || x == 1 || x == 3 || x == 4 || x == 6) 
    bar();
}

compiles into:

_foo:                                   ## @foo
## BB#0:                                ## %entry
	cmpl	$6, %edi
	ja	LBB0_2
## BB#1:                                ## %entry
	movl	%edi, %eax
	movl	$91, %ecx
	btq	%rax, %rcx
	jb	LBB0_3

instead of:

_foo:                                   ## @foo
## BB#0:                                ## %entry
	cmpl	$2, %edi
	jb	LBB0_4
## BB#1:                                ## %switch.early.test
	cmpl	$6, %edi
	ja	LBB0_3
## BB#2:                                ## %switch.early.test
	movl	%edi, %eax
	movl	$88, %ecx
	btq	%rax, %rcx
	jb	LBB0_4

This catches a bunch of cases in GCC, which look like this:

 %804 = load i32* @which_alternative, align 4, !tbaa !0
 %805 = icmp ult i32 %804, 2
 %806 = icmp eq i32 %804, 3
 %or.cond121 = or i1 %805, %806
 %807 = icmp eq i32 %804, 4
 %or.cond124 = or i1 %or.cond121, %807
 br i1 %or.cond124, label %.thread, label %808

turning this into a range comparison.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122045 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-17 06:20:15 +00:00
Chris Lattner
ba3c815570 make qsort predicate more conformant by returning 0 for equal values.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121838 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-15 04:52:41 +00:00
Chris Lattner
3aff13b82a - Insert new instructions before DomBlock's terminator,
which is simpler than finding a place to insert in BB.
 - Don't perform the 'if condition hoisting' xform on certain
   i1 PHIs, as it interferes with switch formation.

This re-fixes "example 7", without breaking the world hopefully.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121764 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-14 08:46:09 +00:00
Chris Lattner
60d410d7bb fix two significant issues with FoldTwoEntryPHINode:
first, it can kick in on blocks whose conditions have been
folded to a constant, even though one of the edges will be
trivially folded.

second, it doesn't clean up the "if diamond" that it just 
eliminated away.  This is a problem because other simplifycfg
xforms kick in depending on the order of block visitation,
causing pointless work.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121762 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-14 08:01:53 +00:00
Chris Lattner
071edc81f2 remove the instsimplify logic I added in r121754. It is apparently
breaking the selfhost builds, though I can't fathom how.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121761 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-14 07:53:03 +00:00
Chris Lattner
44da7ca421 clean up logic, convert std::set to SmallPtrSet, handle the case
when all 2-entry phis are simplified away.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121760 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-14 07:41:39 +00:00
Chris Lattner
e0b18e5912 tidy up a bit, move DEBUG down to when we commit to doing the transform so we
don't print it unless the xform happens.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121758 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-14 07:23:10 +00:00
Chris Lattner
07ff3539f5 use SimplifyInstruction instead of reimplementing part of it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121757 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-14 07:20:29 +00:00
Chris Lattner
995ba1bd49 simplify GetIfCondition by using getSinglePredecessor.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121756 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-14 07:15:21 +00:00