Commit Graph

7043 Commits

Author SHA1 Message Date
Owen Anderson
327ca7bec2 Re-apply r112539, being more careful to respect the return values of the constant folding methods. Additionally,
use the ConstantExpr::get*() methods to simplify some constant folding.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112550 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-30 23:22:36 +00:00
Owen Anderson
f523b3e087 Add statistics to evaluate this pass.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112545 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-30 22:45:55 +00:00
Owen Anderson
d930f205db Revert r112539. It accidentally introduced a miscompilation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112543 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-30 22:33:41 +00:00
Owen Anderson
1e35610f20 Fixes and cleanups pointed out by Chris. In general, be careful to handle 0 results from ComputeValueKnownInPredecessors
(indicating undef), and re-use existing constant folding APIs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112539 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-30 22:07:52 +00:00
Chris Lattner
4455608818 rewrite DwarfEHPrepare to use SSAUpdater to promote its allocas
instead of PromoteMemToReg.  This allows it to stop using DF and DT,
eliminating a computation of DT and DF from clang -O3.  Clang is now
down to 2 runs of DomFrontier.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112457 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 19:54:28 +00:00
Chris Lattner
cb7f653422 two changes: 1) make AliasSet hold the list of call sites with an
assertingvh so we get a violent explosion if the pointer dangles.

2) Fix AliasSetTracker::deleteValue to remove call sites with
   by-pointer comparisons instead of by-alias queries.  Using
   findAliasSetForCallSite can cause alias sets to get merged
   when they shouldn't, and can also miss alias sets when the
   call is readonly.

#2 fixes PR6889, which only repros with a .c file :(


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112452 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 18:42:23 +00:00
Chris Lattner
0de5cad74d LICM does get dead instructions input to it. Instead of sinking them
out of loops, just delete them.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112451 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 18:22:25 +00:00
Chris Lattner
d9a5daeb77 use moveBefore instead of remove+insert, it avoids some
symtab manipulation, so its faster (in addition to being
more elegant)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112450 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 18:18:40 +00:00
Chris Lattner
1b9c848d0a revert 112448 for now.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112449 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 18:11:16 +00:00
Chris Lattner
bb07ed3bb5 optimize LICM::hoist to use moveBefore. Correct its updating
of AST to remove the hoisted instruction from the AST, since it
is no longer in the loop.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112448 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 18:03:33 +00:00
Chris Lattner
98917503c7 fix some bugs (found by inspection) where LICM would not update
LICM correctly.  When sinking an instruction, it should not add
entries for the sunk instruction to the AST, it should remove
the entry for the sunk instruction.  The blocks being sunk to
are not in the loop, so their instructions shouldn't be in the
AST (yet)!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112447 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 18:00:00 +00:00
Chris Lattner
4282e32712 rework the ownership of subloop alias information: instead of
keeping them around until the pass is destroyed, keep them
around a) just when useful (not for outer loops) and b) destroy
them right after we use them.  This should reduce memory use
and fixes potential bugs where a loop is deleted and another
loop gets allocated to the same address.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112446 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 17:46:00 +00:00
Chris Lattner
ea1092374c apparently unswitch had the same "Feature". Stop its
claims that it preserves domfrontier if it doesn't really.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112445 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 17:23:19 +00:00
Chris Lattner
937790195e now that loop passes don't use DomFrontier, there is no reason
for the unroller to pretend it supports updating it.  It still
has a horrible hack for DomTree.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112444 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 17:21:35 +00:00
Dan Gohman
4f7e18dee3 Optionally rerun dedicated-register filtering after applying
other filtering techniques, as those may allow it to filter
out more obviously unprofitable candidates.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112441 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 16:39:22 +00:00
Dan Gohman
25608f7f4b Fix several areas in LSR to do a better job keeping the main
LSRInstance data structures up to date. This fixes some
pessimizations caused by stale data which will be exposed
in an upcoming change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112440 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 16:32:54 +00:00
Dan Gohman
4aa5c2e90f Refactor the three main groups of code out of
NarrowSearchSpaceUsingHeuristics into separate functions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112439 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 16:09:42 +00:00
Dan Gohman
e39a47c5b3 Delete a bogus check.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112438 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 15:30:29 +00:00
Dan Gohman
6a83271532 Add some comments.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112437 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 15:27:08 +00:00
Dan Gohman
3902f9fca8 Move this debug output into GenerateAllReuseFormula, to declutter
the high-level logic.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112436 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 15:21:38 +00:00
Dan Gohman
a7d0d64b7a Delete an unused declaration.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112435 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 15:19:11 +00:00
Dan Gohman
46fd7a6ef8 Do one lookup instead of two.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112434 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 15:18:49 +00:00
Chris Lattner
e418ac832c licm preserves the cfg, it doesn't have to explicitly say it
preserves domfrontier.  It does preserve AA though.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112419 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 07:02:56 +00:00
Chris Lattner
44e2bd31f1 now that it doesn't use the PromoteMemToReg function, LICM doesn't
require DomFrontier.  Dropping this doesn't actually save any runs
of the pass though.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112418 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 06:49:44 +00:00
Chris Lattner
e488064922 completely rewrite the memory promotion algorithm in LICM.
Among other things, this uses SSAUpdater instead of 
PromoteMemToReg.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112417 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 06:43:52 +00:00
Chris Lattner
63a75c13b1 use getUniqueExitBlocks instead of a manual set.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112412 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 05:12:21 +00:00
Chris Lattner
a6a36f59b4 reimplement LICM::sink to use SSAUpdater instead of PromoteMemToReg.
This leads to much simpler code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112410 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 04:55:06 +00:00
Chris Lattner
ffd9beefb8 implement SSAUpdater::RewriteUseAfterInsertions, a helpful form of RewriteUse.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112409 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 04:54:06 +00:00
Chris Lattner
abd2a75900 remove dead proto
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112408 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 04:53:24 +00:00
Chris Lattner
d7bc19dfee reduce indentation in LICM::sink by using early exits, use
getUniqueExitBlocks instead of getExitBlocks and a manual
set to eliminate dupes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112405 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 04:28:20 +00:00
Chris Lattner
dc1ceb370a modernize this pass a bit: use efficient set/map and reduce indentation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112404 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-29 04:23:04 +00:00
Chris Lattner
61c70e98ac remove unions from LLVM IR. They are severely buggy and not
being actively maintained, improved, or extended.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112356 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-28 04:09:24 +00:00
Chris Lattner
5f88af5376 remove the ABCD and SSI passes. They don't have any clients that
I'm aware of, aren't maintained, and LVI will be replacing their value.
nlewycky approved this on irc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112355 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-28 03:51:24 +00:00
Chris Lattner
157d4ead36 for completeness, allow undef also.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112351 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-28 03:36:51 +00:00
Chris Lattner
b188a3789e squish dead code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112350 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-28 03:21:03 +00:00
Chris Lattner
7900779543 handle the constant case of vector insertion. For something
like this:

struct S { float A, B, C, D; };

struct S g;
struct S bar() { 
  struct S A = g;
  ++A.B;
  A.A = 42;
  return A;
}

we now generate:

_bar:                                   ## @bar
## BB#0:                                ## %entry
	movq	_g@GOTPCREL(%rip), %rax
	movss	12(%rax), %xmm0
	pshufd	$16, %xmm0, %xmm0
	movss	4(%rax), %xmm2
	movss	8(%rax), %xmm1
	pshufd	$16, %xmm1, %xmm1
	unpcklps	%xmm0, %xmm1
	addss	LCPI1_0(%rip), %xmm2
	pshufd	$16, %xmm2, %xmm2
	movss	LCPI1_1(%rip), %xmm0
	pshufd	$16, %xmm0, %xmm0
	unpcklps	%xmm2, %xmm0
	ret

instead of:

_bar:                                   ## @bar
## BB#0:                                ## %entry
	movq	_g@GOTPCREL(%rip), %rax
	movss	12(%rax), %xmm0
	pshufd	$16, %xmm0, %xmm0
	movss	4(%rax), %xmm2
	movss	8(%rax), %xmm1
	pshufd	$16, %xmm1, %xmm1
	unpcklps	%xmm0, %xmm1
	addss	LCPI1_0(%rip), %xmm2
	movd	%xmm2, %eax
	shlq	$32, %rax
	addq	$1109917696, %rax       ## imm = 0x42280000
	movd	%rax, %xmm0
	ret



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112345 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-28 01:50:57 +00:00
Chris Lattner
3dd08734c1 optimize bitcasts from large integers to vector into vector
element insertion from the pieces that feed into the vector.
This handles a pattern that occurs frequently due to code
generated for the x86-64 abi.  We now compile something like
this:

struct S { float A, B, C, D; };
struct S g;
struct S bar() { 
  struct S A = g;
  ++A.A;
  ++A.C;
  return A;
}

into all nice vector operations:

_bar:                                   ## @bar
## BB#0:                                ## %entry
	movq	_g@GOTPCREL(%rip), %rax
	movss	LCPI1_0(%rip), %xmm1
	movss	(%rax), %xmm0
	addss	%xmm1, %xmm0
	pshufd	$16, %xmm0, %xmm0
	movss	4(%rax), %xmm2
	movss	12(%rax), %xmm3
	pshufd	$16, %xmm2, %xmm2
	unpcklps	%xmm2, %xmm0
	addss	8(%rax), %xmm1
	pshufd	$16, %xmm1, %xmm1
	pshufd	$16, %xmm3, %xmm2
	unpcklps	%xmm2, %xmm1
	ret

instead of icky integer operations:

_bar:                                   ## @bar
	movq	_g@GOTPCREL(%rip), %rax
	movss	LCPI1_0(%rip), %xmm1
	movss	(%rax), %xmm0
	addss	%xmm1, %xmm0
	movd	%xmm0, %ecx
	movl	4(%rax), %edx
	movl	12(%rax), %esi
	shlq	$32, %rdx
	addq	%rcx, %rdx
	movd	%rdx, %xmm0
	addss	8(%rax), %xmm1
	movd	%xmm1, %eax
	shlq	$32, %rsi
	addq	%rax, %rsi
	movd	%rsi, %xmm1
	ret

This resolves rdar://8360454



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112343 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-28 01:20:38 +00:00
Benjamin Kramer
6cfabc7974 Update CMake build. Add newline at end of file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112332 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-28 00:11:12 +00:00
Owen Anderson
a0b59f6bd2 Add a prototype of a new peephole optimizing pass that uses LazyValue info to simplify PHIs and select's.
This pass addresses the missed optimizations from PR2581 and PR4420.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112325 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-27 23:31:36 +00:00
Chris Lattner
4ece577019 Enhance the shift propagator to handle the case when you have:
A = shl x, 42
...
B = lshr ..., 38

which can be transformed into:
A = shl x, 4
...

iff we can prove that the would-be-shifted-in bits
are already zero.  This eliminates two shifts in the testcase
and allows eliminate of the whole i128 chain in the real example.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112314 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-27 22:53:44 +00:00
Chris Lattner
29cc0b3660 Implement a pretty general logical shift propagation
framework, which is good at ripping through bitfield
operations.  This generalize a bunch of the existing
xforms that instcombine does, such as 
  (x << c) >> c -> and
to handle intermediate logical nodes.  This is useful for
ripping up the "promote to large integer" code produced by
SRoA.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112304 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-27 22:24:38 +00:00
Chris Lattner
2d0822a937 remove some special shift cases that have been subsumed into the
more general simplify demanded bits logic.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112291 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-27 21:04:34 +00:00
Owen Anderson
fc2fb17fb7 Fix typos in comments.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112286 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-27 20:32:56 +00:00
Chris Lattner
f9d05ab007 teach the truncation optimization that an entire chain of
computation can be truncated if it is fed by a sext/zext that doesn't
have to be exactly equal to the truncation result type.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112285 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-27 20:32:06 +00:00
Chris Lattner
784f333aef Add an instcombine to clean up a common pattern produced
by the SRoA "promote to large integer" code, eliminating
some type conversions like this:

   %94 = zext i16 %93 to i32                       ; <i32> [#uses=2]
   %96 = lshr i32 %94, 8                           ; <i32> [#uses=1]
   %101 = trunc i32 %96 to i8                      ; <i8> [#uses=1]

This also unblocks other xforms from happening, now clang is able to compile:

struct S { float A, B, C, D; };
float foo(struct S A) { return A.A + A.B+A.C+A.D; }

into:

_foo:                                   ## @foo
## BB#0:                                ## %entry
	pshufd	$1, %xmm0, %xmm2
	addss	%xmm0, %xmm2
	movdqa	%xmm1, %xmm3
	addss	%xmm2, %xmm3
	pshufd	$1, %xmm1, %xmm0
	addss	%xmm3, %xmm0
	ret

on x86-64, instead of:

_foo:                                   ## @foo
## BB#0:                                ## %entry
	movd	%xmm0, %rax
	shrq	$32, %rax
	movd	%eax, %xmm2
	addss	%xmm0, %xmm2
	movapd	%xmm1, %xmm3
	addss	%xmm2, %xmm3
	movd	%xmm1, %rax
	shrq	$32, %rax
	movd	%eax, %xmm0
	addss	%xmm3, %xmm0
	ret

This seems pretty close to optimal to me, at least without
using horizontal adds.  This also triggers in lots of other
code, including SPEC.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112278 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-27 18:31:05 +00:00
Owen Anderson
660cab32fe Use LVI to eliminate conditional branches where we've tested a related condition previously. Update tests for this change.
This fixes PR5652.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112270 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-27 17:12:29 +00:00
Chris Lattner
26dbe7ec18 optimize "integer extraction out of the middle of a vector" as produced
by SRoA.  This is part of rdar://7892780, but needs another xform to
expose this.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112232 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-26 22:14:59 +00:00
Chris Lattner
e5a1426174 optimize bitcast(trunc(bitcast(x))) where the result is a float and 'x'
is a vector to be a vector element extraction.  This allows clang to
compile:

struct S { float A, B, C, D; };
float foo(struct S A) { return A.A + A.B+A.C+A.D; }

into:

_foo:                                   ## @foo
## BB#0:                                ## %entry
	movd	%xmm0, %rax
	shrq	$32, %rax
	movd	%eax, %xmm2
	addss	%xmm0, %xmm2
	movapd	%xmm1, %xmm3
	addss	%xmm2, %xmm3
	movd	%xmm1, %rax
	shrq	$32, %rax
	movd	%eax, %xmm0
	addss	%xmm3, %xmm0
	ret

instead of:

_foo:                                   ## @foo
## BB#0:                                ## %entry
	movd	%xmm0, %rax
	movd	%eax, %xmm0
	shrq	$32, %rax
	movd	%eax, %xmm2
	addss	%xmm0, %xmm2
	movd	%xmm1, %rax
	movd	%eax, %xmm1
	addss	%xmm2, %xmm1
	shrq	$32, %rax
	movd	%eax, %xmm0
	addss	%xmm1, %xmm0
	ret

... eliminating half of the horribleness.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112227 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-26 21:55:42 +00:00
Owen Anderson
62efd3b385 Make JumpThreading smart enough to properly thread StrSwitch when it's compiled with clang++.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112198 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-26 17:40:24 +00:00
Dan Gohman
6cb8c23db1 Reapply r112091 and r111922, support for metadata linking, with a
fix: add a flag to MapValue and friends which indicates whether
any module-level mappings are being made. In the common case of
inlining, no module-level mappings are needed, so MapValue doesn't
need to examine non-function-local metadata, which can be very
expensive in the case of a large module with really deep metadata
(e.g. a large C++ program compiled with -g).

This flag is a little awkward; perhaps eventually it can be moved
into the ClonedCodeInfo class.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112190 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-26 15:41:53 +00:00