Commit Graph

8167 Commits

Author SHA1 Message Date
Eli Friedman
e6f364b6c4 More instcombine cleanup, towards improving debug line info.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131604 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 23:58:37 +00:00
Devang Patel
02dd5418d2 Use IRBuilder while simplifying branch.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131598 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 23:18:47 +00:00
Eli Friedman
107ffd58f7 More instcombine simplifications towards better debug locations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131596 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 23:11:30 +00:00
Devang Patel
176ec40cb1 Use IRBuilder while simplifying return instruction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131580 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 21:33:11 +00:00
Dan Gohman
673968ae78 When forming an ICmpZero LSRUse, normalize the non-IV operand
of the comparison, so that the resulting expression is fully
normalized. This fixes PR9939.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131576 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 21:02:18 +00:00
Devang Patel
b55d924b1e Spread use of IRBuilder even more.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131571 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 20:53:17 +00:00
Devang Patel
007349dafd Use IRBuilder while simplifying switch instruction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131566 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 20:35:38 +00:00
Devang Patel
d46ba26a6b Use IRBuilder while simplifying unwind.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131561 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 20:01:18 +00:00
Eli Friedman
59f15918c2 More instcombine cleanup aimed towards improving debug line info.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131559 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 19:57:14 +00:00
Devang Patel
d3372b85e6 Use IRBuilder while simplifying terminator.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131552 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 18:43:31 +00:00
Devang Patel
a23812cfbd Use IRBuilder while simplifying unconditional branch.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131551 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 18:28:48 +00:00
Devang Patel
f60364de44 Use IRBuilder while folding two entry PHINode.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131548 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 18:16:44 +00:00
Eli Friedman
976e7e1cc8 Switch more inst insertion in instcombine to IRBuilder.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131547 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 18:10:28 +00:00
Devang Patel
3e410c6607 Set up IRBuilder for use during simplification.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131545 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 18:01:27 +00:00
Eli Friedman
1eca76a611 Switch more inst insertion in instcombine to IRBuilder.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131544 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 17:58:37 +00:00
Matt Beaumont-Gay
f88ad9aeee fix typo
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131543 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 17:37:10 +00:00
Eli Friedman
e87ca454ba Switch inst insertion in instcombine transform to IRBuilder.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131542 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 17:31:55 +00:00
Devang Patel
62fb3556ea Use IRBuiler while constant folding terminator.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131541 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 17:26:46 +00:00
Stuart Hastings
d116611e0a Fix inelegant initialization.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131538 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 15:54:26 +00:00
Duncan Sands
d6dde76090 Revert commit 131534 since it seems to have broken several buildbots.
Original log entry:
Refactor getActionType and getTypeToTransformTo ; place all of the 'decision'
code in one place.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131536 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 14:57:56 +00:00
Nadav Rotem
fe3f5d7538 Refactor getActionType and getTypeToTransformTo ; place all of the 'decision'
code in one place.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131534 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 12:26:38 +00:00
Eli Friedman
ef819d0ed8 Start trying to make InstCombine preserve more debug info. The idea here is to set the debug location on the IRBuilder, which will be then right location in most cases. This should magically give many transformations debug locations, and fixing places which are missing a debug location will usually just means changing the code creating it to use the IRBuilder.
As an example, the change to InstCombineCalls catches a common case where a call to a bitcast of a function is rewritten.

Chris, does this approach look reasonable?



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131516 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 01:28:27 +00:00
Eli Friedman
3e22cb9ec3 Use ReplaceInstUsesWith instead of replaceAllUsesWith where appropriate in instcombine.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131512 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-18 00:32:01 +00:00
Devang Patel
d80e8ed2fa Preseve line numbers while simplifying CFG.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131508 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-17 23:29:05 +00:00
Bill Wendling
f5c95b889f Conditionalize the format of the GCOV files by target type. Darwin uses the 4.2
format.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131503 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-17 23:05:13 +00:00
Stuart Hastings
ca1ef48585 X86 pmovsx/pmovzx ignore the upper half of their inputs.
rdar://problem/6945110


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131493 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-17 22:13:31 +00:00
Devang Patel
de98568bf8 Preserve line number information.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131482 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-17 20:00:02 +00:00
Devang Patel
d9b4996637 Set debug loc for new load instruction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131481 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-17 19:43:38 +00:00
Devang Patel
c9ea771cb8 Preserve line number information.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131480 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-17 19:43:06 +00:00
Devang Patel
a8992b3e72 There is no need to force DebugLoc on a PHI at this point.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131427 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-16 22:05:03 +00:00
Devang Patel
227dfdb3c4 Preserve debug info for unused zero extended boolean argument.
Radar 9422775.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131422 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-16 21:24:05 +00:00
Rafael Espindola
0e00c6c561 Don't do tail calls in a function that call setjmp. The stack might be
corrupted when setjmp returns again.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131399 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-16 03:05:33 +00:00
Benjamin Kramer
10fcfb53fd SimplifyCFG: Use ComputeMaskedBits to prune dead cases from switch instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131345 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-14 15:57:25 +00:00
Stuart Hastings
67f071e697 Avoid combining GEPs that might overflow at runtime.
rdar://problem/9267970

Patch by Julien Lerouge!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131339 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-14 05:55:10 +00:00
Julien Lerouge
eea6c95d5d Fix a source of non determinism in FindUsedTypes, use a SetVector instead of a
set.

rdar://9423996


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131283 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-13 05:20:42 +00:00
Andrew Trick
14ba1ff133 Convert SimplifyIVUsers into a worklist instead of a single pass over
the users.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131277 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-13 01:12:21 +00:00
Andrew Trick
aeee4616dd indvars: Added SimplifyIVUsers.
Interleave IV simplifications. Currently involves EliminateComparison
and EliminateRemainder. Next I'll add EliminateExtend.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131210 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-12 00:04:28 +00:00
Devang Patel
65a2f77b0e Preserve line number information.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131112 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-10 00:03:11 +00:00
Duncan Sands
5389210e63 Fix PR9820: a read-only call differs from a load in that a load doesn't
return the pointer being dereferenced, it returns the pointee, but a call
might return the pointer itself.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130979 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-06 10:30:37 +00:00
Nick Lewycky
d363ff334d The computation of string length is not that complicated. Fix it, again. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130967 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-05 23:52:18 +00:00
Eli Friedman
b6e7cd655c PR9838: Fix transform introduced in r127064 to not trigger when only one side of the icmp is an exact shift.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130954 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-05 21:59:18 +00:00
Nick Lewycky
5409a18832 Update the gcov version used slightly, to make it stop causing modern gcov's to
crash.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130911 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-05 02:46:38 +00:00
Nick Lewycky
7a75a9ade8 Remove dead function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130903 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-05 00:17:34 +00:00
Nick Lewycky
fcf74ed5a2 When the path wasn't emitted by the frontend, discard any path on the source
filename.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130897 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-05 00:03:30 +00:00
Devang Patel
0f18d97fd1 Set debug loc for new instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130895 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-04 23:58:50 +00:00
Devang Patel
a922ba7edc Set debug location for new PHI nodes created in exit block.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130894 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-04 23:58:22 +00:00
Devang Patel
95a7de6b91 Preserve line number information while threading jumps.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130880 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-04 22:48:19 +00:00
Devang Patel
b90584ae78 Preserve line number info.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130876 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-04 21:58:58 +00:00
Devang Patel
af35841f2e preserve line number info.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130869 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-04 21:37:05 +00:00
Nick Lewycky
269687fa35 Emit gcov data files to the directory specified in the metadata produced by the
frontend, if applicable.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130835 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-04 04:03:04 +00:00
Andrew Trick
37da408758 indvars: Added DisableIVRewrite and WidenIVs.
This adds functionality to remove size/zero extension during indvars
without generating a canonical IV and rewriting all IV users. It's
disabled by default so should have no effect on codegen. Work in progress.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-04 02:10:13 +00:00
Andrew Trick
4dfdf242c1 indvars: Added canExpandBackEdgeTakenCount.
Only create a canonical IV for backedge taken count if it will
actually be used by LinearFunctionTestReplace. And some related
cleanup, preparing to reduce dependence on canonical IVs.
No significant effect on x86 or arm in the test-suite.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130799 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-03 22:24:10 +00:00
Benjamin Kramer
d2189bf12a Remove unused variables caught by GCC's -Wunused-but-set-variable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130755 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-03 16:00:27 +00:00
Dan Gohman
cca82149ad Add an unfolded offset field to LSR's Formula record. This is used to
model constants which can be added to base registers via add-immediate
instructions which don't require an additional register to materialize
the immediate.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130743 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-03 00:46:49 +00:00
Devang Patel
67352b3ce7 Scanning entire basic block may be too expensive in terms of compile time. Instead, just use whatever location info first non-phi instruction has.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130729 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-02 21:57:00 +00:00
Duncan Sands
00676a6df1 Remove unused variable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130705 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-02 18:41:29 +00:00
Duncan Sands
f24ed77d24 Move some rem transforms out of instcombine and into instsimplify.
This automagically provides a transform noticed by my super-optimizer
as occurring quite often: "rem x, (select cond, x, 1)" -> 0.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130694 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-02 16:27:02 +00:00
Chris Lattner
149f5283f9 enhance memcpyopt to obey -fno-builtin and friends. This addresses a
problem reported on cfe-dev.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130661 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-01 18:27:11 +00:00
Benjamin Kramer
7d6eb5a018 InstCombine: Turn (zext A) udiv (zext B) into (zext (A udiv B)). Same for urem or constant B.
This obviously helps a lot if the division would be turned into a libcall
(think i64 udiv on i386), but div is also one of the few remaining instructions
on modern CPUs that become more expensive when the bitwidth gets bigger.

This also helps register pressure on i386 when dividing chars, divb needs
two 8-bit parts of a 16 bit register as input where divl uses two registers.

int foo(unsigned char a) { return a/10; }
int bar(unsigned char a, unsigned char b) { return a/b; }

compiles into (x86_64)
_foo:
  imull $205, %edi, %eax
  shrl  $11, %eax
  ret
_bar:
  movzbl        %dil, %eax
  divb  %sil, %al
  movzbl        %al, %eax
  ret

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130615 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-30 18:16:07 +00:00
Benjamin Kramer
23b02cd031 Use SimplifyDemandedBits on div instructions.
This folds away silly stuff like (a&255)/1000 -> 0.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130614 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-30 18:16:00 +00:00
Devang Patel
40348e8d1f Assing line number info to new PHIs created by SSA updater.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130551 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-29 22:28:59 +00:00
Devang Patel
bd5426a4f2 Preserve line number information.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130536 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-29 20:38:55 +00:00
Peter Collingbourne
57808b3da0 SimplifyCFG: Expose phi node folding cost threshold as command line parameter
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130528 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-29 18:47:38 +00:00
Peter Collingbourne
f15907fead SimplifyCFG: Add CostRemaining parameter to DominatesMergePoint
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130527 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-29 18:47:31 +00:00
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
Benjamin Kramer
3224806109 Balance parentheses.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130489 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-29 08:41:23 +00:00
Benjamin Kramer
c2e31c1461 InstCombine: turn (C1 << A) << C2) into (C1 << C2) << A)
Fixes PR9809.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130485 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-29 08:15:41 +00:00
Devang Patel
5367b23f76 Preserve line number information.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130450 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 22:48:14 +00:00
Benjamin Kramer
b0884f3f13 We require threse bits to be zero, too.
This shouldn't happen in practice because the icmp would be a constant.
Add a check so we don't miscompile code if something goes wrong.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130446 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 21:38:51 +00:00
Nick Lewycky
7a2ba2fbe4 Only read *predecessor once so as to fix a theoretical issue where it changes
between two reads (threading).

Fix an off-by-one in the indirect counter table that I meant to revert after an
earlier experiment. Whoops!

Implement GCOV_PREFIX. Doesn't handle GCOV_PREFIX_STRIP yet.

Fix an off-by-one in string emission. Extra whoops!

Tolerate DISubprograms that have null Function*'s attached to them. I don't yet
understand what this means, but it happens when you have a global static with
a non-trivial constructor/destructor.

Fix a crash on switch statements with a single successor (default-only).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130443 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 21:35:49 +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
Benjamin Kramer
e12d583621 Fix a comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130428 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 20:09:57 +00:00
Chris Lattner
1e4f44bb8a improve comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130426 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 20:02:57 +00:00
Devang Patel
81199d2545 Do not lose line number info while eliminating tail call.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130419 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 18:43:39 +00:00
Chris Lattner
0a9e3d613b final step needed to resolve PR6627, which allows us to flatten the code down to
a nice and tidy:
  %x1 = load i32* %0, align 4
  %1 = icmp eq i32 %x1, 1179403647
  br i1 %1, label %if.then, label %if.end

instead of doing lots of loads and branches.  May the FreeBSD bootloader
long fit in its allocated space.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130416 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 18:15:47 +00:00
Chris Lattner
ad3ba6a7de code cleanups only.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130414 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 18:08:21 +00:00
Andrew Trick
88e92cf16b Reapply r130340: Fix for PR9730.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130408 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 17:30:04 +00:00
Benjamin Kramer
264ac878b2 InstCombine: Merge "(trunc x) == C1 & (and x, CA) == C2" into a single and+icmp.
This happens when GVN widens loads. Part of PR6627.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130405 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 16:58:40 +00:00
Chris Lattner
4756ecb375 centralize "marking for deletion" into a helper function. Pass GVN around to
static functions instead of passing around tons of random ivars.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130403 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 16:36:48 +00:00
Chris Lattner
f07054d98a Promote toErase to be an ivar of the GVN class.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130401 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 16:18:52 +00:00
Chris Lattner
4034e14985 teach GVN to widen integer loads when they are overaligned, when doing an
wider load would allow elimination of subsequent loads, and when the wider
load is still a native integer type.  This eliminates a ton of loads on 
various benchmarks involving struct fields, though it is somewhat hobbled
by clang not being very aggressive about field alignment.

This is yet another step along the way towards resolving PR6627.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130390 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 07:29:08 +00:00
Andrew Trick
a7707ae19a Reverting r130340 in the unlikely event that it's responsible for a llvm-gcc stage2 compiler error.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130350 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-28 00:13:59 +00:00
Andrew Trick
685f07fac2 Fixes PR9730: indvars: An asserting value handle still pointed to this value
Modified LinearFunctionTestReplace to push the condition on the dead
list instead of eagerly deleting it. This can cause unnecessary
IV rewrites, which should have no effect on codegen and will not be an
issue once we stop generating canonical IVs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130340 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-27 23:00:03 +00:00
Devang Patel
7878f37cf0 Simplify cfg inserts a call to trap when unreachable code is detected. Assign DebugLoc to this new trap instruction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130315 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-27 17:59:27 +00:00
Duncan Sands
089a246333 Stop trying to have instcombine preserve LCSSA form: this was not
effective in avoiding recomputation of LCSSA form; the widespread
use of instsimplify (which looks through phi nodes) means it was
not preserving LCSSA form anyway; and instcombine is no longer
scheduled in the middle of the loop passes so this doesn't matter
anymore.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130301 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-27 10:55:12 +00:00
Chris Lattner
325eeb1cd7 Transform: "icmp eq (trunc (lshr(X, cst1)), cst" to "icmp (and X, mask), cst"
when X has multiple uses.  This is useful for exposing secondary optimizations,
but the X86 backend isn't ready for this when X has a single use.  For example,
this can disable load folding.

This is inching towards resolving PR6627.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130238 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-26 20:18:20 +00:00
Chris Lattner
5036ce4a64 some random cleanups, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130237 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-26 20:02:45 +00:00
Chris Lattner
9750acc079 Improve the bail-out predicate to really only kick in when phi
translation fails.  We were bailing out in some cases that would
cause us to miss GVN'ing some non-local cases away.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130206 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-26 17:41:02 +00:00
Nick Lewycky
1790c9cbb6 Rename everything to follow LLVM style ... I think.
Add support for switch and indirectbr edges. This works by densely numbering
all blocks which have such terminators, and then separately numbering the
possible successors. The predecessors write down a number, the successor knows
its own number (as a ConstantInt) and sends that and the pointer to the number
the predecessor wrote down to the runtime, who looks up the counter in a
per-function table.

Coverage data should now be functional, but I haven't tested it on anything
other than my 2-file synthetic test program for coverage.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130186 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-26 03:54:16 +00:00
Chris Lattner
1f821512fc Enhance MemDep: When alias analysis returns a partial alias result,
return it as a clobber.  This allows GVN to do smart things.

Enhance GVN to be smart about the case when a small load is clobbered
by a larger overlapping load.  In this case, forward the value.  This
allows us to compile stuff like this:

int test(void *P) {
  int tmp = *(unsigned int*)P;
  return tmp+*((unsigned char*)P+1);
}

into:

_test:                                  ## @test
	movl	(%rdi), %ecx
	movzbl	%ch, %eax
	addl	%ecx, %eax
	ret

which has one load.  We already handled the case where the smaller
load was from a must-aliased base pointer.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130180 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-26 01:21:15 +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
Nick Lewycky
a4c4c0e129 In gcov profiling, give all functions an extra unified return block. This is
necessary since gcov counts transitions between blocks. It can't see if you've
run every line in a straight-line function, so we add an edge for it to notice.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129905 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-21 03:18:00 +00:00
Nick Lewycky
17df2c3240 Fix think-o: emit all 8 bytes of the EOF marker. Also reflow a line in a
comment for 80 columns.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129904 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-21 02:48:39 +00:00
Nick Lewycky
a61e52c9b7 Add independent controls for whether GCOV profiling should emit .gcno files or
instrument the program to emit .gcda.
TODO: we should emit slightly different .gcda files when .gcno emission is off.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129903 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-21 01:56:25 +00:00
Cameron Zwarich
344731c018 Fix another case of <rdar://problem/9184212> that only occurs with code
generated by llvm-gcc, since llvm-gcc uses 2 i64s for passing a 4 x float
vector on ARM rather than an i64 array like Clang.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129878 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-20 21:48:38 +00:00
Cameron Zwarich
c5c43b958c The bitcast case here is actually handled uniformly earlier in the function, so
delete it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129877 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-20 21:48:34 +00:00
Cameron Zwarich
5fc1282c18 Cleanup some code to better use an early return style in preparation for adding
more cases.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129876 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-20 21:48:16 +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
Chandler Carruth
3b55a372d4 Mark some functions as used which are used within debug-only code. This
silences Clang's -Wunused-function when building in release mode.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129709 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-18 18:49:44 +00:00
Frits van Bommel
86f72a8002 Rename a misleadingly-named variable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129644 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-16 14:32:34 +00:00
Jay Foad
4130278fbe Fix bug when checking phi operands in InstCombiner::visitPHINode(),
found by code inspection.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129641 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-16 14:17:37 +00:00
Rafael Espindola
86837e8745 Fix cmake build.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129632 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-16 02:06:46 +00:00
Nick Lewycky
0c4de8a4eb Move the re-stemming function up top and use it where it's currently inlined.
Break the arc-profile code out to a function like the notes emission code is,
and reorder the functions in the file.

The only functionality change is that we no longer modify the Module when the
Module has no debug info to use.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129631 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-16 02:05:18 +00:00
Nick Lewycky
b192870420 Rename LineProfiling to GCOVProfiling to more accurately represent what it
does. Also mostly implement it. Still a work-in-progress, but generates legal
output on crafted test cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129630 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-16 01:20:23 +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
Eli Friedman
3ec01b7dac Add an instcombine for constructs like a | -(b != c); a select is more
canonical, and generally leads to better code.  Found while looking at
an article about saturating arithmetic.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129545 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-14 22:41:27 +00:00
Owen Anderson
f6832bbda0 Fix an infinite alternation in JumpThreading where two transforms would repeatedly undo each other. The solution is to perform more aggressive constant folding to make one of the edges just folded away rather than trying to thread it.
Fixes <rdar://problem/9284786>.

Discovered with CSmith.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129538 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-14 21:35:50 +00:00
Mon P Wang
481823aa81 Cleanup r129509 based on comments by Chris
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129532 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-14 19:20:42 +00:00
Mon P Wang
ddf9abf2b6 Cleanup r129472 by using a utility routine as suggested by Eli.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129509 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-14 08:04:01 +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
b3b15711b9 fix a couple -Wsign-compare warnings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129501 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-14 02:27:25 +00:00
Mon P Wang
be0761c820 Vectors with different number of elements of the same element type can have
the same allocation size but different primitive sizes(e.g., <3xi32> and
<4xi32>).  When ScalarRepl promotes them, it can't use a bit cast but
should use a shuffle vector instead.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129472 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-13 21:40:02 +00:00
Junjie Gu
7133b85b87 Fixed the revision 129449.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129450 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-13 16:45:49 +00:00
Junjie Gu
32644d9bfd Passing unroll parameters (unroll-count, threshold, and partial unroll) via LoopUnroll class's ctor. Doing so
will allow multiple context with different loop unroll parameters to run.  This is a minor change and no effect 
on existing application.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129449 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-13 16:15:29 +00:00
Rafael Espindola
0d9874b48d Add the alias analysis to the C api.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129447 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-13 15:44:58 +00:00
Bill Wendling
f93f7b2446 Reapply r129401 with patch for clang.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129419 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-13 00:36:11 +00:00
Bill Wendling
f9b2dc66c8 Revert r129401 for now. Clang is using the old way of doing things.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129403 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-12 22:59:27 +00:00
Bill Wendling
d5f323d70b Remove the unaligned load intrinsics in favor of using native unaligned loads.
Now that we have a first-class way to represent unaligned loads, the unaligned
load intrinsics are superfluous.

First part of <rdar://problem/8460511>.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129401 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-12 22:46:31 +00:00
NAKAMURA Takumi
39df9b5920 lib/Transforms/Instrumentation/CMakeLists.txt: Add LineProfiling.cpp to fix up r129340.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129343 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-12 01:54:40 +00:00
Nick Lewycky
93b68b20d4 Add support for line profiling. Very work-in-progress.
Use debug info in the IR to find the directory/file:line:col. Each time that location changes, bump a counter.

Unlike the existing profiling system, we don't try to look at argv[], and thusly don't require main() to be present in the IR. This matches GCC's technique where you specify the profiling flag when producing each .o file.

The runtime library is minimal, currently just calling printf at program shutdown time. The API is designed to make it possible to emit GCOV data later on.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129340 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-12 01:06:09 +00:00
Nick Lewycky
ceb465a8a4 Consider ConstantAggregateZero as well as ConstantArray/Struct.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129338 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-12 01:02:45 +00:00
Dan Gohman
dac5dbadeb Fix reassociate to use a worklist instead of recursing when new
reassociation opportunities are exposed. This fixes a bug where
the nested reassociation expects to be the IR to be consistent,
but it isn't, because the outer reassociation has disconnected
some of the operands.  rdar://9167457


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129324 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-12 00:11:56 +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
Chris Lattner
b5f18f5df0 remove the StructRetPromotion pass. It is unused, not maintained and
has some bugs.  If this is interesting functionality, it should be 
reimplemented in the argpromotion pass.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129314 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-11 23:09:44 +00:00
Nick Lewycky
5ea5c61589 Just because a GlobalVariable's initializer is [N x { i32, void ()* }] doesn't
mean that it has to be ConstantArray of ConstantStruct. We might have
ConstantAggregateZero, at either level, so don't crash on that.

Also, semi-deprecate the sentinal value. The linker isn't aware of sentinals so
we end up with the two lists appended, each with their "sentinals" on them.
Different parts of LLVM treated sentinals differently, so make them all just
ignore the single entry and continue on with the rest of the list.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129307 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-11 22:11:20 +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
Eli Friedman
18a2e50a9b Add back a couple checks removed by r129128; the fact that an intitializer
is an array of structures doesn't imply it's a ConstantArray of
ConstantStruct.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129207 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-09 09:11:09 +00:00
Chris Lattner
f5bf464b70 fix PR9523, a crash in looprotate on a non-canonical loop made out of indirectbr.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129203 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-09 07:25:58 +00:00
Chris Lattner
0403b473dd Fix a bug where RecursivelyDeleteTriviallyDeadInstructions could
delete the instruction pointed to by CGP's current instruction
iterator, leading to a crash on the testcase.  This fixes PR9578.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129200 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-09 07:05:44 +00:00
Nick Lewycky
918035f802 Add a function for profiling to run at shutdown. Unlike the existing API, this
can be used even when main() isn't present in the Module, but it means that you
don't get to read argv[].


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129163 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-08 22:19:52 +00:00
Nick Lewycky
2c44a80d99 llvm.global_[cd]tor is defined to be either external, or appending with an array
of { i32, void ()* }. Teach the verifier to verify that, deleting copies of
checks strewn about.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129128 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-08 07:30:21 +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
Rafael Espindola
45e1a53efd Expose more passes to the C API.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129087 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-07 18:20:46 +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
Eli Friedman
0e382192c1 PR9634: Don't unconditionally tell the AliasSetTracker that the PreheaderLoad
is equivalent to any other relevant value; it isn't true in general.
If it is equivalent, the LoopPromoter will tell the AST the equivalence.
Also, delete the PreheaderLoad if it is unused.

Chris, since you were the last one to make major changes here, can you check
that this is sane?



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129049 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-07 01:35:06 +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
Nick Lewycky
06d2b4223f Fix typos. Adjust some whitespace for style. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128924 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-05 20:39:27 +00:00
Nadav Rotem
0286ca89f0 InstCombine optimizes gep(bitcast(x)) even when the bitcasts casts away address
space info. We crash with an assert in this case. This change checks that the
address space of the bitcasted pointer is the same as the gep ptr.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128884 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-05 14:29:52 +00:00
Jay Foad
3e2f74e6d6 Remove some support for ReturnInsts with multiple operands, and for
returning a scalar value in a function whose return type is a single-
element structure or array.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128810 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-04 07:44:02 +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
Benjamin Kramer
f5b75932b8 While SimplifyDemandedBits constant folds this, we can't rely on it here.
It's possible to craft an input that hits the recursion limits in a way
that SimplifyDemandedBits doesn't simplify the icmp but ComputeMaskedBits
can infer which bits are zero.

No test case as it depends on too many other things. Fixes PR9609.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128777 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-02 18:50:58 +00:00
Benjamin Kramer
406a650237 Fix comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128745 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-01 22:29:18 +00:00
Benjamin Kramer
5337fabdc4 Tweaks to the icmp+sext-to-shifts optimization to address Frits' comments:
- Localize the check if an icmp has one use to a place where we know we're
  introducing something that's likely more expensive than a sext from i1.
- Add an assert to make sure a case that would lead to a miscompilation is
  folded away earlier.
- Fix a typo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128744 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-01 22:22:11 +00:00
Benjamin Kramer
ce1498bdbe Fix build.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128733 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-01 20:15:16 +00:00
Benjamin Kramer
0baa94a13b InstCombine: Turn icmp + sext into bitwise/integer ops when the input has only one unknown bit.
int test1(unsigned x) { return (x&8) ? 0 : -1; }
int test3(unsigned x) { return (x&8) ? -1 : 0; }

before (x86_64):
_test1:
	andl	$8, %edi
	cmpl	$1, %edi
	sbbl	%eax, %eax
	ret
_test3:
	andl	$8, %edi
	cmpl	$1, %edi
	sbbl	%eax, %eax
	notl	%eax
	ret

after:
_test1:
	shrl	$3, %edi
	andl	$1, %edi
	leal	-1(%rdi), %eax
	ret
_test3:
	shll	$28, %edi
	movl	%edi, %eax
	sarl	$31, %eax
	ret

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128732 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-01 20:09:10 +00:00
Benjamin Kramer
0a30c42008 InstCombine: Move (sext icmp) transforms into their own method. No intended functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128731 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-01 20:09:03 +00:00
Nadav Rotem
0ff8a4fa35 Instcombile optimization: extractelement(cast) -> cast(extractelement)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128683 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-31 22:57:29 +00:00
Benjamin Kramer
7ebdc37d2b InstCombine: APFloat can't perform arithmetic on PPC double doubles, don't even try.
Thanks Eli!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128676 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-31 21:35:49 +00:00
Benjamin Kramer
00e00d693c InstCombine: Fix transform to use the swapped predicate.
Thanks Frits!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128628 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-31 10:46:03 +00:00
Benjamin Kramer
68b4bd0a63 InstCombine: fold fcmp (fneg x), (fneg y) -> fcmp x, y
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128627 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-31 10:12:22 +00:00
Benjamin Kramer
0db50189dc InstCombine: fold fcmp pred (fneg x), C -> fcmp swap(pred) x, -C
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128626 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-31 10:12:15 +00:00
Benjamin Kramer
b194bdc03b InstCombine: Shrink "fcmp (fpext x), C" to "fcmp x, C" if C can be losslessly converted to the type of x.
Fixes PR9592.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128625 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-31 10:12:07 +00:00
Benjamin Kramer
cd0274ca18 InstCombine: fold fcmp (fpext x), (fpext y) -> fcmp x, y.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128624 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-31 10:11:58 +00:00
Bill Wendling
31d244ead5 * The DSE code that tested for overlapping needed to take into account the fact
that one of the numbers is signed while the other is unsigned. This could lead
  to a wrong result when the signed was promoted to an unsigned int.

* Add the data layout line to the testcase so that it will test the appropriate
  thing.

Patch by David Terei!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128577 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-30 21:37:19 +00:00
Benjamin Kramer
546739656e InstCombine: If the divisor of an fdiv has an exact inverse, turn it into an fmul.
Fixes PR9587.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128546 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-30 15:42:35 +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
Benjamin Kramer
9822b869fc InstCombine: Add a few missing combines for ANDs and ORs of sign bit tests.
On x86 we now compile "if (a < 0 && b < 0)" into
	testl	%edi, %esi
	js	IF.THEN

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128496 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-29 22:06:41 +00:00
Benjamin Kramer
ec3f227820 DSE: Remove an early exit optimization that depended on the ordering of a SmallPtrSet.
Fixes PR9569 and will hopefully make selfhost on ASLR-enabled systems more deterministic.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128482 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-29 20:28:57 +00:00
Cameron Zwarich
9827b78b51 Do some simple copy propagation through integer loads and stores when promoting
vector types. This helps a lot with inlined functions when using the ARM soft
float ABI. Fixes <rdar://problem/9184212>.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128453 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-29 05:19:52 +00:00
Nick Lewycky
2bf026e375 Remove tabs I accidentally added.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128413 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-28 17:48:26 +00:00
Jay Foad
fd4a5497b6 Make more use of PHINode::getNumIncomingValues().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128406 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-28 13:03:10 +00:00
Frits van Bommel
f56762a96d Add some debug output when -instcombine uses RAUW. This can make debug output for those cases much clearer since without this it only showed that the original instruction was removed, not what it was replaced with.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128399 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-27 23:32:31 +00:00
Nick Lewycky
675619ca38 Teach the transformation that moves binary operators around selects to preserve
the subclass optional data.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128388 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-27 19:51:23 +00:00
Benjamin Kramer
d655e6e9dc Use APInt's umul_ov instead of rolling our own overflow detection.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128380 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-27 15:04:38 +00:00
Nick Lewycky
98cd75027c Add a small missed optimization: turn X == C ? X : Y into X == C ? C : Y. This
removes one use of X which helps it pass the many hasOneUse() checks.

In my analysis, this turns up very often where X = A >>exact B and that can't be
simplified unless X has one use (except by increasing the lifetime of A which is
generally a performance loss).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128373 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-27 07:30:57 +00:00
Bill Wendling
1a4d58af09 Simplification noticed by Frits.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128333 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-26 09:32:07 +00:00
Bill Wendling
150c4a1a89 Rework the logic that determines if a store completely overlaps an ealier store.
There are two ways that a later store can comletely overlap a previous store:

1. They both start at the same offset, but the earlier store's size is <= the
   later's size, or
2. The earlier store's offset is > the later's offset, but it's offset + size
   doesn't extend past the later's offset + size.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128332 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-26 08:02:59 +00:00
Cameron Zwarich
c77a10fe0a Fix a typo and add a test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128331 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-26 04:58:50 +00:00
Bill Wendling
e420449e80 PR9561: A store with a negative offset (via GEP) could erroniously say that it
completely overlaps a previous store, thus mistakenly deleting that store. Check
for this condition.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128319 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-26 01:20:37 +00:00
Nick Lewycky
628b337561 No functionality change, just adjust some whitespace for coding style compliance.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128257 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-25 06:05:50 +00:00
Cameron Zwarich
9035484200 Debug intrinsics must be skipped at the beginning and ends of blocks, lest they
affect the generated code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128217 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-24 16:34:59 +00:00
Cameron Zwarich
dc31cfeb74 It is enough for the CallInst to have no uses to be made a tail call with a ret
void; it doesn't need to have a void type.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128212 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-24 15:54:11 +00:00
Devang Patel
52e37df8c0 s/UpdateDT/ModifiedDT/g
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128211 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-24 15:35:25 +00:00
Cameron Zwarich
6e8ffc1c4d Do early taildup of ret in CodeGenPrepare for potential tail calls that have a
void return type. This fixes PR9487.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128197 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-24 04:52:10 +00:00
Cameron Zwarich
4bae588c75 Use an early return instead of a long if block.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128196 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-24 04:52:07 +00:00
Cameron Zwarich
680c962ebd When UpdateDT is set, DT is invalid, which could cause problems when trying to
use it later. I couldn't make a test that hits this with the current code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128195 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-24 04:52:04 +00:00
Cameron Zwarich
661a390b83 Check for TLI so that -codegenprepare can be used from opt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128194 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-24 04:51:51 +00:00
Cameron Zwarich
1537ce75ed Fix PR9464 by correcting some math that just happened to be right in most cases
that were hit in practice.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128146 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-23 05:25:55 +00:00
Anders Carlsson
807bc2a381 Handle another case that Frits suggested.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128068 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-22 03:21:01 +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
Anders Carlsson
b12caf31f4 More cleanups to the OptimizeEmptyGlobalCXXDtors GlobalOpt function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127997 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-21 14:54:40 +00:00
Anders Carlsson
262a862787 As suggested by Nick Lewycky, ignore debugging intrinsics when trying to decide whether a destructor is empty or not.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127985 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-21 02:42:27 +00:00
Nick Lewycky
35ee1c921c Fix comments
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127984 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-21 02:26:01 +00:00
Evan Cheng
485fafc840 Re-apply r127953 with fixes: eliminate empty return block if it has no predecessors; update dominator tree if cfg is modified.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127981 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-21 01:19:09 +00:00
Anders Carlsson
4f735ca185 Don't try to eliminate invokes to __cxa_atexit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127976 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-20 20:21:33 +00:00
Anders Carlsson
372ec6aa91 Don't segfault on mutual recursion, as pointed out by Frits.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127975 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-20 20:16:43 +00:00
Anders Carlsson
1f7c7ba380 Address comments from Frits van Bommel.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127974 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-20 19:51:13 +00:00
Anders Carlsson
a201c4c2e6 Add an optimization to GlobalOpt that eliminates calls to __cxa_atexit, if the function passed is empty.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127970 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-20 17:59:11 +00:00
Daniel Dunbar
7a90e04fc7 Revert r127953, "SimplifyCFG has stopped duplicating returns into predecessors
to canonicalize IR", it broke a lot of things.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127954 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-19 21:47:14 +00:00
Evan Cheng
ae16d6b972 SimplifyCFG has stopped duplicating returns into predecessors to canonicalize IR
to have single return block (at least getting there) for optimizations. This
is general goodness but it would prevent some tailcall optimizations.
One specific case is code like this:
int f1(void);
int f2(void);
int f3(void);
int f4(void);
int f5(void);
int f6(void);
int foo(int x) {
  switch(x) {
  case 1: return f1();
  case 2: return f2();
  case 3: return f3();
  case 4: return f4();
  case 5: return f5();
  case 6: return f6();
  }
}

=>
LBB0_2:                                 ## %sw.bb
  callq   _f1
  popq    %rbp
  ret
LBB0_3:                                 ## %sw.bb1
  callq   _f2
  popq    %rbp
  ret
LBB0_4:                                 ## %sw.bb3
  callq   _f3
  popq    %rbp
  ret

This patch teaches codegenprep to duplicate returns when the return value
is a phi and where the phi operands are produced by tail calls followed by
an unconditional branch:

sw.bb7:                                           ; preds = %entry
  %call8 = tail call i32 @f5() nounwind
  br label %return
sw.bb9:                                           ; preds = %entry
  %call10 = tail call i32 @f6() nounwind
  br label %return
return:
  %retval.0 = phi i32 [ %call10, %sw.bb9 ], [ %call8, %sw.bb7 ], ... [ 0, %entry ]
  ret i32 %retval.0

This allows codegen to generate better code like this:

LBB0_2:                                 ## %sw.bb
        jmp     _f1                     ## TAILCALL
LBB0_3:                                 ## %sw.bb1
        jmp     _f2                     ## TAILCALL
LBB0_4:                                 ## %sw.bb3
        jmp     _f3                     ## TAILCALL

rdar://9147433


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127953 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-19 17:17:39 +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
Andrew Trick
f3e6774880 Remove TargetData and ValueTracking includes. I didn't mean for them to sneak in my last checkin.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127842 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-18 00:36:39 +00:00
Andrew Trick
b12a754cce Added isValidRewrite() to check the result of ScalarEvolutionExpander.
SCEV may generate expressions composed of multiple pointers, which can
lead to invalid GEP expansion. Until we can teach SCEV to follow strict
pointer rules, make sure no bad GEPs creep into IR.
Fixes rdar://problem/9038671.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127839 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-17 23:51:11 +00:00
Andrew Trick
ead71d59a7 whitespace
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127837 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-17 23:46:48 +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
1bcdb6ffad Fix a comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127728 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-16 08:13:42 +00:00
Cameron Zwarich
85b0f468cf Only convert allocas to scalars if it is profitable. The profitability metric I
chose is having a non-memcpy/memset use and being larger than any native integer
type. Originally I chose having an access of a size smaller than the total size
of the alloca, but this caused some minor issues on the spirit benchmark where
SRoA runs again after some inlining.

This fixes <rdar://problem/8613163>.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127718 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-16 00:13:44 +00:00
Cameron Zwarich
deac268f89 Better use initializer lists.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127716 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-16 00:13:37 +00:00
Cameron Zwarich
d4c9c3e6b9 Add a clarifying comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127715 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-16 00:13:35 +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
Eric Christopher
b9b80c3268 If we don't know how long a string is we can't fold an _chk version to the
normal version.

Fixes rdar://9123638


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127636 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-15 00:25:41 +00:00
Andrew Trick
3228cc259b Added SCEV::NoWrapFlags to manage unsigned, signed, and self wrap
properties.
Added the self-wrap flag for SCEV::AddRecExpr.
A slew of temporary FIXMEs indicate the intention of the no-self-wrap flag
without changing behavior in this revision.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127590 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-14 16:50:06 +00:00
Andrew Trick
d99b39e43b whitespace
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127589 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-14 16:48:10 +00:00
Jin-Gu Kang
948d9e7ec7 This case is solved by Scalar Replacement of Aggregates (DT) and
Early CSE pass so this patch reverts it to original source code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127574 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-14 01:21:00 +00:00
Jin-Gu Kang
198e97c423 Add comment as following:
load and store reference same memory location, the memory location
is represented by getelementptr with two uses (load and store) and
the getelementptr's base is alloca with single use. At this point,
instructions from alloca to store can be removed.
(this pattern is generated when bitfield is accessed.)
For example,
%u = alloca %struct.test, align 4               ; [#uses=1]
%0 = getelementptr inbounds %struct.test* %u, i32 0, i32 0;[#uses=2]
%1 = load i8* %0, align 4                       ; [#uses=1]
%2 = and i8 %1, -16                             ; [#uses=1]
%3 = or i8 %2, 5                                ; [#uses=1]
store i8 %3, i8* %0, align 4


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127565 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-13 14:05:51 +00:00
Jin-Gu Kang
c5c03f9024 This patch removes some of useless instructions generated by bitfield access.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127539 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-12 12:18:44 +00:00
Cameron Zwarich
899eaa3569 Roll r127459 back in:
Optimize trivial branches in CodeGenPrepare, which often get created from the
lowering of objectsize intrinsics. Unfortunately, a number of tests were relying
on llc not optimizing trivial branches, so I had to add an option to allow them
to continue to test what they originally tested.

This fixes <rdar://problem/8785296> and <rdar://problem/9112893>.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127498 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-11 21:52:04 +00:00
Daniel Dunbar
950d3db5f4 Revert r127459, "Optimize trivial branches in CodeGenPrepare, which often get
created from the", it broke some GCC test suite tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127477 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-11 19:30:30 +00:00
Benjamin Kramer
6b4972518c InstCombine: Fix a thinko where transform an icmp under the assumption that it's a zero comparison when it's not.
Fixes PR9454.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127464 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-11 11:37:40 +00:00
Cameron Zwarich
592ca3fda9 Optimize trivial branches in CodeGenPrepare, which often get created from the
lowering of objectsize intrinsics. Unfortunately, a number of tests were relying
on llc not optimizing trivial branches, so I had to add an option to allow them
to continue to test what they originally tested.

This fixes <rdar://problem/8785296> and <rdar://problem/9112893>.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127459 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-11 04:54:27 +00:00
Dan Gohman
c9f2f61d34 RecursivelyDeleteTriviallyDeadInstructions only needs a
Value, not an Instruction, so casting is not necessary. Also,
it's theoretically possible that the Value is not an
Instruction, since WeakVH follows RAUWs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127427 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-10 20:57:44 +00:00
Dan Gohman
fa0e6facc7 Fix reassociate to postpone certain instruction deletions until
after it has finished all of its reassociations, because its
habit of unlinking operands and holding them in a datastructure
while working means that it's not easy to determine when an
instruction is really dead until after all its regular work is
done. rdar://9096268.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127424 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-10 19:51:54 +00:00
Benjamin Kramer
6b96fe7e14 InstCombine: Turn umul_with_overflow into mul nuw if we can prove that it cannot overflow.
This happens a lot in clang-compiled C++ code because it adds overflow checks to operator new[]:
  unsigned *foo(unsigned n) { return new unsigned[n]; }
We can optimize away the overflow check on 64 bit targets because (uint64_t)n*4 cannot overflow.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127418 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-10 18:40:14 +00:00
Devang Patel
a2ab3999ed Preserve line number information while simplifying libcalls.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127362 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-09 21:27:52 +00:00
Devang Patel
0ef1560f27 These llvm.dbg.* constants are not used anymore.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127352 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-09 19:41:33 +00:00
Cameron Zwarich
032c10fee2 Fix a crasher introduced by r127317 that is seen on the bots when using an
alloca as both integer and floating-point vectors of the same size. Bugpoint is
not cooperating with me, but I'll try to find a manual testcase tomorrow.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127320 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-09 07:34:11 +00:00
Cameron Zwarich
b2fd770136 Add support to scalar replacement for partial vector accesses of an alloca, e.g.
a union of a float, <2 x float>, and <4 x float>. This mostly comes up with the
use of vector intrinsics, especially in NEON when programmers know the layout of
the register file. This enables codegen to eliminate a lot of the subregister
traffic it would otherwise generate.

This commit only enables this for a small number of floating-point cases, but a
lot more integer cases. I assume this is okay for all ports, but I did not do
extensive testing of the quality of code involving i512 vectors and the like. If
there is a use case where this generates worse code than before, let me know and
we can scale it back.

This fixes <rdar://problem/9036264>.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127317 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-09 05:43:05 +00:00
Cameron Zwarich
c9ecd14cee Move vector type merging to a separate function in preparation for it getting
more complicated.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127316 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-09 05:43:01 +00:00
Eli Friedman
c6b018b737 PR9346: Prevent SimplifyDemandedBits from incorrectly introducing
INT_MIN % -1.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127306 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-09 01:28: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
Devang Patel
5aa3fa6d82 llvm.dbg.declare intrinsic does not use any llvm::Values. It's magic!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127282 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-08 22:12:11 +00:00
Nick Lewycky
dcf77575d2 Reorder comments to put them the right way around.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127220 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-08 06:29:47 +00:00
Devang Patel
290342a157 While sinking an instruction, do not lose llvm.dbg.value intrinsic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127214 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-08 03:06:19 +00:00
Devang Patel
cd77a50e63 Preserve line no. info.
Radar 9097659


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127182 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-07 22:43:45 +00:00
Nick Lewycky
c14bc77315 Add more analysis of the sign bit of an srem instruction. If the LHS is negative
then the result could go either way. If it's provably positive then so is the
srem. Fixes PR9343 #7!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127146 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-07 01:50:10 +00:00
Rafael Espindola
1b5ec068f5 Don't internalize available_externally functions. We already did the right
thing for variables.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127138 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-06 23:41:34 +00:00
Nick Lewycky
d01f50f42c ConstantInt has some getters which return ConstantInt's or ConstantVector's of
the value splatted into every element. Extend this to getTrue and getFalse which
by providing new overloads that take Types that are either i1 or <N x i1>. Use
it in InstCombine to add vector support to some code, fixing PR8469!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127116 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-06 03:36:19 +00:00
Benjamin Kramer
103391d639 InstCombine: We know the number of items initially added to the worklist map, reserve space early to avoid rehashing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127089 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-05 16:43:46 +00:00
Cameron Zwarich
7c8d351d99 Fix PR9398 - 10% of llc compile time is spent in Value::getNumUses. This reduces
the percentage of time spent in CodeGenPrepare when llcing 403.gcc from 12.6% to
1.8% of total llc time.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127069 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-05 08:12:26 +00:00
Nick Lewycky
58bfcdbcf6 Thread comparisons over udiv/sdiv/ashr/lshr exact and lshr nuw/nsw whenever
possible. This goes into instcombine and instsimplify because instsimplify
doesn't need to check hasOneUse since it returns (almost exclusively) constants.

This fixes PR9343 #4 #5 and #8!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127064 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-05 05:19:11 +00:00
Nick Lewycky
9feda1730c Try once again to optimize "icmp (srem X, Y), Y" by turning the comparison into
true/false or "icmp slt/sge Y, 0".


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127063 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-05 04:28:48 +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
Richard Osborne
ea2578c63f Fix typo in comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126941 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-03 14:21:22 +00:00
Richard Osborne
022708f221 Optimize fprintf -> iprintf if there are no floating point arguments
and siprintf is available on the target.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126940 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-03 14:20:22 +00:00
Richard Osborne
419454ad37 Optimize sprintf -> siprintf if there are no floating point arguments
and siprintf is available on the target.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126937 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-03 14:09:28 +00:00
Richard Osborne
3649824bec Optimize printf -> iprintf if there are no floating point arguments
and iprintf is available on the target. Currently iprintf is only
marked as being available on the XCore.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126935 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-03 13:17:51 +00:00
Cameron Zwarich
3ccfbc2012 Remove some more unused code that I missed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126826 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-02 03:48:29 +00:00
Cameron Zwarich
56e3793acf Eliminate the unused CodeGenPrepare option to split critical edges.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126825 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-02 03:31:46 +00:00
Cameron Zwarich
4c078f0d6d Stop computing the number of uses twice per value in CodeGenPrepare's sinking of
addressing code. On 403.gcc this almost halves CodeGenPrepare time and reduces
total llc time by 9.5%. Unfortunately, getNumUses() is still the hottest function
in llc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126782 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-01 21:13:53 +00:00
Anders Carlsson
d70be0b2c1 Make InstCombiner::FoldAndOfICmps create a ConstantRange that's the
intersection of the LHS and RHS ConstantRanges and return "false" when
the range is empty.

This simplifies some code and catches some extra cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126744 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-01 15:05:01 +00:00
Eli Friedman
f291ab2fba Add an obvious missing safety check to DAE::RemoveDeadArgumentsFromCallers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126720 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-01 00:33:47 +00:00