Frits van Bommel
df58ece78a
Add a parameter to ConstantFoldTerminator() that callers can use to ask it to also clean up the condition of any conditional terminator it folds to be unconditional, if that turns the condition into dead code. This just means it calls RecursivelyDeleteTriviallyDeadInstructions() in strategic spots. It defaults to the old behavior.
...
I also changed -simplifycfg, -jump-threading and -codegenprepare to use this to produce slightly better code without any extra cleanup passes (AFAICT this was the only place in -simplifycfg where now-dead conditions of replaced terminators weren't being cleaned up). The only other user of this function is -sccp, but I didn't read that thoroughly enough to figure out whether it might be holding pointers to instructions that could be deleted by this.
llvm-svn: 131855
2011-05-22 16:24:18 +00:00
Nick Lewycky
9f7644d549
Teach the inliner to emit llvm.lifetime.start/end, to scope the local variables
...
of the inlinee to the code representing the original function.
llvm-svn: 131838
2011-05-22 05:22:10 +00:00
Devang Patel
8d9eb3b0f7
Reapply r131605. This time with a fix, which is to use NoFolder.
...
llvm-svn: 131673
2011-05-19 20:52:46 +00:00
Rafael Espindola
4ebe940cd4
revert 131605 to fix PR9946.
...
llvm-svn: 131620
2011-05-19 02:26:30 +00:00
Devang Patel
c5390e2f7f
Use IRBuilder.
...
llvm-svn: 131609
2011-05-19 00:13:33 +00:00
Devang Patel
ecb22f0544
Use IRBuilder while simplifying unreachable.
...
llvm-svn: 131607
2011-05-19 00:09:21 +00:00
Devang Patel
fa6d0b4f84
Use IRBuilder while simplifying conditional branch.
...
llvm-svn: 131605
2011-05-18 23:59:51 +00:00
Devang Patel
877a16ea33
Use IRBuilder while simplifying branch.
...
llvm-svn: 131598
2011-05-18 23:18:47 +00:00
Devang Patel
3f94bed4e4
Use IRBuilder while simplifying return instruction.
...
llvm-svn: 131580
2011-05-18 21:33:11 +00:00
Devang Patel
3549e33227
Spread use of IRBuilder even more.
...
llvm-svn: 131571
2011-05-18 20:53:17 +00:00
Devang Patel
fd9b1daf82
Use IRBuilder while simplifying switch instruction.
...
llvm-svn: 131566
2011-05-18 20:35:38 +00:00
Devang Patel
40690a2df4
Use IRBuilder while simplifying unwind.
...
llvm-svn: 131561
2011-05-18 20:01:18 +00:00
Devang Patel
f0b8a243b9
Use IRBuilder while simplifying terminator.
...
llvm-svn: 131552
2011-05-18 18:43:31 +00:00
Devang Patel
faedd704bb
Use IRBuilder while simplifying unconditional branch.
...
llvm-svn: 131551
2011-05-18 18:28:48 +00:00
Devang Patel
9249a85cdc
Use IRBuilder while folding two entry PHINode.
...
llvm-svn: 131548
2011-05-18 18:16:44 +00:00
Devang Patel
6eb1a7bd09
Set up IRBuilder for use during simplification.
...
llvm-svn: 131545
2011-05-18 18:01:27 +00:00
Matt Beaumont-Gay
7472bb0a7e
fix typo
...
llvm-svn: 131543
2011-05-18 17:37:10 +00:00
Devang Patel
a6e4c7a441
Use IRBuiler while constant folding terminator.
...
llvm-svn: 131541
2011-05-18 17:26:46 +00:00
Devang Patel
b75e746499
Preseve line numbers while simplifying CFG.
...
llvm-svn: 131508
2011-05-17 23:29:05 +00:00
Devang Patel
8a2b06e577
Preserve line number information.
...
llvm-svn: 131480
2011-05-17 19:43:06 +00:00
Devang Patel
8cf3c94ae5
There is no need to force DebugLoc on a PHI at this point.
...
llvm-svn: 131427
2011-05-16 22:05:03 +00:00
Devang Patel
9f871794b6
Preserve debug info for unused zero extended boolean argument.
...
Radar 9422775.
llvm-svn: 131422
2011-05-16 21:24:05 +00:00
Benjamin Kramer
5943d0a3ee
SimplifyCFG: Use ComputeMaskedBits to prune dead cases from switch instructions.
...
llvm-svn: 131345
2011-05-14 15:57:25 +00:00
Devang Patel
236dc68956
Set debug location for new PHI nodes created in exit block.
...
llvm-svn: 130894
2011-05-04 23:58:22 +00:00
Devang Patel
4127ad57df
Scanning entire basic block may be too expensive in terms of compile time. Instead, just use whatever location info first non-phi instruction has.
...
llvm-svn: 130729
2011-05-02 21:57:00 +00:00
Devang Patel
60fb94e8bf
Assing line number info to new PHIs created by SSA updater.
...
llvm-svn: 130551
2011-04-29 22:28:59 +00:00
Peter Collingbourne
d78bf257ad
SimplifyCFG: Expose phi node folding cost threshold as command line parameter
...
llvm-svn: 130528
2011-04-29 18:47:38 +00:00
Peter Collingbourne
0994e869f9
SimplifyCFG: Add CostRemaining parameter to DominatesMergePoint
...
llvm-svn: 130527
2011-04-29 18:47:31 +00:00
Peter Collingbourne
06646aa091
SimplifyCFG: Add Trunc, ZExt and SExt to the list of cheap instructions for phi node folding
...
llvm-svn: 130526
2011-04-29 18:47:25 +00:00
Devang Patel
5e9ca7876e
Remove DbgDeclare only if all uses are converted.
...
llvm-svn: 130431
2011-04-28 20:32:02 +00:00
Jay Foad
c146569beb
Remove unused STL header includes.
...
llvm-svn: 130068
2011-04-23 19:53:52 +00:00
Jay Foad
32fce4d563
PR9214: Convert Metadata API to use ArrayRef.
...
llvm-svn: 129932
2011-04-21 19:59:31 +00:00
Jay Foad
0dcd432074
Trivial simplification.
...
llvm-svn: 129759
2011-04-19 15:23:29 +00:00
Chris Lattner
0304b82f80
Fix a ton of comment typos found by codespell. Patch by
...
Luis Felipe Strano Moraes!
llvm-svn: 129558
2011-04-15 05:18:47 +00:00
Chris Lattner
88e2acc24c
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.
llvm-svn: 129502
2011-04-14 02:44:53 +00:00
Chris Lattner
2871dd44cb
comment cleanup, use moveBefore instead of removeFromParent+insertBefore.
...
llvm-svn: 129319
2011-04-11 23:24:57 +00:00
Jay Foad
0d5ca4cf44
Don't include Operator.h from InstrTypes.h.
...
llvm-svn: 129271
2011-04-11 09:35:34 +00:00
Devang Patel
47e1db49c9
Do not let debug info interfer with branch folding.
...
llvm-svn: 129114
2011-04-07 23:11:25 +00:00
Devang Patel
17670a995c
While hoisting common code from if/else, hoist debug info intrinsics if they match.
...
llvm-svn: 129078
2011-04-07 17:27:36 +00:00
Devang Patel
bb234bb5dd
Simplify. isIdenticalToWhenDefined() checks opcode.
...
llvm-svn: 129041
2011-04-07 00:30:15 +00:00
Devang Patel
12a95842b2
While folding branch to a common destination into a predecessor, copy dbg values also.
...
llvm-svn: 129035
2011-04-06 22:37:20 +00:00
Eli Friedman
f739e21880
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...)
llvm-svn: 128802
2011-04-04 00:37:38 +00:00
Eli Friedman
8b6d220330
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.
llvm-svn: 128782
2011-04-02 22:45:17 +00:00
Jay Foad
53632b7c03
Remove PHINode::reserveOperandSpace(). Instead, add a parameter to
...
PHINode::Create() giving the (known or expected) number of operands.
llvm-svn: 128537
2011-03-30 11:28:46 +00:00
Jay Foad
dc5a008237
(Almost) always call reserveOperandSpace() on newly created PHINodes.
...
llvm-svn: 128535
2011-03-30 11:19:20 +00:00
Devang Patel
05641a9b85
Simplify.
...
llvm-svn: 128030
2011-03-21 22:04:45 +00:00
Devang Patel
c8b77563dc
If an AllocaInst referred by DbgDeclareInst is used by a LoadInst then the LoadInst should also get a corresponding llvm.dbg.value intrinsic.
...
llvm-svn: 127924
2011-03-18 23:45:43 +00:00
Devang Patel
a5de669faa
Remove dead code.
...
llvm-svn: 127923
2011-03-18 23:33:58 +00:00
Devang Patel
bafc4fec54
Consider debug info intrinsics pointing to null value as dead instructions.
...
llvm-svn: 127922
2011-03-18 23:28:02 +00:00
Devang Patel
f8c3eb7368
Try to not lose variable's debug info during instcombine.
...
This is done by lowering dbg.declare intrinsic into dbg.value intrinsic.
Radar 9143931.
llvm-svn: 127834
2011-03-17 22:18:16 +00:00
Devang Patel
3506f02e33
Refactor into a separate utility function.
...
llvm-svn: 127832
2011-03-17 21:58:19 +00:00
Cameron Zwarich
333ed540e7
Clean up something noticed by Fritz.
...
llvm-svn: 127684
2011-03-15 18:42:33 +00:00
Cameron Zwarich
7947e73536
Do not add PHIs with no users when creating LCSSA form. Patch by Andrew Clinton.
...
llvm-svn: 127674
2011-03-15 07:41:25 +00:00
Eli Friedman
c0bfbd0610
PR9450: Make switch optimization in SimplifyCFG not dependent on the ordering
...
of pointers in an std::map.
llvm-svn: 127650
2011-03-15 02:23:35 +00:00
Eli Friedman
d1e9ff0d6c
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.
llvm-svn: 127299
2011-03-09 00:48:33 +00:00
Jakob Stoklund Olesen
c7bf5eaafb
DenseMap<uintptr_t,...> doesn't allow all values as keys.
...
Avoid colliding with the sentinels, hopefully unbreaking
llvm-gcc-x86_64-linux-selfhost.
llvm-svn: 126982
2011-03-04 02:48:56 +00:00
Frits van Bommel
4a2b658705
Teach SimplifyCFG that (switch (select cond, X, Y)) is better expressed as a branch.
...
Based on a patch by Alistair Lynn.
llvm-svn: 126647
2011-02-28 09:44:07 +00:00
Benjamin Kramer
39a5d8596c
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.
llvm-svn: 126481
2011-02-25 10:33:33 +00:00
Benjamin Kramer
44b43a85db
SimplifyCFG: GEPs with just one non-constant index are also cheap.
...
llvm-svn: 126452
2011-02-24 23:26:09 +00:00
Benjamin Kramer
b5996b08b7
SimplifyCFG: GEPs with constant indices are cheap enough to be executed unconditionally.
...
llvm-svn: 126445
2011-02-24 22:46:11 +00:00
Devang Patel
29b946c0bd
Do not use DIFactory. Use DIBuilder.
...
llvm-svn: 126398
2011-02-24 18:49:55 +00:00
Duncan Sands
17a277da6d
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.
llvm-svn: 126129
2011-02-21 17:32:05 +00:00
Duncan Sands
702e8b136e
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).
llvm-svn: 126124
2011-02-21 16:27:36 +00:00
Nick Lewycky
ecae3aec02
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.
llvm-svn: 126088
2011-02-20 18:05:56 +00:00
Nick Lewycky
4d7bb906df
Teach RecursivelyDeleteDeadPHINodes to handle multiple self-references. Patch
...
by Andrew Clinton!
llvm-svn: 126077
2011-02-20 08:38:20 +00:00
Chris Lattner
cd170f7cf6
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.
llvm-svn: 125827
2011-02-18 04:25:21 +00:00
Cameron Zwarich
9d8ab7d0f7
Rename 'loopsimplify' to 'loop-simplify'.
...
llvm-svn: 125317
2011-02-10 23:38:10 +00:00
Benjamin Kramer
04249128ab
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.
llvm-svn: 125056
2011-02-07 22:37:28 +00:00
Benjamin Kramer
75785ec972
SimplifyCFG: Also transform switches that represent a range comparison but are not sorted into sub+icmp.
...
This transforms another 1000 switches in gcc.c.
llvm-svn: 124826
2011-02-03 22:51:41 +00:00
Benjamin Kramer
b739613711
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
llvm-svn: 124724
2011-02-02 15:56:22 +00:00
Evan Cheng
4af5487b74
Re-apply r124518 with fix. Watch out for invalidated iterator.
...
llvm-svn: 124526
2011-01-29 04:46:23 +00:00
Evan Cheng
1f943b9b13
Revert r124518. It broke Linux self-host.
...
llvm-svn: 124522
2011-01-29 02:43:04 +00:00
Evan Cheng
a1e4cb5f09
Re-commit r124462 with fixes. Tail recursion elim will now dup ret into unconditional predecessor to enable TCE on demand.
...
llvm-svn: 124518
2011-01-29 01:29:26 +00:00
Evan Cheng
5b6c72e549
Revert r124462. There are a few big regressions that I need to fix first.
...
llvm-svn: 124478
2011-01-28 07:12:38 +00:00
Evan Cheng
7031f450b3
- 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.
llvm-svn: 124462
2011-01-28 02:19:21 +00:00
Chris Lattner
f33b65080c
fix PR9017, a bug where we'd assert when promoting in unreachable
...
code.
llvm-svn: 124100
2011-01-24 03:29:07 +00:00
Chris Lattner
077cdfcadb
fix PR9015, a crash linking recursive metadata.
...
llvm-svn: 124099
2011-01-24 03:18:24 +00:00
Cameron Zwarich
3295a3b4db
Convert two std::vectors to SmallVectors for a 3.4% speedup running -scalarrepl
...
on test-suite + SPEC2000 & SPEC2006.
llvm-svn: 124068
2011-01-23 08:03:04 +00:00
Cameron Zwarich
4ccaa5dccc
Convert a std::map to a DenseMap for another 1.7% speedup on -scalarrepl.
...
llvm-svn: 123732
2011-01-18 04:50:38 +00:00
Cameron Zwarich
c35c06d0d4
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.
llvm-svn: 123731
2011-01-18 04:41:32 +00:00
Cameron Zwarich
c93f994801
Remove code for updating dominance frontiers and some outdated references to
...
dominance and post-dominance frontiers.
llvm-svn: 123725
2011-01-18 04:11:31 +00:00
Cameron Zwarich
e39e476305
Remove outdated references to dominance frontiers.
...
llvm-svn: 123724
2011-01-18 03:53:26 +00:00
Cameron Zwarich
0a1975802e
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%.
llvm-svn: 123662
2011-01-17 17:38:41 +00:00
Cameron Zwarich
77e381e302
Roll out r123609 due to failures on the llvm-x86_64-linux-checks bot.
...
llvm-svn: 123618
2011-01-17 07:26:51 +00:00
Cameron Zwarich
e35642342b
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.
llvm-svn: 123609
2011-01-17 01:08:59 +00:00
Chris Lattner
e6d5b3c4ce
Generalize LoadAndStorePromoter a bit and switch LICM
...
to use it.
llvm-svn: 123501
2011-01-15 00:12:35 +00:00
Chris Lattner
2cf8e75d34
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.
llvm-svn: 123456
2011-01-14 19:36:13 +00:00
Chris Lattner
b1ba935526
indentation
...
llvm-svn: 123426
2011-01-14 04:23:53 +00:00
Jakob Stoklund Olesen
37fe53c1a9
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.
llvm-svn: 123286
2011-01-11 22:54:38 +00:00
Chris Lattner
1674862564
this pass claims to preserve scev, make sure to tell it about deletions.
...
llvm-svn: 123247
2011-01-11 18:14:50 +00:00
Frits van Bommel
f5bd48972a
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.
llvm-svn: 123234
2011-01-11 12:52:11 +00:00
Chris Lattner
a82a6cfe6d
when MergeBlockIntoPredecessor merges two blocks, update MemDep if it
...
is floating around in the ether.
llvm-svn: 123223
2011-01-11 08:16:49 +00:00
Chris Lattner
dc7b2160ba
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.
llvm-svn: 123222
2011-01-11 08:13:40 +00:00
Chris Lattner
b1a9c9ed36
random cleanups
...
llvm-svn: 123221
2011-01-11 08:00:40 +00:00
Chris Lattner
145e4ee94e
various code cleanups, enhance MergeBlockIntoPredecessor to preserve
...
loop info.
llvm-svn: 123074
2011-01-08 19:08:40 +00:00
Chris Lattner
f1a01c01d9
reduce nesting.
...
llvm-svn: 123071
2011-01-08 18:47:43 +00:00
Cameron Zwarich
a40df277f1
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.
llvm-svn: 123064
2011-01-08 17:01:52 +00:00
Chris Lattner
397937fa0d
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.
llvm-svn: 123058
2011-01-08 08:15:20 +00:00
Jay Foad
03be607946
Remove all uses of the "ugly" method BranchInst::setUnconditionalDest().
...
llvm-svn: 123025
2011-01-07 20:25:56 +00:00
Duncan Sands
667024a2eb
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.
llvm-svn: 122745
2011-01-03 10:50:04 +00:00
Chris Lattner
e396e846b4
split dom frontier handling stuff out to its own DominanceFrontier header,
...
so that Dominators.h is *just* domtree. Also prune #includes a bit.
llvm-svn: 122714
2011-01-02 22:09:33 +00:00
Duncan Sands
2d1c116071
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.
llvm-svn: 122695
2011-01-02 13:38:21 +00:00
Duncan Sands
74270e8100
Simplify this pass by using a depth-first iterator to ensure that all
...
operands are visited before the instructions themselves.
llvm-svn: 122647
2010-12-31 17:49:05 +00:00
Duncan Sands
ca280dbcd5
Zap dead instructions harder.
...
llvm-svn: 122645
2010-12-31 16:17:54 +00:00
Benjamin Kramer
c84434924f
Make a bunch of symbols internal.
...
llvm-svn: 122642
2010-12-30 22:34:44 +00:00
Benjamin Kramer
30e1ba0fcc
BuildLibCalls: Nuke EmitMemCpy, EmitMemMove and EmitMemSet. They are dead and superseded by IRBuilder.
...
llvm-svn: 122576
2010-12-27 00:25:32 +00:00
Chris Lattner
a73a53e67f
don't lose TD info
...
llvm-svn: 122556
2010-12-25 20:52:04 +00:00
Chris Lattner
38d6d6d367
switch the inliner alignment enforcement stuff to use the
...
getOrEnforceKnownAlignment function, which simplifies the code
and makes it stronger.
llvm-svn: 122555
2010-12-25 20:42:38 +00:00
Chris Lattner
c4cb20b9bf
Move getOrEnforceKnownAlignment out of instcombine into Transforms/Utils.
...
llvm-svn: 122554
2010-12-25 20:37:57 +00:00
Jeffrey Yasskin
a199652a3e
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.
llvm-svn: 122458
2010-12-23 00:58:24 +00:00
Duncan Sands
c7868f60bc
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.
llvm-svn: 122343
2010-12-21 17:08:55 +00:00
Duncan Sands
6e2fd37144
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.
llvm-svn: 122336
2010-12-21 16:12:03 +00:00
Duncan Sands
0a1b3c4cee
Oops, forgot to add the pass itself!
...
llvm-svn: 122265
2010-12-20 21:07:42 +00:00
Duncan Sands
09fbb211eb
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.
llvm-svn: 122264
2010-12-20 20:54:37 +00:00
Chris Lattner
ba962825a4
when eliding a byval copy due to inlining a readonly function, we have
...
to make sure that the reused alloca has sufficient alignment.
llvm-svn: 122236
2010-12-20 08:10:40 +00:00
Chris Lattner
c0a48df9f9
pull byval processing out to its own helper function.
...
llvm-svn: 122235
2010-12-20 07:57:41 +00:00
Chris Lattner
029952c844
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.
llvm-svn: 122234
2010-12-20 07:45:28 +00:00
Chris Lattner
25d76d1e53
simplify this a bit.
...
llvm-svn: 122156
2010-12-18 20:22:49 +00:00
Benjamin Kramer
39b30b18fa
SimplifyCFG: Ranges can be larger than 64 bits. Fixes Release-selfhost build.
...
llvm-svn: 122054
2010-12-17 10:48:14 +00:00
Chris Lattner
e92f8121d4
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.
llvm-svn: 122045
2010-12-17 06:20:15 +00:00
Chris Lattner
1499119975
make qsort predicate more conformant by returning 0 for equal values.
...
llvm-svn: 121838
2010-12-15 04:52:41 +00:00
Chris Lattner
c1aaf52608
- 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.
llvm-svn: 121764
2010-12-14 08:46:09 +00:00
Chris Lattner
22d4dc5a4d
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.
llvm-svn: 121762
2010-12-14 08:01:53 +00:00
Chris Lattner
362f9a82c0
remove the instsimplify logic I added in r121754. It is apparently
...
breaking the selfhost builds, though I can't fathom how.
llvm-svn: 121761
2010-12-14 07:53:03 +00:00
Chris Lattner
c2e42269ae
clean up logic, convert std::set to SmallPtrSet, handle the case
...
when all 2-entry phis are simplified away.
llvm-svn: 121760
2010-12-14 07:41:39 +00:00
Chris Lattner
8e4194276b
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.
llvm-svn: 121758
2010-12-14 07:23:10 +00:00
Chris Lattner
811462b2f4
use SimplifyInstruction instead of reimplementing part of it.
...
llvm-svn: 121757
2010-12-14 07:20:29 +00:00
Chris Lattner
e2400eb801
simplify GetIfCondition by using getSinglePredecessor.
...
llvm-svn: 121756
2010-12-14 07:15:21 +00:00
Chris Lattner
8ea88e66dd
use AddPredecessorToBlock in 3 places instead of a manual loop.
...
llvm-svn: 121755
2010-12-14 07:09:42 +00:00
Chris Lattner
a87ac36a54
make FoldTwoEntryPHINode use instsimplify a bit, make
...
GetIfCondition faster by avoiding pred_iterator. No
really interesting change.
llvm-svn: 121754
2010-12-14 07:00:00 +00:00
Chris Lattner
027d572664
remove the dead (and terrible) llvm::RemoveSuccessor function.
...
llvm-svn: 121753
2010-12-14 06:51:55 +00:00
Chris Lattner
d9436ab7d7
improve DEBUG's a bit, switch to eraseFromParent() to simplify
...
code a bit, switch from constant folding to instsimplify.
llvm-svn: 121751
2010-12-14 06:17:25 +00:00
Chris Lattner
093b5b256d
reapply my recent change that disables a piece of the switch formation
...
work, but fixes 400.perlbmk.
llvm-svn: 121749
2010-12-14 05:57:30 +00:00
Owen Anderson
5536134dc4
Fix recent buildbot breakage by pulling SimplifyCFG back to its state as of r121694, the most recent state
...
where I'm confident there were no crashes or miscompilations. XFAIL the test added since then for now.
llvm-svn: 121733
2010-12-13 23:49:28 +00:00
Chris Lattner
dcba81d96f
temporarily disable part of my previous patch, which causes an iterator invalidation issue, causing a crash on some versions of perlbmk.
...
llvm-svn: 121728
2010-12-13 23:02:19 +00:00
Chris Lattner
759d8aa712
add some DEBUG's.
...
llvm-svn: 121711
2010-12-13 19:55:30 +00:00
Benjamin Kramer
7f1cdac1e4
Fix sort predicate. qsort(3)'s predicate semantics differ from std::sort's. Fixes PR 8780.
...
llvm-svn: 121705
2010-12-13 18:20:38 +00:00
Chris Lattner
0368bf7457
reinstate my patch: the miscompile was caused by an inverted branch in the
...
'and' case.
llvm-svn: 121695
2010-12-13 08:12:19 +00:00
Chris Lattner
caad324345
Completely disable the optimization I added in r121680 until
...
I can track down a miscompile. This should bring the buildbots
back to life
llvm-svn: 121693
2010-12-13 07:41:29 +00:00
Chris Lattner
5ce3e42d80
Make simplifycfg reprocess newly formed "br (cond1 | cond2)" conditions
...
when simplifying, allowing them to be eagerly turned into switches. This
is the last step required to get "Example 7" from this blog post:
http://blog.regehr.org/archives/320
On X86, we now generate this machine code, which (to my eye) seems better
than the ICC generated code:
_crud: ## @crud
## BB#0: ## %entry
cmpb $33, %dil
jb LBB0_4
## BB#1: ## %switch.early.test
addb $-34, %dil
cmpb $58, %dil
ja LBB0_3
## BB#2: ## %switch.early.test
movzbl %dil, %eax
movabsq $288230376537592865, %rcx ## imm = 0x400000017001421
btq %rax, %rcx
jb LBB0_4
LBB0_3: ## %lor.rhs
xorl %eax, %eax
ret
LBB0_4: ## %lor.end
movl $1, %eax
ret
llvm-svn: 121690
2010-12-13 07:00:06 +00:00
Chris Lattner
20b9e84c7e
make this logic a bit simpler.
...
llvm-svn: 121689
2010-12-13 06:36:51 +00:00
Chris Lattner
74d917e19d
split all the guts of SimplifyCFGOpt::run out into one function
...
per terminator kind.
llvm-svn: 121688
2010-12-13 06:25:44 +00:00
Chris Lattner
ea15ce73be
fix a bug in r121680 that upset the various buildbots.
...
llvm-svn: 121687
2010-12-13 05:34:18 +00:00
Chris Lattner
1eb2e235c8
refactor the speculative execution logic to be factored into the cond branch code instead of
...
doing a cfg search for every block simplified.
llvm-svn: 121686
2010-12-13 05:26:52 +00:00
Chris Lattner
4b9e3a31b0
simplify a bunch of code.
...
llvm-svn: 121685
2010-12-13 05:20:28 +00:00
Chris Lattner
d79dd057bf
move HoistThenElseCodeToIf up to a more logical and efficient-to-handle place.
...
llvm-svn: 121684
2010-12-13 05:15:29 +00:00
Chris Lattner
80f8577d74
move 'MergeBlocksIntoPredecessor' call earlier. Use
...
getSinglePredecessor to simplify code.
llvm-svn: 121683
2010-12-13 05:10:48 +00:00
Chris Lattner
7ad8e06c3b
factor new code out to a SimplifyBranchOnICmpChain helper function.
...
llvm-svn: 121681
2010-12-13 05:03:41 +00:00
Chris Lattner
5cbbcc56ad
enhance the "change or icmp's into switch" xform to handle one value in an
...
'or sequence' that it doesn't understand. This allows us to optimize
something insane like this:
int crud (unsigned char c, unsigned x)
{
if(((((((((( (int) c <= 32 ||
(int) c == 46) || (int) c == 44)
|| (int) c == 58) || (int) c == 59) || (int) c == 60)
|| (int) c == 62) || (int) c == 34) || (int) c == 92)
|| (int) c == 39) != 0)
foo();
}
into:
define i32 @crud(i8 zeroext %c, i32 %x) nounwind ssp noredzone {
entry:
%cmp = icmp ult i8 %c, 33
br i1 %cmp, label %if.then, label %switch.early.test
switch.early.test: ; preds = %entry
switch i8 %c, label %if.end [
i8 39, label %if.then
i8 44, label %if.then
i8 58, label %if.then
i8 59, label %if.then
i8 60, label %if.then
i8 62, label %if.then
i8 46, label %if.then
i8 92, label %if.then
i8 34, label %if.then
]
by pulling the < comparison out ahead of the newly formed switch.
llvm-svn: 121680
2010-12-13 04:50:38 +00:00
Chris Lattner
f6be61e969
merge two very similar functions into one that has a bool argument.
...
llvm-svn: 121678
2010-12-13 04:26:26 +00:00