1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00
Commit Graph

6502 Commits

Author SHA1 Message Date
Victor Hernandez
50e7dcdcc2 Switch Elts from vector to SmallVector
llvm-svn: 93989
2010-01-20 06:56:16 +00:00
Victor Hernandez
d79e7e0e12 Map operands of all function-local metadata, not just metadata passed to llvm.dbg.declare intrinsics
llvm-svn: 93979
2010-01-20 05:49:59 +00:00
Dan Gohman
4ca37472ec When doing address-mode sinking, expand the base register first, rather
than the scaled register. This makes it more likely that subsequent
AddrModeMatcher queries will match the new address the same way as the
old, instead of accidentally matching what had been the base register
as the new scaled register, and then failing to match the scaled register.
This fixes some problems with address-mode sinking multiple muls into a
block, which will be a lot more common with some upcoming
LoopStrengthReduction changes.

llvm-svn: 93935
2010-01-19 22:45:06 +00:00
Chris Lattner
e0124f19f9 optimize ~(~X >>s Y) --> (X >>s Y), patch by Edmund Grimley
Evans!

llvm-svn: 93884
2010-01-19 18:16:19 +00:00
Bob Wilson
e94d77854f Fix a crash in scalarrepl for memcpy/memmove where the source and destination
are the same.  I had already fixed a similar problem where the source and
destination were different bitcasts derived from the same alloca, but the
previous fix still did not handle the case where both operands are exactly
the same value.  Radar 7552893.

llvm-svn: 93848
2010-01-19 04:32:48 +00:00
Eric Christopher
5b602f9bf7 Fix comment.
llvm-svn: 93831
2010-01-19 01:20:15 +00:00
Chris Lattner
6cd7a81f86 my instcombine transformations to make extension elimination more
aggressive changed the canonical form from sext(trunc(x)) to ashr(lshr(x)),
make sure to transform a couple more things into that canonical form,
and catch a case where we missed turning zext/shl/ashr into a single sext.

llvm-svn: 93787
2010-01-18 22:19:16 +00:00
Devang Patel
2cae5754c6 While mapping llvm.dbg.declare intrinsic manually map its operand, if possible,
because it points to an alloca instruction through metadata.

llvm-svn: 93757
2010-01-18 19:52:14 +00:00
Owen Anderson
d73ce407a5 Convert some of the dynamic opcode lookups into static ones.
llvm-svn: 93693
2010-01-17 19:33:27 +00:00
Owen Anderson
50cacaff8f Fix comment.
llvm-svn: 93679
2010-01-17 06:49:03 +00:00
Bob Wilson
bdd9890c7d Fix a comment typo.
llvm-svn: 93560
2010-01-15 21:55:02 +00:00
Bill Wendling
488a7187b4 When the visitSub method was split into visitSub and visitFSub, this xform was
added to the FSub version. However, the original version of this xform guarded
against doing this for floating point (!Op0->getType()->isFPOrFPVector()).

This is causing LLVM to perform incorrect xforms for code like:

void func(double *rhi, double *rlo, double xh, double xl, double yh, double yl){
  double mh, ml;
  double c = 134217729.0;
  double up, u1, u2, vp, v1, v2;
        
  up = xh*c;
  u1 = (xh - up) + up;
  u2 = xh - u1;
        
  vp = yh*c;
  v1 = (yh - vp) + vp;
  v2 = yh - v1;
        
  mh = xh*yh;
  ml = (((u1*v1 - mh) + (u1*v2)) + (u2*v1)) + (u2*v2);
  ml += xh*yl + xl*yh;
        
  *rhi = mh + ml;
  *rlo = (mh - (*rhi)) + ml;
}

The last line was optimized away, but rl is intended to be the difference
between the infinitely precise result of mh + ml and after it has been rounded
to double precision.

llvm-svn: 93369
2010-01-13 23:23:17 +00:00
Chris Lattner
21bbaf49d5 1) Use the new SimplifyInstructionsInBlock routine instead of the copy
in JT.

2) When cloning blocks for PHI or xor conditions, use
instsimplify to simplify the code as we go.  This allows us to 
squish common cases early in JT which opens up opportunities for
subsequent iterations, and allows it to completely simplify the
testcase.

llvm-svn: 93253
2010-01-12 20:41:47 +00:00
Chris Lattner
87f86498c3 add a helper function.
llvm-svn: 93251
2010-01-12 19:40:54 +00:00
Chris Lattner
bc0016437d tidy up
llvm-svn: 93222
2010-01-12 02:07:50 +00:00
Chris Lattner
774e3967ad Teach jump threading to duplicate small blocks when the branch
condition is a xor with a phi node.  This eliminates nonsense
like this from 176.gcc in several places:

 LBB166_84:
        testl   %eax, %eax
-       setne   %al
-       xorb    %cl, %al
-       notb    %al
-       testb   $1, %al
-       je      LBB166_85
+       je      LBB166_69
+       jmp     LBB166_85

This is rdar://7391699

llvm-svn: 93221
2010-01-12 02:07:17 +00:00
Chris Lattner
d6d8cc7b37 some cleanup, and make it obvious that ProcessJumpOnPHI only works
on branches by renaming it and checking for a branch at the call site.

llvm-svn: 93208
2010-01-11 23:41:09 +00:00
Chris Lattner
a8cabeeecb reenable the piece that turns trunc(zext(x)) -> x even if zext has multiple uses,
codegen has no apparent problem with the trunc version of this, because it turns
into a simple subreg idiom

llvm-svn: 93202
2010-01-11 22:49:40 +00:00
Chris Lattner
2749cc2036 Disable folding sext(trunc(x)) -> x (and other similar cast/cast cases) when the
trunc has multiple uses.  Codegen is not able to coalesce the subreg case 
correctly and so this leads to higher register pressure and spilling (see PR5997).

This speeds up 256.bzip2 from 8.60 -> 8.04s on my machine, ~7%.

llvm-svn: 93200
2010-01-11 22:45:25 +00:00
Chris Lattner
85a6f02b94 add one more bitfield optimization, allowing clang to generate
good code on PR4216:

_test_bitfield:                                             ## @test_bitfield
	orl	$32962, %edi
	movl	$4294941946, %eax
	andq	%rdi, %rax
	ret

instead of:

_test_bitfield:
        movl    $4294941696, %ecx
        movl    %edi, %eax
        orl     $194, %edi
        orl     $32768, %eax
        andq    $250, %rdi
        andq    %rax, %rcx
        movq    %rdi, %rax
        orq     %rcx, %rax
        ret

Evan is looking into the remaining andq+imm -> andl optimization.

llvm-svn: 93147
2010-01-11 06:55:24 +00:00
Chris Lattner
16e36659f5 Extend CanEvaluateZExtd to handle and/or/xor more aggressively in the
BitsToClear case.  This allows it to promote expressions which have an
and/or/xor after the lshr, promoting cases like test2 (from PR4216) 
and test3 (random extample extracted from a spec benchmark).

clang now compiles the code in PR4216 into:

_test_bitfield:                                             ## @test_bitfield
	movl	%edi, %eax
	orl	$194, %eax
	movl	$4294902010, %ecx
	andq	%rax, %rcx
	orl	$32768, %edi
	andq	$39936, %rdi
	movq	%rdi, %rax
	orq	%rcx, %rax
	ret

instead of:

_test_bitfield:                                             ## @test_bitfield
	movl	%edi, %eax
	orl	$194, %eax
	movl	$4294902010, %ecx
	andq	%rax, %rcx
	shrl	$8, %edi
	orl	$128, %edi
	shlq	$8, %rdi
	andq	$39936, %rdi
	movq	%rdi, %rax
	orq	%rcx, %rax
	ret

which is still not great, but is progress.

llvm-svn: 93145
2010-01-11 04:05:13 +00:00
Chris Lattner
f2ba85eedc Remove the dead TD argument to CanEvaluateZExtd, and add a
new BitsToClear result which allows us to start promoting
expressions that end with a lshr-by-constant.  This is
conservatively correct and better than what we had before
(see testcases) but still needs to be extended further.

llvm-svn: 93144
2010-01-11 03:32:00 +00:00
Chris Lattner
d7f1b97147 improve comments, remove dead TD argument to CanEvaluateSExtd.
llvm-svn: 93143
2010-01-11 02:43:35 +00:00
Chris Lattner
18d753e05f teach sext optimization to handle truncs from types that are not
the dest of the sext.

llvm-svn: 93128
2010-01-10 20:30:41 +00:00
Chris Lattner
ca53de1ab7 teach zext optimization how to deal with truncs that don't come from
the zext dest type.  This allows us to handle test52/53 in cast.ll,
and allows llvm-gcc to generate much better code for PR4216 in -m64
mode:

_test_bitfield:                                             ## @test_bitfield
	orl	$32962, %edi
	movl	%edi, %eax
	andl	$-25350, %eax
	ret

This also fixes a bug handling vector extends, ensuring that the
mask produced is a vector constant, not an integer constant.

llvm-svn: 93127
2010-01-10 20:25:54 +00:00
Chris Lattner
67e0ef4d5d simplify CanEvaluateSExtd to return a bool now that we have a
simpler profitability predicate.

llvm-svn: 93111
2010-01-10 07:57:20 +00:00
Chris Lattner
fa864affbc the NumCastsRemoved argument to CanEvaluateSExtd is dead, remove it.
llvm-svn: 93110
2010-01-10 07:42:21 +00:00
Chris Lattner
e68d6e61b1 now that the cost model has changed, we can always consider
elimination of a sign extend to be a win, which simplifies 
the client of CanEvaluateSExtd, and allows us to eliminate
more casts (examples taken from real code).

llvm-svn: 93109
2010-01-10 07:40:50 +00:00
Chris Lattner
e86619ca01 change the preferred canonical form for a sign extension to be
lshr+ashr instead of trunc+sext.  We want to avoid type 
conversions whenever possible, it is easier to codegen expressions
without truncates and extensions.

llvm-svn: 93107
2010-01-10 07:08:30 +00:00
Chris Lattner
00b1e8508e fix indentation of switch statements, no functionality change.
llvm-svn: 93106
2010-01-10 06:59:55 +00:00
Chris Lattner
1332cfaea1 fix pasto that broke bootstrap.
llvm-svn: 93105
2010-01-10 06:50:04 +00:00
Chris Lattner
7314e76078 simplify CanEvaluateZExtd now that we don't care about the number of
bits known clear in the result and don't care about the # casts 
eliminated.  TD is also dead but keeping it for now.

llvm-svn: 93098
2010-01-10 02:50:04 +00:00
Chris Lattner
1106f03886 two changes:
1) don't try to optimize a sext or zext that is only used by a trunc, let
   the trunc get optimized first.  This avoids some pointless effort in
   some common cases since instcombine scans down a block in the first pass.
2) Change the cost model for zext elimination to consider an 'and' cheaper
   than a zext.  This allows us to do it more aggressively, and for the next
   patch to simplify the code quite a bit.

llvm-svn: 93097
2010-01-10 02:39:31 +00:00
Chris Lattner
a04ed0659f enhance CanEvaluateZExtd to handle shift left and sext, allowing
more expressions to be promoted and casts eliminated.

llvm-svn: 93096
2010-01-10 02:22:12 +00:00
Chris Lattner
eb3da2ab86 remove an xform subsumed by EvaluateInDifferentType.
llvm-svn: 93095
2010-01-10 01:35:55 +00:00
Julien Lerouge
950d1334d1 Fix nondeterministic behavior.
llvm-svn: 93093
2010-01-10 01:07:22 +00:00
Chris Lattner
edb60f0861 clean up this xform by using m_Trunc.
llvm-svn: 93092
2010-01-10 01:04:31 +00:00
Chris Lattner
3efde81a44 inline and remove the rest of commonIntCastTransforms.
llvm-svn: 93091
2010-01-10 01:00:46 +00:00
Chris Lattner
492e9ca5a4 Inline the expression type promotion/demotion stuff out of
commonIntCastTransforms into the callers, eliminating a switch,
and allowing the static predicate  methods to be moved down to
live next to the corresponding function.  No functionality 
change.

llvm-svn: 93089
2010-01-10 00:58:42 +00:00
Chris Lattner
b142e13f84 only factor from expressions whose uses are empty and whose
base is the right expression type.  This fixes PR5981.

llvm-svn: 93045
2010-01-09 06:01:36 +00:00
Julien Lerouge
76c75e82d0 Fix nondeterministic behavior.
llvm-svn: 93038
2010-01-09 01:06:49 +00:00
Eric Christopher
937778e8d0 Remove unnecessary dyn_cast and add a comment. Part of a WIP.
llvm-svn: 93026
2010-01-08 21:37:11 +00:00
Chris Lattner
fd117b63f7 mplement a theoretical fixme.
llvm-svn: 93024
2010-01-08 19:28:47 +00:00
Chris Lattner
474cd30fb7 rename CanEvaluateInDifferentType -> CanEvaluateTruncated and
simplify it now that it is only used for truncates.

llvm-svn: 93021
2010-01-08 19:19:23 +00:00
Chris Lattner
05ae88cc8f teach instcombine to delete sign extending shift pairs (sra(shl X, C), C) when
the input is already sign extended.

llvm-svn: 93019
2010-01-08 19:04:21 +00:00
Duncan Sands
c94f8aeb36 Suppress an unused variable warning when assertions are off;
remove some trailing whitespace while there.

llvm-svn: 93008
2010-01-08 17:51:48 +00:00
Chris Lattner
725b9ba4e5 tidy up some stuff duncan pointed out.
llvm-svn: 93007
2010-01-08 17:48:19 +00:00
Chris Lattner
944f9c4ac1 teach ComputeNumSignBits to look through PHI nodes.
llvm-svn: 92964
2010-01-07 23:44:37 +00:00
Chris Lattner
db8fa82914 Enhance instcombine to reason more strongly about promoting computation
that feeds into a zext, similar to the patch I did yesterday for sext.
There is a lot of room for extension beyond this patch.

llvm-svn: 92962
2010-01-07 23:41:00 +00:00
Benjamin Kramer
df696ee6b4 Use a do-while loop instead of while + boolean.
llvm-svn: 92912
2010-01-07 13:50:07 +00:00
Duncan Sands
8299315be7 Be less stingy as to how many selects and phi nodes we
are prepared to look through.

llvm-svn: 92898
2010-01-07 05:48:42 +00:00
Chris Lattner
1a64e58fa3 handle ConstantVector while I'm in here.
llvm-svn: 92892
2010-01-07 01:20:20 +00:00
Chris Lattner
0b0caf0877 fix a globalopt crash on 'bullet' (handling evaluation of a store
to an element of a vector in a static ctor) which occurs with an 
unrelated patch I'm testing.  Annoyingly, EvaluateStoreInto basically 
does exactly the same stuff as InsertElement constant folding, but it
now handles vectors, and you can't insertelement into a vector.  It
would be 'really nice' if GEP into a vector were not legal.

llvm-svn: 92889
2010-01-07 01:16:21 +00:00
Eric Christopher
0574ce70c3 Move the object size intrinsic optimization to inst-combine and make
it work for any integer size return type.

llvm-svn: 92853
2010-01-06 20:04:44 +00:00
Duncan Sands
de0adbdf25 Fix a README item: have functionattrs look through selects and
phi nodes when deciding which pointers point to local memory.
I actually checked long ago how useful this is, and it isn't
very: it hardly ever fires in the testsuite, but since Chris
wants it here it is!

llvm-svn: 92836
2010-01-06 15:37:47 +00:00
Mikhail Glushenkov
f7e36a1fe2 Formatting.
llvm-svn: 92831
2010-01-06 09:20:39 +00:00
Duncan Sands
4ef1119d94 Partially address a README by having functionattrs consider calls to
memcpy, memset and other intrinsics that only access their arguments
to be readnone if the intrinsic's arguments all point to local memory.
This improves the testcase in the README to readonly, but it could in
theory be made readnone, however this would involve more sophisticated
analysis that looks through the memcpy.

llvm-svn: 92829
2010-01-06 08:45:52 +00:00
Chris Lattner
0f611954b6 tweaks suggested by Duncan
llvm-svn: 92824
2010-01-06 05:32:15 +00:00
Chris Lattner
0b73344d8a Teach instcombine's sext elimination logic to be more aggressive.
Previously, instcombine would only promote an expression tree to
the larger type if doing so eliminated two casts.  This is because
a need to manually do the sign extend after the promoted expression
tree with two shifts.  Now, we keep track of whether the result of
the computation is going to be properly sign extended already.  If
so, we can unconditionally promote the expression, which allows us
to zap more sext's.

This implements rdar://6598839 (aka gcc pr38751)

llvm-svn: 92815
2010-01-06 01:56:21 +00:00
Chris Lattner
7bf6842c49 simplify this code.
llvm-svn: 92800
2010-01-05 23:00:30 +00:00
Chris Lattner
a101affbdb make this a static function instead of a method.
llvm-svn: 92795
2010-01-05 22:30:42 +00:00
Chris Lattner
53b9ed70ee more rearrangement and cleanup, fix my test failure.
llvm-svn: 92792
2010-01-05 22:21:18 +00:00
Chris Lattner
45cd7ba394 cleanup
llvm-svn: 92790
2010-01-05 22:07:33 +00:00
Chris Lattner
2f69f6a822 remove two trunc xforms that are subsumed by EvaluateInDifferentType.
The only difference is that EvaluateInDifferentType checks to ensure
they are profitable before doing them :)

llvm-svn: 92788
2010-01-05 22:01:41 +00:00
Chris Lattner
13293b9738 just remove this xform which is subsumed by others.
llvm-svn: 92775
2010-01-05 21:16:30 +00:00
Chris Lattner
3aac94341a move a trunc-specific transform out of commonIntCastTransforms into visitTrunc.
llvm-svn: 92773
2010-01-05 21:11:17 +00:00
Benjamin Kramer
0ba7479f2c Move remaining stuff to the isInteger predicate.
llvm-svn: 92771
2010-01-05 21:05:54 +00:00
Chris Lattner
18ed3a6976 move a zext specific xform out of commonIntCastTransforms into visitZExt and modernize it.
llvm-svn: 92770
2010-01-05 21:04:47 +00:00
Chris Lattner
4c21bfec50 move a trunc-specific xform out of commonIntCastTransforms into visitTrunc
llvm-svn: 92768
2010-01-05 20:57:30 +00:00
Chris Lattner
e293a03aff reduce indentation
llvm-svn: 92766
2010-01-05 20:56:24 +00:00
Benjamin Kramer
c233521d45 Convert a ton of simple integer type equality tests to the new predicate.
llvm-svn: 92760
2010-01-05 20:07:06 +00:00
Chris Lattner
f457542506 optimize comparisons against cttz/ctlz/ctpop, patch by Alastair Lynn!
llvm-svn: 92745
2010-01-05 18:09:56 +00:00
Dan Gohman
4b9a39d586 Nick Lewycky pointed out that this code makes changes unconditionally.
llvm-svn: 92739
2010-01-05 17:50:58 +00:00
Dan Gohman
fff95c0489 Set Changed properly after calling DeleteDeadPHIs.
llvm-svn: 92735
2010-01-05 16:31:45 +00:00
Dan Gohman
e4a22bdd4a Use do+while instead of while for loops which obviously have a
non-zero trip count. Use SmallVector's pop_back_val().

llvm-svn: 92734
2010-01-05 16:27:25 +00:00
Dan Gohman
7924aacfe4 Fix indentation.
llvm-svn: 92733
2010-01-05 16:20:55 +00:00
Dan Gohman
41cc1e1fc4 Make RecursivelyDeleteTriviallyDeadInstructions,
RecursivelyDeleteDeadPHINode, and DeleteDeadPHIs return a flag
indicating whether they made any changes.

llvm-svn: 92732
2010-01-05 15:45:31 +00:00
Benjamin Kramer
cd6b749245 Add newline at EOF.
llvm-svn: 92727
2010-01-05 13:32:48 +00:00
Benjamin Kramer
e90a3c66c4 Avoid going through the LLVMContext for type equality where it's safe to dereference the type pointer.
llvm-svn: 92726
2010-01-05 13:12:22 +00:00
Chris Lattner
09b91ecf3c prune some #includes.
llvm-svn: 92712
2010-01-05 07:54:43 +00:00
Chris Lattner
58ddbda58c split and/or/xor out into one overly-large (2000LOC) file. However, I think
it does make sense to keep them together, at least for now.

llvm-svn: 92711
2010-01-05 07:50:36 +00:00
Chris Lattner
7201f09ff2 missed file with previous commit.
llvm-svn: 92710
2010-01-05 07:45:02 +00:00
Chris Lattner
dd39b601af split instcombine of shifts out to its own file.
llvm-svn: 92709
2010-01-05 07:44:46 +00:00
Chris Lattner
e75f48f8bd eliminate getBitCastOperand and simplify some over-complex inbounds stuff.
llvm-svn: 92708
2010-01-05 07:42:10 +00:00
Chris Lattner
e21194fe22 split call handling out to InstCombineCalls.cpp
llvm-svn: 92707
2010-01-05 07:32:13 +00:00
Chris Lattner
491e03b6ef optimize cttz and ctlz when we can prove something about the
leading/trailing bits.  Patch by Alastair Lynn!

llvm-svn: 92706
2010-01-05 07:23:56 +00:00
Chris Lattner
e36e3b586d this inline function moved to addsub
llvm-svn: 92705
2010-01-05 07:20:54 +00:00
Chris Lattner
63747a10a8 split add/sub out to its own file. Eliminate use of
dyn_castNotVal in the X+~X transform.  dyn_castNotVal is
dramatic overkill for what the xform needed.

llvm-svn: 92704
2010-01-05 07:18:46 +00:00
Chris Lattner
5ea00f56bd all the places we use hasOneUse() we know are instructions, so inline
and simplify.

llvm-svn: 92700
2010-01-05 07:04:23 +00:00
Chris Lattner
081decf118 eliminate AssociativeOpt and its last uses.
llvm-svn: 92697
2010-01-05 07:01:16 +00:00
Chris Lattner
4d773ac576 inline the FoldICmpLogical functor.
llvm-svn: 92695
2010-01-05 06:59:49 +00:00
Chris Lattner
1e57d0e7e3 inline the 'AddRHS' transformation, simplifying things significantly.
Eliminate the 'AddMaskingAnd' transformation, it is redundant with this
more general code right below it:
  // A+B --> A|B iff A and B have no bits set in common.

llvm-svn: 92693
2010-01-05 06:29:13 +00:00
Chris Lattner
17a2db8444 remove massive over-genality manifested as a big template
that got instantiated.  There is no reason for instcombine
to try this hard for simple associative optimizations.  Next
up, eliminate the template completely.

llvm-svn: 92692
2010-01-05 06:24:06 +00:00
Chris Lattner
92f9d59ad1 split mul/div/rem instructions out to their own file.
llvm-svn: 92689
2010-01-05 06:09:35 +00:00
Chris Lattner
8822b80a65 clean up header.
llvm-svn: 92688
2010-01-05 06:05:07 +00:00
Chris Lattner
e4910dc145 split select out to its own file.
llvm-svn: 92687
2010-01-05 06:03:12 +00:00
Chris Lattner
b55724e825 split out load/store/alloca.
llvm-svn: 92685
2010-01-05 05:57:49 +00:00
Chris Lattner
916d97c2d5 reduce indentation
llvm-svn: 92684
2010-01-05 05:42:08 +00:00
Chris Lattner
e22030e730 split vector stuff out to InstCombineVectorOps.cpp
llvm-svn: 92683
2010-01-05 05:36:20 +00:00
Chris Lattner
23ff3ce8eb split PHI node stuff out to InstCombinePHI.cpp
llvm-svn: 92682
2010-01-05 05:31:55 +00:00
Chris Lattner
48618eeec3 convert various IntrinsicInst's to use class instead of struct.
llvm-svn: 92681
2010-01-05 05:21:26 +00:00
Chris Lattner
2ef4ba7cf5 fix an infinite loop in reassociate building emacs.
llvm-svn: 92679
2010-01-05 04:55:35 +00:00
David Greene
6b20914d8a Change errs() to dbgs().
llvm-svn: 92639
2010-01-05 01:28:37 +00:00
David Greene
a48859b420 Change errs() to dbgs().
llvm-svn: 92636
2010-01-05 01:28:29 +00:00
David Greene
6c314b2f2b Change errs() to dbgs().
llvm-svn: 92633
2010-01-05 01:28:12 +00:00
David Greene
706266dce6 Change errs() to dbgs().
llvm-svn: 92631
2010-01-05 01:28:07 +00:00
David Greene
04f5c49e6f Change errs() to dbgs().
llvm-svn: 92629
2010-01-05 01:28:05 +00:00
David Greene
e5c3a6f658 Change errs() to dbgs().
llvm-svn: 92627
2010-01-05 01:27:54 +00:00
David Greene
0d082a1e9d Change errs() to dbgs().
llvm-svn: 92625
2010-01-05 01:27:51 +00:00
David Greene
ccb57dd5d2 Change errs() to dbgs().
llvm-svn: 92624
2010-01-05 01:27:47 +00:00
David Greene
ab5e347e1d Change errs() to dbgs().
llvm-svn: 92623
2010-01-05 01:27:44 +00:00
David Greene
9bb1c8a001 Change errs() to dbgs().
llvm-svn: 92622
2010-01-05 01:27:39 +00:00
David Greene
633e3e29d8 Change errs() to dbgs().
llvm-svn: 92620
2010-01-05 01:27:33 +00:00
David Greene
342f06bea0 Change errs() to dbgs().
llvm-svn: 92619
2010-01-05 01:27:30 +00:00
David Greene
6c61de5712 Change errs() to dbgs().
llvm-svn: 92617
2010-01-05 01:27:24 +00:00
David Greene
bb6730f5ac Change errs() to dbgs().
llvm-svn: 92615
2010-01-05 01:27:21 +00:00
David Greene
0a35321dc2 Change errs() to dbgs().
llvm-svn: 92614
2010-01-05 01:27:19 +00:00
David Greene
9befdbf1a8 Change errs() to dbgs().
llvm-svn: 92613
2010-01-05 01:27:17 +00:00
David Greene
02e79531be Change errs() to dbgs().
llvm-svn: 92612
2010-01-05 01:27:15 +00:00
David Greene
937fdd9ec0 Change errs() to dbgs().
llvm-svn: 92611
2010-01-05 01:27:11 +00:00
David Greene
578f63538f Change errs() to dbgs().
llvm-svn: 92610
2010-01-05 01:27:09 +00:00
David Greene
d5a25b5d1f Change errs() to dbgs().
llvm-svn: 92609
2010-01-05 01:27:06 +00:00
David Greene
15100f4246 Change errs() to dbgs().
llvm-svn: 92608
2010-01-05 01:27:04 +00:00
David Greene
a013a3b5e4 Change errs() to dbgs().
llvm-svn: 92607
2010-01-05 01:27:01 +00:00
David Greene
d0587e9991 Change errs() to dbgs().
llvm-svn: 92606
2010-01-05 01:26:57 +00:00
David Greene
1d478b6184 Change errs() to dbgs().
llvm-svn: 92605
2010-01-05 01:26:54 +00:00
David Greene
e07c8e1668 Change errs() to dbgs().
llvm-svn: 92604
2010-01-05 01:26:52 +00:00
David Greene
991e882855 Change errs() to dbgs().
llvm-svn: 92603
2010-01-05 01:26:49 +00:00
David Greene
94ab26dd76 Change errs() to dbgs().
llvm-svn: 92602
2010-01-05 01:26:45 +00:00
David Greene
2805ab874b Change errs() to dbgs().
llvm-svn: 92601
2010-01-05 01:26:44 +00:00
David Greene
e7608c8372 Change errs() to dbgs().
llvm-svn: 92600
2010-01-05 01:26:41 +00:00
David Greene
afac983b1a Change errs() to dbgs().
llvm-svn: 92599
2010-01-05 01:26:39 +00:00
Devang Patel
3b08c33f33 Remove dead debug info intrinsics.
Intrinsic::dbg_stoppoint
 Intrinsic::dbg_region_start 
 Intrinsic::dbg_region_end 
 Intrinsic::dbg_func_start
AutoUpgrade simply ignores these intrinsics now.

llvm-svn: 92557
2010-01-05 01:10:40 +00:00
Daniel Dunbar
1fb9148421 Fix some struct/class specifier mismatches.
llvm-svn: 92550
2010-01-05 00:15:58 +00:00
Chris Lattner
3b060b2d41 Truncate GEP indexes larger than the pointer size down to pointer size
when doing this transform if the GEP is not inbounds.  No testcase because
it is very difficult to trigger this: instcombine already canonicalizes
GEP indices to pointer size, so it relies specific permutations of the
instcombine worklist.

Thanks to Duncan for pointing this possible problem out.

llvm-svn: 92495
2010-01-04 18:57:15 +00:00
Chris Lattner
8304a93ff4 silence a bogus 'might be used uninit' warning from GCC.
llvm-svn: 92494
2010-01-04 18:48:26 +00:00
Chris Lattner
e19878577c move some more cast-related stuff
llvm-svn: 92471
2010-01-04 07:59:07 +00:00
Mikhail Glushenkov
38e36d577a 80-col violations, trailing whitespace.
llvm-svn: 92470
2010-01-04 07:55:25 +00:00
Chris Lattner
f9920fbac9 move the [Can]EvaluateInDifferentType functions out to InstCombineCasts.cpp
llvm-svn: 92469
2010-01-04 07:54:59 +00:00
Chris Lattner
7a5037baf5 split 943 lines of instcombine out to a new InstCombineCasts.cpp
file.  InstructionCombining.cpp is now down to a svelte 9300 lines :)

llvm-svn: 92468
2010-01-04 07:53:58 +00:00
Chris Lattner
fed736376e split instcombine of compares (visit[FI]Cmp) out to
a new InstCombineCompares.cpp file.

llvm-svn: 92467
2010-01-04 07:37:31 +00:00
Chris Lattner
176c21d33e update cmakefile
llvm-svn: 92466
2010-01-04 07:19:55 +00:00
Chris Lattner
fbcc4eb5a5 move the 'SimplifyDemandedFoo' methods out to their own file, cutting 1K lines out of instcombine.cpp
llvm-svn: 92465
2010-01-04 07:17:19 +00:00
Chris Lattner
cf0889fda3 split the instcombine class definition out to a header shared
among the instcombine library.

llvm-svn: 92463
2010-01-04 07:12:23 +00:00
Chris Lattner
cb0fe8a20b remove a ton of unneeded LLVMContext stuff.
llvm-svn: 92462
2010-01-04 07:02:48 +00:00
Chris Lattner
ec9a1ab1bb move InstCombineWorklist out to its own header.
llvm-svn: 92461
2010-01-04 06:30:00 +00:00
Chris Lattner
2e86be5607 forgot to svn add these.
llvm-svn: 92460
2010-01-04 06:28:20 +00:00
Chris Lattner
2d9948f5f1 move instcombine to its own library, it's past time.
llvm-svn: 92459
2010-01-04 06:23:24 +00:00
Chris Lattner
ce3f5f3448 implement an instcombine xform needed by clang's codegen
on the example in PR4216.  This doesn't trigger in the testsuite,
so I'd really appreciate someone scrutinizing the logic for
correctness.

llvm-svn: 92458
2010-01-04 06:03:59 +00:00
Chris Lattner
eb68b810a8 pull my debug hooks out, I'm done with this xform for now.
llvm-svn: 92446
2010-01-03 06:58:48 +00:00
Nick Lewycky
ebb78c871c Small cleanups, refactor some duplicated code into a single method. No
functionality change.

llvm-svn: 92445
2010-01-03 04:39:07 +00:00
Chris Lattner
647c629ee4 generalize the previous transformation to handle indexing into
arrays of structs and other arrays, so long as all the subsequent
indexes are constants.  This triggers frequently for stuff like:

@divisions = internal constant [29 x [2 x i32]] [[2 x i32] zeroinitializer, [2 x i32] [i32 0, i32 1], [2 x i32] [i32 0, i32 2], [2 x i32] [i32 0, i32 1], [2 x i32] zeroinitializer, [2 x i32] [i32 0, i32 1], [2 x i32] [i32 0, i32 1], [2 x i32] [i32 0, i32 2], [2 x i32] [i32 0, i32 2], [2 x i32] zeroinitializer, [2 x i32] zeroinitializer, [2 x i32] zeroinitializer, [2 x i32] [i32 0, i32 2], [2 x i32] [i32 0, i32 1], [2 x i32] zeroinitializer, [2 x i32] [i32 1, i32 0], [2 x i32] [i32 1, i32 1], [2 x i32] [i32 1, i32 1], [2 x i32] [i32 1, i32 2], [2 x i32] [i32 1, i32 1], [2 x i32] [i32 1, i32 0], [2 x i32] [i32 1, i32 2], [2 x i32] [i32 1, i32 2], [2 x i32] [i32 1, i32 0], [2 x i32] [i32 1, i32 0], [2 x i32] [i32 1, i32 0], [2 x i32] [i32 1, i32 1], [2 x i32] [i32 1, i32 2], [2 x i32] [i32 1, i32 2]], align 32 ; <[29 x [2 x i32]]*> [#uses=50]

	  %623 = getelementptr inbounds [29 x [2 x i32]]* @divisions, i64 0, i64 %619, i64 0 ; <i32*> [#uses=1]
	   %684 = icmp eq i32 %683, 999 

also for the "my_defs" table in 'gs', etc.

llvm-svn: 92444
2010-01-03 03:03:27 +00:00
Nick Lewycky
b871238139 Cleanup.
llvm-svn: 92436
2010-01-03 00:55:31 +00:00
Chris Lattner
acb0c133ec teach instcombine to optimize idioms like A[i]&42 == 0. This
occurs in 403.gcc in mode_mask_array, in safe-ctype.c (which
is copied in multiple apps) in _sch_istable, etc.

llvm-svn: 92427
2010-01-02 22:08:28 +00:00
Chris Lattner
4af67af013 Teach the table lookup optimization to generate range compares
when a consequtive sequence of elements all satisfies the 
predicate.  Like the double compare case, this generates better
code than the magic constant case and generalizes to more than
32/64 element array lookups.

Here are some examples where it triggers.  From 403.gcc, most
accesses to the rtx_class array are handled, e.g.:

@rtx_class = constant [153 x i8] c"xxxxxmmmmmmmmxxxxxxxxxxxxmxxxxxxiiixxxxxxxxxxxxxxxxxxxooxooooooxxoooooox3x2c21c2222ccc122222ccccaaaaaa<<<<<<<<<<<<<<<<<<111111111111bbooxxxxxxxxxxcc2211x", align 32 ; <[153 x i8]*> [#uses=547]
   %142 = icmp eq i8 %141, 105
@rtx_class = constant [153 x i8] c"xxxxxmmmmmmmmxxxxxxxxxxxxmxxxxxxiiixxxxxxxxxxxxxxxxxxxooxooooooxxoooooox3x2c21c2222ccc122222ccccaaaaaa<<<<<<<<<<<<<<<<<<111111111111bbooxxxxxxxxxxcc2211x", align 32 ; <[153 x i8]*> [#uses=543]
	   %165 = icmp eq i8 %164, 60      

Also, most of the 59-element arrays (mode_class/rid_to_yy, etc) 
optimized before are actually range compares.  This lets 32-bit
machines optimize them.

400.perlbmk has stuff like this:

400.perlbmk: PL_regkind, even for 32-bit:
@PL_regkind = constant [62 x i8] c"\00\00\02\02\02\06\06\06\06\09\09\0B\0B\0D\0E\0E\0E\11\12\12\14\14\16\16\18\18\1A\1A\1C\1C\1E\1F !!!$$&'((((,-.///88886789:;8$", align 32 ; <[62 x i8]*> [#uses=4]
	   %811 = icmp ne i8 %810, 33 

@PL_utf8skip = constant [256 x i8] c"\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\03\03\03\03\03\03\03\03\03\03\03\03\03\03\03\03\04\04\04\04\04\04\04\04\05\05\05\05\06\06\07\0D", align 32 ; <[256 x i8]*> [#uses=94]
	   %12 = icmp ult i8 %10, 2
           
etc.

llvm-svn: 92426
2010-01-02 21:50:18 +00:00
Chris Lattner
c67cde71b1 theoretically the negate we find could be in a different function, check
for this case.

llvm-svn: 92425
2010-01-02 21:46:33 +00:00
Chris Lattner
dfb25d34f5 use enums for the over/underdefined markers for clarity. Switch
to using -2/-3 instead of -1/-2 for a future xform.

llvm-svn: 92423
2010-01-02 20:20:33 +00:00
Chris Lattner
07a1a284d3 remove the random sampling framework, which is not maintained anymore.
If there is interest, it can be resurrected from SVN.  PR4912.

llvm-svn: 92422
2010-01-02 20:07:03 +00:00
Nick Lewycky
cda0109ec5 Fix logic error in previous commit. The != case needs to become an or, not an
and.

llvm-svn: 92419
2010-01-02 16:14:56 +00:00
Nick Lewycky
3cc8fe073a Optimize pointer comparison into the typesafe form, now that the backends will
handle them efficiently. This is the opposite direction of the transformation
we used to have here.

llvm-svn: 92418
2010-01-02 15:25:44 +00:00
Chris Lattner
e1a2489017 Generalize the previous xform to handle cases where exactly
two elements match or don't match with two comparisons.  For
example, the testcase compiles into:

define i1 @test5(i32 %X) {
  %1 = icmp eq i32 %X, 2                          ; <i1> [#uses=1]
  %2 = icmp eq i32 %X, 7                          ; <i1> [#uses=1]
  %R = or i1 %1, %2                               ; <i1> [#uses=1]
  ret i1 %R
}

This generalizes the previous xforms when the array is larger than
64 elements (and this case matches) and generates better code for
cases where it overlaps with the magic bitshift case.

This generalizes more cases than you might expect.  For example,
400.perlbmk has:

@PL_utf8skip = constant [256 x i8] c"\01\01\01\...
%15 = icmp ult i8 %7, 7

403.gcc has:
@rid_to_yy = internal constant [114 x i16] [i16 259, i16 260, ...
%18 = icmp eq i16 %16, 295 

and xalancbmk has a bunch of examples, such as 
_ZN11xercesc_2_5L15gCombiningCharsE and _ZN11xercesc_2_5L10gBaseCharsE.

llvm-svn: 92417
2010-01-02 09:35:17 +00:00
Chris Lattner
8b60c9de65 fix a miscompilation I introduced of cdecl with a late change.
llvm-svn: 92416
2010-01-02 09:22:13 +00:00
Chris Lattner
1cdc77b8da enhance the compare/load/index optimization to work on *any* load
from a global with 32/64 elements or less (depending on whether
i64 is native on the target), generating a bitshift idiom to 
determine the result.  For example, on test4 we produce:

define i1 @test4(i32 %X) {
  %1 = lshr i32 933, %X                           ; <i32> [#uses=1]
  %2 = and i32 %1, 1                              ; <i32> [#uses=1]
  %R = icmp ne i32 %2, 0                          ; <i1> [#uses=1]
  ret i1 %R
}

This triggers in a number of interesting cases, for example, here's an
fp case:
@A.3255 = internal constant [4 x double] [double 4.100000e+00, double -3.900000e+00, double -1.000000e+00, double 1.000000e+00], align 32 ; <[4 x double]*> [#uses=7]
...
	   %7 = fcmp olt double %3, 0.000000e+00

In this case we make the slen2_tab global dead, which is nice:
@slen2_tab = internal constant [16 x i32] [i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3, i32 1, i32 2, i32 3, i32 1, i32 2, i32 3, i32 2, i32 3], align 32 ; <[16 x i32]*> [#uses=1]
...
	   %204 = icmp eq i32 %46, 0     

Perl has a bunch of these, also on the 'Perl_regkind' array:
@Perl_yygindex = internal constant [51 x i16] [i16 0, i16 0, i16 0, i16 0, i16 374, i16 351, i16 0, i16 -12, i16 0, i16 946, i16 413, i16 -83, i16 0, i16 0, i16 0, i16 -311, i16 -13, i16 4007, i16 2893, i16 0, i16 0, i16 0, i16 0, i16 0, i16 372, i16 -8, i16 0, i16 0, i16 246, i16 -131, i16 43, i16 86, i16 208, i16 -45, i16 -169, i16 987, i16 0, i16 0, i16 0, i16 0, i16 308, i16 0, i16 -271, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0], align 32 ; <[51 x i16]*> [#uses=1]
...
  %1364 = icmp eq i16 %1361, 0

186.crafty really likes this on 64-bit machines, because it triggers on a bunch of globals like this:
@white_outpost = internal constant [64 x i8] c"\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\02\02\00\00\00\00\00\04\05\05\04\00\00\00\00\03\06\06\03\00\00\00\00\00\01\01\00\00\00\00\00\00\00\00\00\00\00", align 32 ; <[64 x i8]*> [#uses=2]

However the big winner is 403.gcc, which triggers hundreds of times, eliminating all the accesses to the 57-element arrays 'mode_class', mode_unit_size, mode_bitsize, regclass_map, etc.

go 64-bit machines :)

llvm-svn: 92415
2010-01-02 08:56:52 +00:00
Chris Lattner
59136ba5ad enhance the previous optimization to work with fcmp in addition
to icmp.

llvm-svn: 92412
2010-01-02 08:20:51 +00:00
Chris Lattner
f3f6c10218 Teach instcombine to fold compares of loads from constant
arrays with variable indices into a comparison of the index
with a constant.  The most common occurrence of this that
I see by far is stuff like:

if ("foobar"[i] == '\0') ...

which we compile into: if (i == 6), saving a load and 
materialization of the global address.  This also exposes 
loop trip count information to later passes in many cases.

This triggers hundreds of times in xalancbmk, which is where I first
noticed it, but it also triggers in many other apps.  Here are a few 
interesting ones from various apps:

@must_be_connected_without = internal constant [8 x i8*] [i8* getelementptr inbounds ([3 x i8]* @.str64320, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8]* @.str27283, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8]* @.str71327, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8]* @.str72328, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8]* @.str18274, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8]* @.str11267, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8]* @.str32288, i64 0, i64 0), i8* null], align 32 ; <[8 x i8*]*> [#uses=2]
  %scevgep.i = getelementptr [8 x i8*]* @must_be_connected_without, i64 0, i64 %indvar.i ; <i8**> [#uses=1]
  %17 = load ...
  %18 = icmp eq i8* %17, null                     ; <i1> [#uses=1]
-> icmp eq i64 %indvar.i, 7 


@yytable1095 = internal constant [84 x i8] c"\12\01(\05\06\07\08\09\0A\0B\0C\0D\0E1\0F\10\11266\1D: \10\11,-,0\03'\10\11B6\04\17&\18\1945\05\06\07\08\09\0A\0B\0C\0D\0E\1E\0F\10\11*\1A\1B\1C$3+>#%;<IJ=ADFEGH9KL\00\00\00C", align 32 ; <[84 x i8]*> [#uses=2]
  %57 = getelementptr inbounds [84 x i8]* @yytable1095, i64 0, i64 %56 ; <i8*> [#uses=1]
   %mode.0.in = getelementptr inbounds [9 x i32]* @mb_mode_table, i64 0, i64 %.pn ; <i32*> [#uses=1]
load ...
   %64 = icmp eq i8 %58, 4                         ; <i1> [#uses=1]
-> icmp eq i64 %.pn, 35             ; <i1> [#uses=0]


@gsm_DLB = internal constant [4 x i16] [i16 6554, i16 16384, i16 26214, i16 32767]
%scevgep.i = getelementptr [4 x i16]* @gsm_DLB, i64 0, i64 %indvar.i ; <i16*> [#uses=1]
%425 = load %scevgep.i
%426 = icmp eq i16 %425, -32768                 ; <i1> [#uses=0]
-> false

llvm-svn: 92411
2010-01-02 08:12:04 +00:00
Chris Lattner
cf784992da remove the instcombine transformations that are inserting nasty
pointer to int casts that confuse later optimizations.  See PR3351
for details.

This improves but doesn't complete fix 483.xalancbmk because llvm-gcc
does this xform in GCC's "fold" routine as well.  Clang++ will do
better I guess.

llvm-svn: 92408
2010-01-02 00:31:05 +00:00
Chris Lattner
ef4fba933d add a simple instcombine xform, simplify another one to use hasAllZeroIndices()
instead of hand rolling a loop.

llvm-svn: 92403
2010-01-01 23:09:08 +00:00
Chris Lattner
feb7b1af69 generalize the pointer difference optimization to handle
a constantexpr gep on the 'base' side of the expression.
This completes comment #4 in PR3351, which comes from
483.xalancbmk.

llvm-svn: 92402
2010-01-01 22:42:29 +00:00
Chris Lattner
89b1b63bdf teach instcombine to optimize pointer difference idioms involving constant
expressions.  This is a step towards comment #4 in PR3351.

llvm-svn: 92401
2010-01-01 22:29:12 +00:00
Chris Lattner
de358b45b6 use 'match' to simplify some code.
llvm-svn: 92400
2010-01-01 22:12:03 +00:00
Chris Lattner
ce7717e168 implement the transform requested in PR5284
llvm-svn: 92398
2010-01-01 18:34:40 +00:00
Chris Lattner
6d58c7dd39 add missing line.
llvm-svn: 92384
2010-01-01 01:54:08 +00:00
Chris Lattner
e5f5e4b151 add a few trivial instcombines for llvm.powi.
llvm-svn: 92383
2010-01-01 01:52:15 +00:00
Chris Lattner
662a872e15 When factoring multiply expressions across adds, factor both
positive and negative forms of constants together.  This 
allows us to compile:

int foo(int x, int y) {
    return (x-y) + (x-y) + (x-y);
}

into:

_foo:                                                       ## @foo
	subl	%esi, %edi
	leal	(%rdi,%rdi,2), %eax
	ret

instead of (where the 3 and -3 were not factored):

_foo:
        imull   $-3, 8(%esp), %ecx
        imull   $3, 4(%esp), %eax
        addl    %ecx, %eax
        ret

this started out as:
    movl    12(%ebp), %ecx
    imull   $3, 8(%ebp), %eax
    subl    %ecx, %eax
    subl    %ecx, %eax
    subl    %ecx, %eax
    ret

This comes from PR5359.

llvm-svn: 92381
2010-01-01 01:13:15 +00:00
Chris Lattner
4a56803f29 clean up some comments.
llvm-svn: 92377
2010-01-01 00:04:26 +00:00
Chris Lattner
8812fc68ee switch from std::map to DenseMap for rank data structures.
llvm-svn: 92375
2010-01-01 00:01:34 +00:00
Chris Lattner
ebe5932016 reuse negates where possible instead of always creating them from scratch.
This allows us to optimize test12 into:

define i32 @test12(i32 %X) {
  %factor = mul i32 %X, -3                        ; <i32> [#uses=1]
  %Z = add i32 %factor, 6                         ; <i32> [#uses=1]
  ret i32 %Z
}

instead of:

define i32 @test12(i32 %X) {
  %Y = sub i32 6, %X                              ; <i32> [#uses=1]
  %C = sub i32 %Y, %X                             ; <i32> [#uses=1]
  %Z = sub i32 %C, %X                             ; <i32> [#uses=1]
  ret i32 %Z
}

llvm-svn: 92373
2009-12-31 20:34:32 +00:00
Chris Lattner
bdf261d481 we don't need a smallptrset to detect duplicates, the values are
sorted, so we can just do a linear scan.

llvm-svn: 92372
2009-12-31 19:49:01 +00:00
Chris Lattner
5551708ece make reassociate more careful about not leaving around dead mul's
llvm-svn: 92370
2009-12-31 19:34:45 +00:00
Chris Lattner
0e3d1bade8 remove debug
llvm-svn: 92369
2009-12-31 19:25:19 +00:00
Chris Lattner
59379f8bb0 teach reassociate to factor x+x+x -> x*3. While I'm at it,
fix RemoveDeadBinaryOp to actually do something.

llvm-svn: 92368
2009-12-31 19:24:52 +00:00
Chris Lattner
333b35d45e change reassociate to use SmallVector for its key datastructures
instead of std::vector.

llvm-svn: 92366
2009-12-31 18:40:32 +00:00
Chris Lattner
0c384066c0 change an if to an assert, fix comment.
llvm-svn: 92364
2009-12-31 18:18:46 +00:00
Chris Lattner
e8cca9664a move the rest of the add optimization code out to OptimizeAdd,
improve some comments, simplify a bit of code.

llvm-svn: 92363
2009-12-31 18:17:13 +00:00
Chris Lattner
236f281971 factor statistic updating better.
llvm-svn: 92362
2009-12-31 17:51:05 +00:00
Chris Lattner
4870f6a384 simple fix for an incorrect factoring which causes a
miscompilation, PR5458.

llvm-svn: 92354
2009-12-31 08:33:49 +00:00
Chris Lattner
d8516bddb2 factor code out into helper functions.
llvm-svn: 92347
2009-12-31 07:59:34 +00:00
Chris Lattner
b4d616f2d4 switch some std::vector's to smallvector. Reduce nesting.
llvm-svn: 92346
2009-12-31 07:48:51 +00:00
Chris Lattner
fe111bf087 use more modern datastructures.
llvm-svn: 92344
2009-12-31 07:33:14 +00:00
Chris Lattner
3ebdd96db7 clean up -debug output.
llvm-svn: 92343
2009-12-31 07:17:37 +00:00
Chris Lattner
ecba817b0e fix Analysis/DebugInfo.h to not include Metadata.h. Do this
by moving one method out of line and eliminating redundant checks
from other methods.

llvm-svn: 92337
2009-12-31 03:02:08 +00:00
Chris Lattner
c12382b7c8 rename "elements" of metadata to "operands". "Elements" are
things that occur in types.  "operands" are things that occur
in values.

llvm-svn: 92322
2009-12-31 01:22:29 +00:00
Benjamin Kramer
e59de5e9b0 Use an array instead of a SmallVector.
llvm-svn: 92264
2009-12-29 11:04:52 +00:00
Chris Lattner
31895ba512 prune #includes.
llvm-svn: 92260
2009-12-29 09:12:29 +00:00
Chris Lattner
84e9de4a58 Final step in the metadata API restructuring: move the
getMDKindID/getMDKindNames methods to LLVMContext (and add
convenience methods to Module), eliminating MetadataContext.
Move the state that it maintains out to LLVMContext.

llvm-svn: 92259
2009-12-29 09:01:33 +00:00
Chris Lattner
a78c161348 remove useless argument.
llvm-svn: 92256
2009-12-29 08:03:58 +00:00
Chris Lattner
9ec640a902 This is a major cleanup of the instruction metadata interfaces that
I asked Devang to do back on Sep 27.  Instead of going through the
MetadataContext class with methods like getMD() and getMDs(), just
ask the instruction directly for its metadata with getMetadata()
and getAllMetadata().

This includes a variety of other fixes and improvements: previously
all Value*'s were bloated because the HasMetadata bit was thrown into
value, adding a 9th bit to a byte.  Now this is properly sunk down to
the Instruction class (the only place where it makes sense) and it
will be folded away somewhere soon.

This also fixes some confusion in getMDs and its clients about 
whether the returned list is indexed by the MDID or densely packed.
This is now returned sorted and densely packed and the comments make
this clear.

This introduces a number of fixme's which I'll follow up on.

llvm-svn: 92235
2009-12-28 23:41:32 +00:00
Chris Lattner
e0b9847223 split code that doesn't need to be templated out of IRBuilder into a new
non-templated IRBuilderBase class.  Move that large CreateGlobalString
out of line, eliminating the need to #include GlobalVariable.h in IRBuilder.h

llvm-svn: 92227
2009-12-28 21:28:46 +00:00
Chris Lattner
cd3aa9d1ff rename getMDKind -> getMDKindID, make it autoinsert if an MD Kind
doesn't exist already, eliminate registerMDKind.  Tidy up a bunch
of random stuff.

llvm-svn: 92225
2009-12-28 20:45:51 +00:00
Chris Lattner
6dd4686b48 Metadata.h doesn't need to include ValueHandle.h anymore.
llvm-svn: 92211
2009-12-28 08:20:46 +00:00
Chris Lattner
5d3919d5f9 move an optimization for memcmp out of simplifylibcalls and into
SDISel.  This optimization was causing simplifylibcalls to 
introduce type-unsafe nastiness.  This is the first step, I'll be 
expanding the memcmp optimizations shortly, covering things that
we really really wouldn't want simplifylibcalls to do.

llvm-svn: 92098
2009-12-24 00:37:38 +00:00
Chris Lattner
7dbb93e430 reorder to follow a normal fall-through style, no functionality change.
llvm-svn: 92084
2009-12-23 23:24:51 +00:00
David Greene
1b160211dd Remove dump routine and the associated Debug.h from a header. Patch up
other files to compensate.

llvm-svn: 92075
2009-12-23 22:58:38 +00:00
Eric Christopher
ce677a909d Update objectsize intrinsic and associated dependencies. Fix
lowering code and update testcases.

llvm-svn: 91979
2009-12-23 02:51:48 +00:00
Chris Lattner
4a7bce50b8 Fix the Convert to scalar to not insert dead loads in the store case. The
load is needed when we have a small store into a large alloca (at which 
point we get a load/insert/store sequence), but when you do a full-sized
store, this load ends up being dead.

This dead load is bad in really large nasty testcases where the load ends
up causing mem2reg to insert large chains of dependent phi nodes which only
ADCE can delete.  Instead of doing this, just don't insert the dead load.

This fixes rdar://6864035

llvm-svn: 91917
2009-12-22 19:33:28 +00:00
Chris Lattner
0fbb62fcc5 fix some fixme's by using twines
llvm-svn: 91916
2009-12-22 19:23:33 +00:00
Bob Wilson
0dc93264b1 Generalize SROA to allow the first index of a GEP to be non-zero. Add a
missing check that an array reference doesn't go past the end of the array,
and remove some redundant checks for in-bound array and vector references
that are no longer needed.

llvm-svn: 91897
2009-12-22 06:57:14 +00:00
Chris Lattner
4e30207029 Implement PR5795 by merging duplicated return blocks. This could go further
by merging all returns in a function into a single one, but simplifycfg 
currently likes to duplicate the return (an unfortunate choice!)

llvm-svn: 91890
2009-12-22 06:07:30 +00:00
Chris Lattner
cd79ebb23c The phi translated pointer can be computed when returning a partially cached result
instead of stored.  This reduces memdep memory usage, and also eliminates a bunch of
weakvh's.  This speeds up gvn on gcc.c-torture/20001226-1.c from 23.9s to 8.45s (2.8x)
on a different machine than earlier.

llvm-svn: 91885
2009-12-22 04:25:02 +00:00
Eric Christopher
c1b128aa04 Whitespace fixes.
llvm-svn: 91875
2009-12-22 01:23:51 +00:00
Daniel Dunbar
8efbce934e Add suggested parentheses.
llvm-svn: 91853
2009-12-21 23:27:57 +00:00
Chris Lattner
8bd3f74d82 Add a fastpath to Load GVN to special case when we have exactly one dominating
load to avoid even messing around with SSAUpdate at all.  In this case (which
is very common, we can just use the input value directly).

This speeds up GVN time on gcc.c-torture/20001226-1.c from 36.4s to 16.3s,
which still isn't great, but substantially better and this is a simple speedup
that applies to lots of different cases.

llvm-svn: 91851
2009-12-21 23:15:48 +00:00
Chris Lattner
41cad2092d refactor some code out to a new helper method.
llvm-svn: 91849
2009-12-21 23:04:33 +00:00
Chris Lattner
1cbad45619 improve indentation avoid a pointless conversion from weakvh to trackingvh,
no functionality change.

llvm-svn: 91848
2009-12-21 22:43:03 +00:00
Bob Wilson
eb77079db5 Remove special-case SROA optimization of variable indexes to one-element and
two-element arrays.  After restructuring the SROA code, it was not safe to
do this without adding more checking.  It is not clear that this special-case
has really been useful, and removing this simplifies the code quite a bit.

llvm-svn: 91828
2009-12-21 18:39:47 +00:00
Chris Lattner
cd9fb503c8 revert r89298, which was committed without a testcase. I think
the underlying PHI node insertion issue in SSAUpdate is fixed.

llvm-svn: 91821
2009-12-21 07:45:57 +00:00
Chris Lattner
c54fd1e777 fix PR5837 by having SSAUpdate reuse phi nodes for the
'GetValueInMiddleOfBlock' case, instead of inserting 
duplicates.

A similar fix is almost certainly needed by the machine-level
SSAUpdate implementation.

llvm-svn: 91820
2009-12-21 07:16:11 +00:00
Chris Lattner
c9bfe8679e give instcombine some helper functions for matching MIN and MAX, and
implement some optimizations for MIN(MIN()) and MAX(MAX()) and 
MIN(MAX()) etc.  This substantially improves the code in PR5822 but
doesn't kick in much elsewhere.  2 max's were optimized in 
pairlocalalign and one in smg2000.

llvm-svn: 91814
2009-12-21 06:03:05 +00:00
Chris Lattner
f1474e1761 enhance x-(-A) -> x+A to preserve NUW/NSW.
Use the presence of NSW/NUW to fold "icmp (x+cst), x" to a constant in
cases where it would otherwise be undefined behavior.

Surprisingly (to me at least), this triggers hundreds of the times in
a few benchmarks: lencode, ldecode, and 466.h264ref seem to *really*
like this.

llvm-svn: 91812
2009-12-21 04:04:05 +00:00
Chris Lattner
d34eb29977 Optimize all cases of "icmp (X+Cst), X" to something simpler. This triggers
a bunch in lencode, ldecod, spass, 176.gcc, 252.eon, among others.  It is 
also the first part of PR5822

llvm-svn: 91811
2009-12-21 03:19:28 +00:00
Douglas Gregor
f39dd74a3f Fix a bunch of little errors that Clang complains about when its being pedantic
llvm-svn: 91764
2009-12-19 07:05:23 +00:00
Chris Lattner
d9bf69f1a5 fix PR5827 by disabling the phi slicing transformation in a case
where instcombine would have to split a critical edge due to a
phi node of an invoke.  Since instcombine can't change the CFG,
it has to bail out from doing the transformation.

llvm-svn: 91763
2009-12-19 07:01:15 +00:00
Bob Wilson
067a1be3e9 Update my SROA changes in response to review.
* change FindElementAndOffset to return a uint64_t instead of unsigned, and
  to identify the type to be used for that result in a GEP instruction.
* move "isa<ConstantInt>" to be first in conditional.
* replace some dyn_casts with casts.
* add a comment about handling mem intrinsics.

llvm-svn: 91762
2009-12-19 06:53:17 +00:00
Bob Wilson
03b6955c7f Reapply 91459 with a simple fix for the problem that broke the x86_64-darwin
bootstrap.  This also replaces the WeakVH references that Chris objected to
with normal Value references.

llvm-svn: 91711
2009-12-18 20:14:40 +00:00
Eli Friedman
c8ab298dbd Optimize icmp of null and select of two constants even if the select has
multiple uses.  (The construct in question was found in gcc.)

llvm-svn: 91675
2009-12-18 08:22:35 +00:00
Dan Gohman
87a4da3d59 Eliminte unnecessary uses of <cstdio>.
llvm-svn: 91666
2009-12-18 03:25:51 +00:00
Dan Gohman
0f8f7f179d Add Loop contains utility methods for testing whether a loop
contains another loop, or an instruction. The loop form is
substantially more efficient on large loops than the typical
code it replaces.

llvm-svn: 91654
2009-12-18 01:24:09 +00:00
Dan Gohman
66a17c5ce2 Minor code simplification.
llvm-svn: 91653
2009-12-18 01:20:44 +00:00
Dan Gohman
3ea233d1f2 Don't pass const pointers by reference.
llvm-svn: 91647
2009-12-18 00:38:08 +00:00
Dan Gohman
dcf5423e51 Update a comment.
llvm-svn: 91645
2009-12-18 00:28:43 +00:00
Dan Gohman
c483bed5e8 Reapply LoopStrengthReduce and IVUsers cleanups, excluding the part
of 91296 that caused trouble -- the Processed list needs to be
preserved for the livetime of the pass, as AddUsersIfInteresting
is called from other passes.

llvm-svn: 91641
2009-12-18 00:06:20 +00:00
Eli Friedman
9543d05079 Allow instcombine to combine "sext(a) >u const" to "a >u trunc(const)".
llvm-svn: 91631
2009-12-17 22:42:29 +00:00
Eli Friedman
8afea2d095 Make the ptrtoint comparison simplification work if one side is a global.
llvm-svn: 91624
2009-12-17 21:27:47 +00:00
Eli Friedman
ff5c248066 Slightly generalize transformation of memmove(a,a,n) so that it also applies
to memcpy. (Such a memcpy is technically illegal, but in practice is safe
and is generated by struct self-assignment in C code.)

llvm-svn: 91621
2009-12-17 21:07:31 +00:00
Bob Wilson
9d4b46c0e6 Re-revert 91459. It's breaking the x86_64 darwin bootstrap.
llvm-svn: 91607
2009-12-17 18:34:24 +00:00
Evan Cheng
18e334195d Revert 91280-91283, 91286-91289, 91291, 91293, 91295-91296. It apparently introduced a non-deterministic behavior in the optimizer somewhere.
llvm-svn: 91598
2009-12-17 09:39:49 +00:00
Daniel Dunbar
c4abbc0ab6 Reapply r91459, it was only unmasking the bug, and since TOT is still broken having it reverted does no good.
llvm-svn: 91559
2009-12-16 20:09:53 +00:00
Daniel Dunbar
929f303477 Revert "Reapply 91184 with fixes and an addition to the testcase to cover the
problem", this broke llvm-gcc bootstrap for release builds on
x86_64-apple-darwin10.

This reverts commit db22309800b224a9f5f51baf76071d7a93ce59c9.

llvm-svn: 91534
2009-12-16 10:56:17 +00:00
Chris Lattner
2d5fc1649a reapply my strstr optimization. I have reproduced the x86-64 bootstrap
miscompile (i386.o miscompares) but it happens both with and without
this patch.

llvm-svn: 91532
2009-12-16 09:32:05 +00:00
Chris Lattner
8751050a34 revert my strstr optimization, I'm told it breaks x86-64 bootstrap.
Will reapply with a fix when I get a chance.

llvm-svn: 91486
2009-12-16 00:46:02 +00:00
Bob Wilson
8505aa648d Reapply 91184 with fixes and an addition to the testcase to cover the problem
found last time.  Instead of trying to modify the IR while iterating over it,
I've change it to keep a list of WeakVH references to dead instructions, and
then delete those instructions later.  I also added some special case code to
detect and handle the situation when both operands of a memcpy intrinsic are
referencing the same alloca.

llvm-svn: 91459
2009-12-15 22:00:51 +00:00
Chris Lattner
fa960751b1 optimize strstr, PR5783
llvm-svn: 91438
2009-12-15 19:14:40 +00:00
Dan Gohman
a1003e40f7 Delete an unused function.
llvm-svn: 91432
2009-12-15 16:30:09 +00:00
Chris Lattner
284fe3f14c add some other xforms that should be done as part of PR5783
llvm-svn: 91428
2009-12-15 09:05:13 +00:00
Chris Lattner
587962c667 Remove isPod() from DenseMapInfo, splitting it out to its own
isPodLike type trait.  This is a generally useful type trait for
more than just DenseMap, and we really care about whether something
acts like a pod, not whether it really is a pod.

llvm-svn: 91421
2009-12-15 07:26:43 +00:00
Dan Gohman
abb2ea84d9 Fix a thinko; isNotAlreadyContainedIn had a built-in negative, so the
condition was inverted when the code was converted to contains().

llvm-svn: 91295
2009-12-14 17:31:01 +00:00
Dan Gohman
ea5d4d2354 Remove unnecessary #includes.
llvm-svn: 91293
2009-12-14 17:19:06 +00:00
Dan Gohman
5066c25e62 Instead of having a ScalarEvolution pointer member in BasedUser, just pass
the ScalarEvolution pointer into the functions which need it.

llvm-svn: 91289
2009-12-14 17:12:51 +00:00
Dan Gohman
b001599b67 Don't bother cleaning up if there's nothing to clean up.
llvm-svn: 91288
2009-12-14 17:10:44 +00:00
Dan Gohman
178e26adbf Delete an unused variable.
llvm-svn: 91287
2009-12-14 17:08:09 +00:00