1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 03:53:04 +02:00
Commit Graph

5478 Commits

Author SHA1 Message Date
Dan Gohman
49c397bf4b Minor code simplification.
llvm-svn: 74491
2009-06-30 01:24:43 +00:00
Dan Gohman
28702fab4e Don't try to split a loop when the controlling icmp instruction
doesn't have an IV-based operand. This fixes PR4471.

llvm-svn: 74399
2009-06-27 22:58:27 +00:00
Dan Gohman
fcd5eedead Remove the block from the LoopInfo, rather than just the Loop.
LoopInfo will handle removing it from the Loop, as well as updating
its own tables.

llvm-svn: 74398
2009-06-27 22:32:36 +00:00
Dan Gohman
8d2a45fadb Teach LoopSimplify how to merge multiple loop exits into a single exit,
when one of them can be converted to a trivial icmp and conditional
branch.

This addresses what is essentially a phase ordering problem.
SimplifyCFG knows how to do this transformation, but it doesn't do so
if the primary block has any instructions in it other than an icmp and
a branch. In the given testcase, the block contains other instructions,
however they are loop-invariant and can be hoisted. SimplifyCFG doesn't
have LoopInfo though, so it can't hoist them. And, it's important that
the blocks be merged before LoopRotation, as it doesn't support
multiple-exit loops.

llvm-svn: 74396
2009-06-27 21:30:38 +00:00
Dan Gohman
a753bd44ff More minor code simplifications.
llvm-svn: 74395
2009-06-27 21:23:40 +00:00
Dan Gohman
4acfd5098d When a value is used multiple times within a single PHI, instructions
inserted to replace that value must dominate all of of the basic
blocks associated with the uses of the value in the PHI, not just
one of them.

llvm-svn: 74376
2009-06-27 05:16:57 +00:00
Dan Gohman
4f74e815f1 Incorporate the insertion point into the key of SCEVExpander's CSE map.
This helps it avoid reusing an instruction that doesn't dominate all
of the users, in cases where the original instruction was inserted
before all of the users were known.  This may result in redundant
expansions of sub-expressions that depend on loop-unpredictable values
in some cases, however this isn't very common, and it primarily impacts
IndVarSimplify, so GVN can be expected to clean these up.

This eliminates the need for IndVarSimplify's FixUsesBeforeDefs,
which fixes several bugs.

llvm-svn: 74352
2009-06-26 22:53:46 +00:00
Devang Patel
4f5d296df0 Remove unused routines.
llvm-svn: 74351
2009-06-26 22:53:22 +00:00
Owen Anderson
2bcd131128 Constify this value.
llvm-svn: 74330
2009-06-26 21:39:56 +00:00
Douglas Gregor
6d9b0e8c19 Fix linking of llvm-ld and lli with CMake, from Xerxes Rånby
llvm-svn: 74285
2009-06-26 15:37:00 +00:00
Devang Patel
84a8914a4a Remove debug info anchors - llvm.dbg.compile_units, llvm.dbg.subprograms
and llvm.dbg.global_variables.

llvm-svn: 74251
2009-06-26 01:49:18 +00:00
Dan Gohman
71b1c43d91 Change this code to a form about which VC++ reportedly isn't unhappy.
llvm-svn: 74243
2009-06-26 00:35:12 +00:00
Dan Gohman
ba8760719f Fix LCSSA to avoid emitting a PHI node for the unwind destination of
an invoke instruction, since the value isn't really live across that
edge.

llvm-svn: 74242
2009-06-26 00:31:13 +00:00
Dan Gohman
3983d5070b Minor code simplification.
llvm-svn: 74240
2009-06-26 00:26:03 +00:00
Dan Gohman
68902a1ad2 Reword a few comments.
llvm-svn: 74146
2009-06-25 00:22:44 +00:00
Dan Gohman
c2c1e1ff38 When inserting code into a loop preheader, insert it before the
terminator, instead of after the last phi. This fixes a bug
exposed by ScalarEvolution analyzing more kinds of loops.
This fixes PR4436.

llvm-svn: 74072
2009-06-24 14:31:06 +00:00
Dan Gohman
4f4bda36df Extend ScalarEvolution's multiple-exit support to compute exact
trip counts in more cases.

Generalize ScalarEvolution's isLoopGuardedByCond code to recognize
And and Or conditions, splitting the code out into an
isNecessaryCond helper function so that it can evaluate Ands and Ors
recursively, and make SCEVExpander be much more aggressive about
hoisting instructions out of loops.

test/CodeGen/X86/pr3495.ll has an additional instruction now, but
it appears to be due to an arbitrary register allocation difference.

llvm-svn: 74048
2009-06-24 01:18:18 +00:00
Dan Gohman
1eb6954545 Don't emit a redundant BitCastInst if the value to be defined in the
preheader is already an instruction.

llvm-svn: 74031
2009-06-24 00:28:59 +00:00
Dan Gohman
b4f58ad636 Fix a few minor issues that were exposed by the removal of SCEVHandle.
llvm-svn: 73910
2009-06-22 22:08:45 +00:00
Owen Anderson
c023151c9f SCEVHandle is no more!
llvm-svn: 73906
2009-06-22 21:39:50 +00:00
Dan Gohman
8426522d55 Fix this code to correctly handle loops with multiple exits. Until
now, this hasn't mattered, because ScalarEvolution hasn't been able
to compute trip counts for loops with multiple exits. But it will
soon.

llvm-svn: 73864
2009-06-22 00:15:15 +00:00
Dan Gohman
1a33c92bb2 Rename a variable for consistency with the ExitBlock vs ExitingBlock
terminology that LoopInfo uses.

llvm-svn: 73863
2009-06-21 23:48:38 +00:00
Dan Gohman
a81541945b Fix a typo in a comment that Frits von Bommel noticed.
llvm-svn: 73796
2009-06-19 23:41:37 +00:00
Dan Gohman
651faa1905 Re-apply r73718, now that the fix in r73787 is in, and add a
hand-crafted testcase which demonstrates the bug that was exposed
in 254.gap.

llvm-svn: 73793
2009-06-19 23:23:27 +00:00
Dan Gohman
9bd151655f Fix LSR's OptimizeSMax to ignore max operators with more than 2 operands,
which it isn't prepared to handle.

llvm-svn: 73787
2009-06-19 23:03:46 +00:00
Evan Cheng
b90241ac42 Revert 73718. It's breaking 254.gap.
llvm-svn: 73783
2009-06-19 21:15:06 +00:00
Chris Lattner
8f6f044afd make jump threading handle lexically identical compare instructions
as if they were multiple uses of the same instruction.  This interacts
well with the existing loadpre that j-t does to open up many new jump
threads earlier.

llvm-svn: 73768
2009-06-19 16:27:56 +00:00
Nick Lewycky
a5f89b09c6 Teach jump threading to look at comparisons between phi nodes and non-constants.
llvm-svn: 73755
2009-06-19 04:56:29 +00:00
Chris Lattner
8ddc06469c Improve tail call elim to move loads above readonly calls
when it allows forming a tail call.  Patch by Frits van
Bommel.  This implements PR4323.

llvm-svn: 73752
2009-06-19 04:22:16 +00:00
Chris Lattner
3a683c551f part of PR4405: disable a contentious optimization for
strcmp -> memcmp when the lengths of the strings are unknown.

Patch by Nick Lewycky!

llvm-svn: 73751
2009-06-19 04:17:36 +00:00
Dan Gohman
da82dc2ec1 Generalize LSR's OptimizeSMax to handle unsigned max tests as well
as signed max tests. Along with r73717, this helps CodeGen avoid
emitting code for a maximum operation for this class of loop.

llvm-svn: 73718
2009-06-18 20:23:18 +00:00
Anton Korobeynikov
fed9dcc88c Revert IRBuilder CC propagation. Fix SimplifyLibCalls instead.
llvm-svn: 73715
2009-06-18 20:05:31 +00:00
Dan Gohman
fd857b0406 Remove the code from IVUsers that attempted to handle
casted induction variables in cases where the cast
isn't foldable. It ended up being a pessimization in
many cases. This could be fixed, but it would require
a bunch of complicated code in IVUsers' clients. The
advantages of this approach aren't visible enough to
justify it at this time.

llvm-svn: 73706
2009-06-18 16:54:06 +00:00
Dan Gohman
dc884a7830 Generalize the zext(trunc(t) & C) instcombine to work even with
C is not a low-bits mask, and add a similar instcombine for
zext((trunc(t) & C) ^ C).

llvm-svn: 73705
2009-06-18 16:30:21 +00:00
Dan Gohman
1530824138 Instcombine zext(trunc(x) & mask) to x&mask, even if the trunc has
multiple users.

llvm-svn: 73656
2009-06-17 23:17:05 +00:00
Dale Johannesen
26f0dd9021 This fixes a bug introduced in 72661, which can
move loads back past a check that the load address
is valid, see new testcase.  The test that went
in with 72661 has exactly this case, except that
the conditional it's moving past is checking
something else; I've settled for changing that
test to reference a global, not a pointer.  It
may be possible to scan all the tests you pass and
make sure none of them are checking any component
of the address, but it's not trivial and I'm not
trying to do that here.

llvm-svn: 73632
2009-06-17 20:48:23 +00:00
Torok Edwin
09a9b85420 Add debug message about non-local loads being clobbered.
llvm-svn: 73625
2009-06-17 18:48:18 +00:00
Dan Gohman
c7dfa0d7c0 Update comments to use doxygen syntax.
llvm-svn: 73621
2009-06-17 17:51:33 +00:00
Sanjiv Gupta
6d9a123c1d >> What if my global variable was into a different address space than stack?
>>     
>
> It doesn't matter in terms of semantics: because AnalyzeGlobal
> returned false, we're guaranteed the address of the global is never
> taken.  I wouldn't be surprised if we end up generating invalid IR in
> some cases, though, because of the semantics of replaceAllUsesWith.
> Do you have a testcase that breaks?
>
>   
The problem is replaceAllUsesWith asserts for type mismatch here. Try attached .bc with llvm-ld.

assert(New->getType() == getType() &&
        "replaceAllUses of value with new value of different type!");

Since stack is always on address space zero, I don't think that type of GV in a different address space is ever going to match.
The other way is to allow replaceAllUsesWith to ignore address spaces while comparing types. (do we have  a way to do that ?).
But then such an optimization may fail the entire idea of user wanting to place a variable into different memory space. The original idea of user might be to save on the stack space (data memory) and hence he asked the variable to be placed into different memory space (program memory). So the best bet here is to deny this optimization by checking

GV->getType()->getAddressSpace() == 0. 

llvm-svn: 73605
2009-06-17 06:47:15 +00:00
Eli Friedman
b3947071ff PR3439: Correct a silly mistake in the SimplifyDemandedUseBits code for
SRem.

llvm-svn: 73598
2009-06-17 02:57:36 +00:00
Dan Gohman
54bbef1525 Generalize a few more instcombines to be vector/scalar-independent.
llvm-svn: 73541
2009-06-16 19:55:29 +00:00
Chris Lattner
574c5de9f8 Generalize instcombine's isSafeToLoadUnconditionally() function
to ignore readonly calls, and factor it out of instcombine so
that it can be used by other passes.  Patch by Frits van Bommel!

llvm-svn: 73506
2009-06-16 17:23:12 +00:00
Dan Gohman
992bf87a6f Use Type::getScalarType.
llvm-svn: 73451
2009-06-16 00:20:26 +00:00
Dan Gohman
2e737ac21f Support vector casts in more places, fixing a variety of assertion
failures.

To support this, add some utility functions to Type to help support
vector/scalar-independent code. Change ConstantInt::get and
ConstantFP::get to support vector types, and add an overload to
ConstantInt::get that uses a static IntegerType type, for
convenience.

Introduce a new getConstant method for ScalarEvolution, to simplify
common use cases.

llvm-svn: 73431
2009-06-15 22:12:54 +00:00
Dale Johannesen
2d0be306fb Fix the crash in this test. This is basically the same
problem addressed in 31284, but the patch there only
addressed the case where an invoke is the first thing in
a block.

llvm-svn: 73416
2009-06-15 20:59:27 +00:00
Owen Anderson
9a8f02a7d5 Merge PartialInliner changes.
llvm-svn: 73412
2009-06-15 20:50:26 +00:00
Dan Gohman
59c4088e16 Make the EnableLoadPRE variable static.
llvm-svn: 73398
2009-06-15 18:30:15 +00:00
Dan Gohman
111f127d23 Fix old-style type names in comments.
llvm-svn: 73362
2009-06-14 23:30:43 +00:00
Dan Gohman
d895ed43c8 Convert several parts of the ScalarEvolution framework to use
SmallVector instead of std::vector.

llvm-svn: 73357
2009-06-14 22:47:23 +00:00
Dan Gohman
973025e678 Add another item to the list of things that indvars does.
llvm-svn: 73355
2009-06-14 22:38:41 +00:00
Torok Edwin
6240e2ef53 Fix CMake build. Patch from Ingmar Vanhassel.
llvm-svn: 73342
2009-06-14 13:39:56 +00:00
Owen Anderson
6aa3d83630 Add an early implementation of a partial inlining pass. The idea behind this
is that, for functions whose bodies are entirely guarded by an if-statement, it
can be profitable to pull the test out of the callee and into the caller.

This code has had some cursory testing, but still has a number of known issues
on the LLVM test suite.

llvm-svn: 73338
2009-06-14 08:26:32 +00:00
Nick Lewycky
e74c3c6d46 Unlike the other instructions, GEP really does need to look at the type of a
pointer. This fixes kimwitu++. Pointed out by Frits van Bommel on review!

llvm-svn: 73299
2009-06-13 19:09:52 +00:00
Dan Gohman
37fef35e88 Teach SCEVExpander's visitAddRecExpr to reuse an existing canonical
induction variable when the addrec to be expanded does not require
a wider type. This eliminates the need for IndVarSimplify to
micro-manage SCEV expansions, because SCEVExpander now
automatically expands them in the form that IndVarSimplify considers
to be canonical. (LSR still micro-manages its SCEV expansions,
because it's optimizing for the target, rather than for
other optimizations.)

Also, this uses the new getAnyExtendExpr, which has more clever
expression simplification logic than the IndVarSimplify code it
replaces, and this cleans up some ugly expansions in code such as
the included masked-iv.ll testcase.

llvm-svn: 73294
2009-06-13 16:25:49 +00:00
Chris Lattner
75c88a3730 second half of fix for PR4366: don't zap store to null of
non-default addrspaces.

llvm-svn: 73253
2009-06-12 21:01:07 +00:00
Dan Gohman
f9b0419cd8 Don't do (x - (y - z)) --> (x + (z - y)) on floating-point types, because
it may round differently. This fixes PR4374.

llvm-svn: 73243
2009-06-12 19:23:25 +00:00
Dan Gohman
43f66023c3 Give Instruction::isSameOperationAs a corresponding comment to note
the relationship with MergeFunctions.cpp's isEquivalentOperation,
and make a trivial code reordering so that the two functions are
easier to compare.

Fix the name of Instruction::isSameOperationAs in MergeFunction.cpp's
isEquivalentOperation's comment, and fix a nearby 80-column violation.

llvm-svn: 73241
2009-06-12 19:03:05 +00:00
Nick Lewycky
32fec8ff24 Keep callers of a weak function calling it, instead of the non-weak equivalent.
llvm-svn: 73235
2009-06-12 17:16:48 +00:00
Nick Lewycky
effec6b472 Don't forget to match the calling convention when producing a thunk.
llvm-svn: 73231
2009-06-12 16:04:00 +00:00
Nick Lewycky
1e36649f95 Given two identical weak functions, produce one internal function and two weak
thunks.

llvm-svn: 73230
2009-06-12 15:56:56 +00:00
Nick Lewycky
5b80791480 Add an "are types equivalent" operation that ignores the types that a pointer
points to while analyzing all other fields.

Use FoldingSetNodeID to produce a good hash. This dramatically decreases run
times.

Emit thunks. This means that it can look at all functions regardless of what
the linkage is or if the address is taken, but unfortunately some small
functions can be even shorter than the thunk because our backend doesn't yet
realize it can just turn these into jumps. This means that this pass will
pessimize code on average.

llvm-svn: 73222
2009-06-12 08:04:51 +00:00
Chris Lattner
e0360f8ae8 Fix 4366: store to null in non-default addr space should not be
turned into unreachable.

llvm-svn: 73195
2009-06-11 17:54:56 +00:00
Jay Foad
5affd7b2c9 Implement and use new method Function::hasAddressTaken().
llvm-svn: 73164
2009-06-10 08:41:11 +00:00
Jay Foad
209162fd09 Remove an unused function SafeToDestroyConstant(). Rename an almost
identical function ConstantIsDead() to SafeToDestroyConstant(), to
emphasise the connection with Constant::destroyConstant().

llvm-svn: 73149
2009-06-09 21:37:11 +00:00
Nick Lewycky
1a54547335 Don't crash on multiple return value with no obvious inserted value.
Fixes PR4314.

llvm-svn: 73007
2009-06-06 23:13:08 +00:00
Eli Friedman
770f633389 PR4340: Run SimplifyDemandedVectorElts on insertelement instructions;
sometimes it can find simplifications that won't be found otherwise.

llvm-svn: 73006
2009-06-06 20:08:03 +00:00
Jay Foad
a442a46de9 Use cast<> instead of dyn_cast<> for things that are known to be
Instructions.

llvm-svn: 73002
2009-06-06 17:49:35 +00:00
Devang Patel
17bb9f4649 Simplify.
llvm-svn: 72965
2009-06-05 22:39:21 +00:00
Dan Gohman
5f6f8101d5 Split the Add, Sub, and Mul instruction opcodes into separate
integer and floating-point opcodes, introducing
FAdd, FSub, and FMul.

For now, the AsmParser, BitcodeReader, and IRBuilder all preserve
backwards compatability, and the Core LLVM APIs preserve backwards
compatibility for IR producers. Most front-ends won't need to change
immediately.

This implements the first step of the plan outlined here:
http://nondot.org/sabre/LLVMNotes/IntegerOverflow.txt

llvm-svn: 72897
2009-06-04 22:49:04 +00:00
Dan Gohman
882851fe9f Don't do the X * 0.0 -> 0.0 transformation in instcombine, because
instcombine doesn't know when it's safe. To partially compensate
for this, introduce new code to do this transformation in
dagcombine, which can use UnsafeFPMath.

llvm-svn: 72872
2009-06-04 17:12:12 +00:00
Dan Gohman
6e9ad19ef7 Don't attempt to simplify an non-affine IV expression if it can't
be simplified to a loop-invariant value. This fixes PR4315.

llvm-svn: 72798
2009-06-03 19:11:31 +00:00
Dan Gohman
f6e6588203 Fix CodeGenPrepare's address-mode sinking to handle unusual
addresses, involving Base values which do not have Pointer type.
This fixes PR4297.

llvm-svn: 72739
2009-06-02 21:29:13 +00:00
Evan Cheng
7875093e82 Avoid infinite looping in AllGlobalLoadUsesSimpleEnoughForHeapSRA(). This can happen when PHI uses are recursively dependent on each other.
llvm-svn: 72710
2009-06-02 00:56:07 +00:00
Eli Friedman
2b0edc3327 PR4286: Make RewriteLoadUserOfWholeAlloca and
RewriteStoreUserOfWholeAlloca deal with tail padding because 
isSafeUseOfBitCastedAllocation expects them to.  Otherwise, we crash 
trying to erase the bitcast.

llvm-svn: 72688
2009-06-01 09:14:32 +00:00
Owen Anderson
928040c625 Be more aggressive in doing LoadPRE by tracing backwards when a block only has
a single predecessor.

Patch by Jakub Staszak.

llvm-svn: 72661
2009-05-31 09:03:40 +00:00
Chris Lattner
8ac63163fe fix PR4284, a bug in simplifylibcalls handling memcmp. Patch by
Benjamin Kramer!

llvm-svn: 72625
2009-05-30 18:43:04 +00:00
Nick Lewycky
a9de2f1c81 Give embedded metadata its own type instead of relying on EmptyStructTy.
llvm-svn: 72610
2009-05-30 05:06:04 +00:00
Bill Wendling
f26f8a579e Enable GVN Load PRE.
llvm-svn: 72589
2009-05-29 20:38:16 +00:00
Torok Edwin
845fc92978 just show the instruction, its not that slow.
llvm-svn: 72577
2009-05-29 16:58:36 +00:00
Torok Edwin
a4ebdef3e8 for instructions with void type we have no choice but print the instruction as
is, otherwise we get a <badref>.

llvm-svn: 72567
2009-05-29 10:28:44 +00:00
Torok Edwin
4a228edc3a Add a DEBUG() output to GVN that prints the instruction clobbering a load.
This is useful when trying to figure out why GVN didn't eliminate redundant
loads.

llvm-svn: 72565
2009-05-29 09:46:03 +00:00
Owen Anderson
09c469ec35 Fix an issue where phiMap was not being updated properly when doing load PRE.
Diagnosis and patch thanks to Jakub Staszak.

llvm-svn: 72562
2009-05-29 05:37:54 +00:00
Nick Lewycky
3dd0d690f3 Use Operands.data() instead of &Operands[0] where Operands is a potentially
empty SmallVector.

llvm-svn: 72512
2009-05-28 04:08:10 +00:00
Dan Gohman
2884c5153c Revert 72493 and replace it with a more conservative fix, for now: don't
rewrite the comparison if there is any implicit extension or truncation
on the induction variable. I'm planning for IVUsers to eventually take
over some of the work of this code, and for it to be generalized.

llvm-svn: 72496
2009-05-27 21:10:47 +00:00
Dan Gohman
994001e5ef In ChangeCompareStride, when the stride to be reused is truncated to
a smaller type, promoted its offset back up to the type of the new
comparison. This fixes PR4222.

llvm-svn: 72493
2009-05-27 20:00:18 +00:00
Dan Gohman
19be1fa810 Change ScalarEvolution::getSCEVAtScope to always return the original value
in the case where a loop exit value cannot be computed, instead of only in
some cases while using SCEVCouldNotCompute in others. This simplifies
getSCEVAtScope's callers.

llvm-svn: 72375
2009-05-24 23:25:42 +00:00
Torok Edwin
5854389857 Move Rewriter.clear() earlier, to avoid triggerring the AssertingVH by
one of the RecursivelyDeleteTriviallyDeadInstructions.
Add a comment explaining why the cache needs to be cleared.

llvm-svn: 72372
2009-05-24 20:08:21 +00:00
Torok Edwin
aca641232c Instead of clearing the rewriter, don't attempt to rewrite dead phi nodes.
Also fix 80 column violation.

llvm-svn: 72371
2009-05-24 19:36:09 +00:00
Dan Gohman
eb3ddbb1ac When rewriting the loop exit test with the canonical induction variable,
leave the original comparison in place if it has other uses, since the
other uses won't be dominated by the new comparison instruction.

llvm-svn: 72369
2009-05-24 19:11:38 +00:00
Dan Gohman
ccdd18130a When replacing a floating-point comparison with an integer
comparison, use takeName to give the integer comparison a name.

llvm-svn: 72367
2009-05-24 18:09:01 +00:00
Torok Edwin
8936fc2e28 The rewriter may hold references to instructions that are deleted because they are trivially dead.
Fix by clearing the rewriter cache before deleting the trivially dead
instructions.
Also make InsertedExpressions use an AssertingVH to catch these
bugs easier.

llvm-svn: 72364
2009-05-24 14:23:16 +00:00
Torok Edwin
beb86bd0b4 available_externall linkage is not local, this was confusing the codegenerator,
and it wasn't generating calls through @PLT for these functions.
hasLocalLinkage() is now false for available_externally,
I attempted to fix the inliner and dce to handle available_externally properly.
It passed make check.

llvm-svn: 72328
2009-05-23 14:06:57 +00:00
Evan Cheng
77529302a6 Fix bug in FoldFCmp_IntToFP_Cst. If inttofp is a uintofp, use unsigned instead of signed integer constant.
llvm-svn: 72300
2009-05-22 23:10:53 +00:00
Dan Gohman
d5fc3518d5 Teach IndVarSimplify's FixUsesBeforeDefs to handle InvokeInsts by
assuming that the use of the value is in a block dominated by the
"normal" destination. LangRef.html and other documentation sources
don't explicitly guarantee this, but it seems to be assumed in
other places in LLVM at least.

This fixes an assertion failure on the included testcase, which
is derived from the Ada testsuite.

FixUsesBeforeDefs is a temporary measure which I'm looking to
replace with a more capable solution.

llvm-svn: 72266
2009-05-22 16:47:11 +00:00
Eli Friedman
334cc4e389 Fix loop-index-split to correctly preserve dominance frontiers. Part of
PR4238.

llvm-svn: 72244
2009-05-22 03:22:46 +00:00
Dan Gohman
fc28858d91 Teach ValueTracking a new way to analyze PHI nodes, and and teach
Instcombine to be more aggressive about using SimplifyDemandedBits
on shift nodes. This allows a shift to be simplified to zero in the
included test case.

llvm-svn: 72204
2009-05-21 02:28:33 +00:00
Dan Gohman
9e0f5a28dc Suppress the IV reversal transformation in the case that the RHS
of the comparison is defined inside the loop. This fixes a
use-before-def problem, because the transformation puts a use
of the RHS outside the loop.

llvm-svn: 72149
2009-05-20 00:34:08 +00:00
Dan Gohman
c24a00edc2 Remove an irrelevant comment.
llvm-svn: 72132
2009-05-19 20:38:47 +00:00
Dan Gohman
ccf5417982 Add some more comments to the top of this file.
llvm-svn: 72131
2009-05-19 20:37:36 +00:00
Dan Gohman
c44e433ce7 Trim unneeded #includes.
llvm-svn: 72130
2009-05-19 20:35:26 +00:00
Dan Gohman
922033d119 Teach SCEVExpander to expand arithmetic involving pointers into GEP
instructions. It attempts to create high-level multi-operand GEPs,
though in cases where this isn't possible it falls back to casting
the pointer to i8* and emitting a GEP with that. Using GEP instructions
instead of ptrtoint+arithmetic+inttoptr helps pointer analyses that
don't use ScalarEvolution, such as BasicAliasAnalysis.

Also, make the AddrModeMatcher more aggressive in handling GEPs.
Previously it assumed that operand 0 of a GEP would require a register
in almost all cases. It now does extra checking and can do more
matching if operand 0 of the GEP is foldable. This fixes a problem
that was exposed by SCEVExpander using GEPs.

llvm-svn: 72093
2009-05-19 02:15:55 +00:00
Dan Gohman
0a71520ce1 Rename UseTy to AccessTy, for consistency with getAccessType, and to
avoid ambiguity with the word "use" in IVStrideUse.

llvm-svn: 72012
2009-05-18 16:45:28 +00:00
Dale Johannesen
8bd6fc810a Reuse existing getUnderlyingObject instead of
adding another copy.

llvm-svn: 71783
2009-05-14 18:41:18 +00:00
Dale Johannesen
e740d81911 Use abs64 in one more place.
llvm-svn: 71775
2009-05-14 16:47:34 +00:00
Dale Johannesen
d0e1e29fb7 Handle some additonal cases of external weak globals.
llvm-svn: 71717
2009-05-13 20:55:30 +00:00
Dale Johannesen
a3b4fb31a1 Don't generate a select whose operand is load of a weak
external.  These may have address 0 and are not safe
to execute unconditionally.

llvm-svn: 71688
2009-05-13 18:25:07 +00:00
Chris Lattner
eb2f327449 calls in nothrow functions can be marked nothrow even if the callee
is not known to be nothrow.  This allows readnone/readonly functions
to be deleted even if we don't know whether the callee can throw.

llvm-svn: 71676
2009-05-13 17:39:14 +00:00
Chris Lattner
927ebd34e2 Fix PR4206 - crash in simplify lib calls
llvm-svn: 71644
2009-05-13 06:26:11 +00:00
Dale Johannesen
18cc7c12b7 Add an int64_t variant of abs, for host environments
without one.  Use it where we were using abs on
int64_t objects.
(I strongly suspect the casts to unsigned in the
fragments in LoopStrengthReduce are not doing whatever
the original intent was, but the obvious change to
uint64_t doesn't work.  Maybe later.)

llvm-svn: 71612
2009-05-13 00:24:22 +00:00
Dan Gohman
d13f674130 Factor the code for collecting IV users out of LSR into an IVUsers class,
and generalize it so that it can be used by IndVarSimplify. Implement the
base IndVarSimplify transformation code using IVUsers. This removes
TestOrigIVForWrap and associated code, as ScalarEvolution now has enough
builtin overflow detection and folding logic to handle all the same cases,
and more. Run "opt -iv-users -analyze -disable-output" on your favorite
loop for an example of what IVUsers does.

This lets IndVarSimplify eliminate IV casts and compute trip counts in
more cases. Also, this happens to finally fix the remaining testcases
in PR1301.

Now that IndVarSimplify is being more aggressive, it occasionally runs
into the problem where ScalarEvolutionExpander's code for avoiding
duplicate expansions makes it difficult to ensure that all expanded
instructions dominate all the instructions that will use them. As a
temporary measure, IndVarSimplify now uses a FixUsesBeforeDefs function
to fix up instructions inserted by SCEVExpander. Fortunately, this code
is contained, and can be easily removed once a more comprehensive
solution is available.

llvm-svn: 71535
2009-05-12 02:17:14 +00:00
Evan Cheng
9b27f3ec42 Teach LSR to optimize more loop exit compares, i.e. change them to use postinc iv value. Previously LSR would only optimize those which are in the loop latch block. However, if LSR can prove it is safe (and profitable), it's now possible to change those not in the latch blocks to use postinc values.
Also, if the compare is the only use, LSR would place the iv increment instruction before the compare instead in the latch.

llvm-svn: 71485
2009-05-11 22:33:01 +00:00
Dale Johannesen
f86e34065b Reverse a loop that is counting up to a maximum to
count down to 0 instead, under very restricted
circumstances.  Adjust 4 testcases in which this
optimization fires.

llvm-svn: 71439
2009-05-11 17:15:42 +00:00
Duncan Sands
f7af13b2d4 Rename PaddedSize to AllocSize, in the hope that this
will make it more obvious what it represents, and stop
it being confused with the StoreSize.

llvm-svn: 71349
2009-05-09 07:06:46 +00:00
Evan Cheng
bf67b0edef Factor out code that optimize loop terminating condition.
llvm-svn: 71305
2009-05-09 01:08:24 +00:00
Chris Lattner
0fd5aea274 fix RewriteStoreUserOfWholeAlloca to use the correct type size
method, fixing a crash on PR4146.  While the store will 
ultimately overwrite the "padded size" number of bits in memory,
the stored value may be a subset of this size.  This function
only wants to handle the case where all bits are stored.

llvm-svn: 71224
2009-05-08 15:54:41 +00:00
Nick Lewycky
8d9ef77adc This transform requires valid TargetData info. Wrap it in 'if (TD)' in
preparation for the day we use null TargetData when no target is specified.

llvm-svn: 71210
2009-05-08 06:47:37 +00:00
Eli Friedman
a280375b23 PR4123: don't crash when inlining a call which uses its own result.
llvm-svn: 71199
2009-05-08 00:22:04 +00:00
Dan Gohman
679947f6ea Perform constant folding on operands of instructions with non-void
types, such as loads and calls.

llvm-svn: 71175
2009-05-07 19:43:39 +00:00
Evan Cheng
ecc4cc83a8 Unbreak the build.
llvm-svn: 71091
2009-05-06 18:00:56 +00:00
David Greene
be8ff09e46 Make sure to use signed arithmetic in APInt to fix a regression.
llvm-svn: 71090
2009-05-06 17:39:26 +00:00
Dan Gohman
33e1f0fcb5 Simplify code by using SmallVector's pop_back_val() instead of
separate back() and pop_back() calls.

llvm-svn: 71089
2009-05-06 17:22:41 +00:00
Duncan Sands
b71ad70b4e Fix PR3754: don't mark functions that wrap MallocInst with
the readnone.  Since MallocInst is scheduled for deletion
it doesn't seem worth doing anything more subtle, such as
having mayWriteToMemory return true for MallocInst.

llvm-svn: 71077
2009-05-06 08:42:00 +00:00
Duncan Sands
880eaf5278 Allow readonly functions to unwind exceptions. Teach
the optimizers about this.  For example, a readonly
function with no uses cannot be removed unless it is
also marked nounwind.

llvm-svn: 71071
2009-05-06 06:49:50 +00:00
Dan Gohman
39d3c78f6a Fix a copy+pasto in a comment.
llvm-svn: 71035
2009-05-05 23:02:38 +00:00
Dan Gohman
c1169472a2 Delete a FIXME which is no longer relevant, and add a FIXME that is.
llvm-svn: 71033
2009-05-05 22:59:55 +00:00
Bill Wendling
5f4fcbeb10 Temporarily reverting r71008. It was causing this failure:
Running /Volumes/Sandbox/Buildbot/llvm/full-llvm/build/llvm.src/test/
CodeGen/X86/dg.exp ...
FAIL: /Volumes/Sandbox/Buildbot/llvm/full-llvm/build/llvm.src/test/
CodeGen/X86/change-compare-stride-1.ll
Failed with exit(1) at line 2
while running: grep {cmpq       $-478,} change-compare-stride-1.ll.tmp
child process exited abnormally

llvm-svn: 71013
2009-05-05 20:49:46 +00:00
David Greene
2bb2b3840e Handle overflow of 64-bit loop conditions.
llvm-svn: 71008
2009-05-05 20:22:36 +00:00
Dan Gohman
00c4ac3add Re-apply 70645, converting ScalarEvolution to use
CallbackVH, with fixes. allUsesReplacedWith need to
walk the def-use chains and invalidate all users of a
value that is replaced. SCEVs of users need to be
recalcualted even if the new value is equivalent. Also,
make forgetLoopPHIs walk def-use chains, since any
SCEV that depends on a PHI should be recalculated when
more information about that PHI becomes available.

llvm-svn: 70927
2009-05-04 22:30:44 +00:00
Dan Gohman
6c425d29e7 Constify a bunch of SCEV-using code.
llvm-svn: 70919
2009-05-04 22:02:23 +00:00
Chris Lattner
84cf4d62a8 fix some problems spotted by Duncan and Nicolas Geoffray
llvm-svn: 70872
2009-05-04 16:29:24 +00:00
Chris Lattner
6807ddd3d9 * Sink 4 duplicates of edge threading validity checks and DOUT prints into
ThreadEdge directly.  This shares the code, but is just a refactoring.
* Make JumpThreading compute the set of loop headers and avoid threading
  across them.  This prevents jump threading from forming irreducible 
  loops (goodness) but also prevents it from threading in other cases that
  are beneficial (see the comment above FindFunctionBackedges).

llvm-svn: 70820
2009-05-04 02:28:08 +00:00
Chris Lattner
b07d558841 Factor loop backedge finding out of CodeGenPrepare into a new
FindFunctionBackedges function.

llvm-svn: 70819
2009-05-04 02:25:58 +00:00
Dan Gohman
8e4b9e586b Revert r70645 for now; it's causing a variety of regressions.
llvm-svn: 70661
2009-05-03 05:46:20 +00:00
Nick Lewycky
01b22399ef Revert r70630. Go back to appending ".b" to internal globals when shrinking
them to bool.

llvm-svn: 70653
2009-05-03 03:49:08 +00:00
Dan Gohman
7d98736ca6 Convert ScalarEvolution to use CallbackVH for its internal map. This
makes ScalarEvolution::deleteValueFromRecords, and it's code that
subtly needed to be called before ReplaceAllUsesWith, unnecessary.

It also makes ValueDeletionListener unnecessary.

llvm-svn: 70645
2009-05-02 21:19:20 +00:00
Dan Gohman
7c5f68dd5c The second argument to RecursivelyDeleteTriviallyDeadInstructions has
a default value, and will hopefully be going away soon.

llvm-svn: 70642
2009-05-02 20:22:10 +00:00
Dan Gohman
a79cce4aef Previously, RecursivelyDeleteDeadInstructions provided an option
of returning a list of pointers to Values that are deleted. This was
unsafe, because the pointers in the list are, by nature of what
RecursivelyDeleteDeadInstructions does, always dangling. Replace this
with a simple callback mechanism. This may eventually be removed if
all clients can reasonably be expected to use CallbackVH.

Use this to factor out the dead-phi-cycle-elimination code from LSR
utility function, and generalize it to use the
RecursivelyDeleteTriviallyDeadInstructions utility function.

This makes LSR more aggressive about eliminating dead PHI cycles;
adjust tests to either be less trivial or to simply expect fewer
instructions.

llvm-svn: 70636
2009-05-02 18:29:22 +00:00
Dan Gohman
cc3edfaa6c Tell ScalarEvolution that the loop is being deleted before actually
deleting it.  This will let ScalarEvolution be more complete about
updating its records.

llvm-svn: 70632
2009-05-02 17:29:26 +00:00
Nick Lewycky
3e85ff61b3 Don't append ".b" to the names of globals that are being shrunk to booleans.
llvm-svn: 70630
2009-05-02 16:21:50 +00:00
Dan Gohman
a4b28ca3c9 Don't split critical edges during the AddUsersIfInteresting phase
of LSR. This makes the AddUsersIfInteresting phase of LSR a pure
analysis instead of a phase that potentially does CFG modifications.

The conditions where this code would actually perform a split are
rare, and in the cases where it actually would do a split the split
is usually undone by CodeGenPrepare, and in cases where splits
actually survive into codegen, they appear to hurt more often than
they help.

llvm-svn: 70625
2009-05-02 05:36:01 +00:00
Dan Gohman
bdc33dc988 Make RequiresTypeConversion canonicalize the types before calling the
target hooks canLosslesslyBitCastTo and isTruncateFree. This allows
targets to avoid worrying about handling all combinations of integer
and pointer types.

llvm-svn: 70555
2009-05-01 17:07:43 +00:00
Dan Gohman
9dd3e99217 Minor whitespace fix.
llvm-svn: 70551
2009-05-01 16:56:32 +00:00
Dan Gohman
a55fce998e Fix some code to work if TargetLowering is not available.
llvm-svn: 70546
2009-05-01 16:29:14 +00:00
Dale Johannesen
be38eaf1d4 Print correct instruction in dump.
llvm-svn: 70427
2009-04-29 22:57:20 +00:00
Dan Gohman
8b1b8d5891 Reword and tidy up some comments.
llvm-svn: 70416
2009-04-29 22:01:05 +00:00
Dan Gohman
418f294b3b Remove an obsolete comment.
llvm-svn: 70262
2009-04-27 22:12:34 +00:00
Dale Johannesen
626b0a32f7 Fix PR 4086, a bug in FP IV elimination.
llvm-svn: 70247
2009-04-27 21:03:15 +00:00
Dan Gohman
e1a532cb4f Permit ChangeCompareStride to rewrite a comparison when the factor
between the comparison's iv stride and the candidate stride is
exactly -1.

llvm-svn: 70244
2009-04-27 20:35:32 +00:00
Dan Gohman
d13f1a3b59 Return null instead of false, as appropriate.
llvm-svn: 70054
2009-04-25 17:28:45 +00:00
Dan Gohman
a7fae1f865 Add several more icmp simplifications. Transform signed comparisons
into unsigned ones when the operands are known to have the same
sign bit value.

llvm-svn: 70053
2009-04-25 17:12:48 +00:00
Sanjiv Gupta
f1177e1be7 Allow i16 type indices to gep.
llvm-svn: 69946
2009-04-24 02:37:54 +00:00
Dan Gohman
c0f47d6ec1 Change SCEVExpander's expandCodeFor to provide more flexibility
with the persistent insertion point, and change IndVars to make
use of it. This fixes a bug where IndVars was holding on to a
stale insertion point and forcing the SCEVExpander to continue to
use it.

This fixes PR4038.

llvm-svn: 69892
2009-04-23 15:16:49 +00:00
Evan Cheng
bdfff0ba69 Make sure both operands have binary instructions have the same type.
llvm-svn: 69844
2009-04-22 23:39:28 +00:00
Evan Cheng
faa208ae5f A few more places where the check of use_empty is needed.
llvm-svn: 69842
2009-04-22 23:09:16 +00:00
Evan Cheng
2af546d5fa Avoid deferencing use_begin() if value does not have a use.
llvm-svn: 69836
2009-04-22 22:45:37 +00:00
Owen Anderson
309568c469 Real fix for PR3549, by using caching for predecessor counts in addition to the predecessors themselves. This halves the time
to optimize the testcase, beyond what my previous patch did.

llvm-svn: 69792
2009-04-22 08:50:12 +00:00
Owen Anderson
b36babc111 Use PredIteratorCache in LCSSA, which gives a 37% overall speedup on the testcase from PR3549. More improvements to come.
llvm-svn: 69788
2009-04-22 08:09:13 +00:00
Chris Lattner
60c88b66da use predicate instead of hand-rolled loop
llvm-svn: 69752
2009-04-21 23:37:18 +00:00
Chris Lattner
95aad4d625 fix a crash on a pointless but valid zero-length memset, rdar://6808691
llvm-svn: 69680
2009-04-21 16:52:12 +00:00
Dan Gohman
4e3e945880 Factor out a common base class from SCEVTruncateExpr, SCEVZeroExtendExpr,
and SCEVSignExtendExpr.

llvm-svn: 69649
2009-04-21 01:25:57 +00:00
Dan Gohman
55d8490e7b Introduce encapsulation for ScalarEvolution's TargetData object, and refactor
the code to minimize dependencies on TargetData.

llvm-svn: 69644
2009-04-21 01:07:12 +00:00
Dale Johannesen
a263eac5f8 Adjust loop size estimate for full unrolling;
GEP's don't usually become instructions.

llvm-svn: 69631
2009-04-20 22:19:33 +00:00
Sanjiv Gupta
0cb9d67bcc Before trying to introduce/eliminate cast/ext/trunc to make indices type as
pointer type, make sure that the pointer size is a valid sequential index type.

llvm-svn: 69574
2009-04-20 06:05:54 +00:00
Dan Gohman
e2e949ee98 Use more const qualifiers with SCEV interfaces.
llvm-svn: 69450
2009-04-18 17:56:28 +00:00
Jim Grosbach
da399d8358 remove trailing whitespace
llvm-svn: 69402
2009-04-17 23:30:55 +00:00
David Greene
d9756224ce Use a safer iterator interface and get rid of std C++ library misuse.
This fixes a --enable-expensive-checks problem.

llvm-svn: 69353
2009-04-17 14:56:18 +00:00
Dan Gohman
61dc247292 Don't create ConstantInts with pointer type. This fixes a
regression in 403.gcc in PIC_CODEGEN=1 and DISABLE_LTO=1
mode.

llvm-svn: 69344
2009-04-17 02:02:52 +00:00
Dan Gohman
0b7e08929a Use TargetData::getTypeSizeInBits instead of getPrimitiveSizeInBits()
to get the correct answer for pointer types.

llvm-svn: 69321
2009-04-16 22:35:57 +00:00
Eli Friedman
13e59b3c41 Fix for PR3944: make mem2reg O(N) instead of O(N^2) in the number of
incoming edges for a block with many predecessors.

llvm-svn: 69312
2009-04-16 21:40:28 +00:00
Dan Gohman
f2bec6720f Minor code simplifications. Don't attempt LSR on theoretical
targets with pointers larger than 64 bits, due to the code not
yet being APInt clean.

llvm-svn: 69296
2009-04-16 16:49:48 +00:00
Dan Gohman
67ad4ee457 LSR is no longer a GEP optimizer. It is now an IV expression
optimizer, which just happen to frequently involve optimizing GEPs.

llvm-svn: 69295
2009-04-16 16:46:01 +00:00
Dan Gohman
b40c343360 Use ConstantExpr::getIntToPtr instead of SCEVExpander::InsertCastOfTo,
since the operand is always a constant.

llvm-svn: 69291
2009-04-16 15:48:38 +00:00
Dan Gohman
862f4743b8 Use a SCEV expression cast instead of immediately inserting a
new instruction with SCEVExpander::InsertCastOfTo.

llvm-svn: 69290
2009-04-16 15:47:35 +00:00
Dan Gohman
98aa1d9693 Expand GEPs in ScalarEvolution expressions. SCEV expressions can now
have pointer types, though in contrast to C pointer types, SCEV
addition is never implicitly scaled. This not only eliminates the
need for special code like IndVars' EliminatePointerRecurrence
and LSR's own GEP expansion code, it also does a better job because
it lets the normal optimizations handle pointer expressions just
like integer expressions.

Also, since LLVM IR GEPs can't directly index into multi-dimensional
VLAs, moving the GEP analysis out of client code and into the SCEV
framework makes it easier for clients to handle multi-dimensional
VLAs the same way as other arrays.

Some existing regression tests show improved optimization.
test/CodeGen/ARM/2007-03-13-InstrSched.ll in particular improved to
the point where if-conversion started kicking in; I turned it off
for this test to preserve the intent of the test.

llvm-svn: 69258
2009-04-16 03:18:22 +00:00
Dale Johannesen
ab8b46beca Eliminate zext over (iv | const) or (signed iv),
and sext over (iv | const), if a longer iv is
available.  Allow expressions to have more than
one zext/sext parent.  All from OpenSSL.

llvm-svn: 69241
2009-04-15 23:31:51 +00:00
Dale Johannesen
98c9716c34 Eliminate zext over (iv & const) or ((iv+const)&const)
if a longer iv is available.  These subscript forms are
not common; they're a bottleneck in OpenSSL.

llvm-svn: 69215
2009-04-15 20:41:02 +00:00
Dale Johannesen
427e9aade9 Enhance induction variable code to remove the
sext around sext(shorter IV + constant), using a
longer IV instead, when it can figure out the
add can't overflow.  This comes up a lot in
subscripting; mainly affects 64 bit.

llvm-svn: 69123
2009-04-15 01:10:12 +00:00
Evan Cheng
bd35a81da5 Avoid making the transformation enabled by my last patch if the new destinations have phi nodes.
llvm-svn: 69121
2009-04-15 00:43:54 +00:00
Devang Patel
7323064183 While inlining, clone llvm.dbg.func.start intrinsic and adjust
llvm.dbg.region.end instrinsic. This nested llvm.dbg.func.start/llvm.dbg.region.end pair now enables DW_TAG_inlined_subroutine support in code generator.

llvm-svn: 69118
2009-04-15 00:17:06 +00:00
Evan Cheng
dba98a0669 Optimize conditional branch on i1 phis with non-constant inputs.
This turns:

eq:
        %3 = icmp eq i32 %1, %2
        br label %join

ne:
        %4 = icmp ne i32 %1, %2
        br label %join

join:
        %5 = phi i1 [%3, %eq], [%4, %ne]
        br i1 %5, label %yes, label %no

=>

eq:
        %3 = icmp eq i32 %1, %2
        br i1 %3, label %yes, label %no

ne:
        %4 = icmp ne i32 %1, %2
        br i1 %4, label %yes, label %no

llvm-svn: 69102
2009-04-14 23:40:03 +00:00
Owen Anderson
f127f4a7a9 LoopIndexSplit needs to inform the loop pass manager of the instructions it is
deleting, not just the basic block.

llvm-svn: 69011
2009-04-14 01:04:19 +00:00
Chris Lattner
57077413f1 eliminate unneeded parens.
llvm-svn: 68939
2009-04-13 05:38:23 +00:00
Chris Lattner
8ad1efdfe1 "There was a typo in my previous patch which leads to miscompilation of
strncat :(

strncat(foo, "bar", 99)
would be optimized to
memcpy(foo+strlen(foo), "bar", 100, 1)
instead of
memcpy(foo+strlen(foo), "bar", 4, 1)"

Patch by Benjamin Kramer!

llvm-svn: 68905
2009-04-12 18:22:33 +00:00
Chris Lattner
f03202e76d add some optimizations for strncpy/strncat and factor some
code.  Patch by Benjamin Kramer!

llvm-svn: 68885
2009-04-12 05:06:39 +00:00
Chris Lattner
7d75f78b92 Instcombine should not promote whole computation trees to "strange"
integer types, unless they are already strange.  This prevents it from
turning the code produced by SROA into crazy libcalls and stuff that 
the code generator can't handle.  In the attached example, the result
was an i96 multiply that caused the x86 backend to assert.

Note that if TargetData had an idea of what the legal types are for
a target that this could be used to stop instcombine from introducing
i64 muls, as Scott wanted.

llvm-svn: 68598
2009-04-08 05:41:03 +00:00
Chris Lattner
2f520929d4 fix rdar://6762290, a crash compiling cxx filt with clang.
llvm-svn: 68500
2009-04-07 05:03:34 +00:00
Chris Lattner
e872752d66 remove empty section
llvm-svn: 68485
2009-04-07 02:55:53 +00:00
Ed Schouten
ff25f858fd Let the strcat optimizer return the pointer to the start of the buffer,
instead of the place where it started to perform the string copy.

- PR3661
- Patch by Benjamin Kramer!

llvm-svn: 68443
2009-04-06 13:06:48 +00:00
Owen Anderson
851ce6d1d5 Reapply r68211, with the miscompilations it caused fixed.
llvm-svn: 68262
2009-04-01 23:53:49 +00:00
Dan Gohman
a134448980 Revert r68172. It caused regressions in
Applications/Burg/burg
  Applications/ClamAV/clamscan
and many other tests.

llvm-svn: 68211
2009-04-01 16:37:47 +00:00
Owen Anderson
d7c837bb4b Enhance GVN to propagate simple conditionals. This fixes PR3921.
llvm-svn: 68172
2009-04-01 01:20:45 +00:00
Chris Lattner
87466e0995 Make the key of ValueRankMap an AssertingVH, so that we die violently
if it dangles.

llvm-svn: 68150
2009-03-31 22:13:29 +00:00
Evan Cheng
c419350132 Throttle back "fold select into operand" transformation. InstCombine should not generate selects of two constants unless they are selects of 0 and 1.
e.g.
define i32 @t1(i32 %c, i32 %x) nounwind {
       %t1 = icmp eq i32 %c, 0
       %t2 = lshr i32 %x, 18
       %t3 = select i1 %t1, i32 %t2, i32 %x
       ret i32 %t3
}

was turned into

define i32 @t2(i32 %c, i32 %x) nounwind {
       %t1 = icmp eq i32 %c, 0
       %t2 = select i1 %t1, i32 18, i32 0
       %t3 = lshr i32 %x, %t2
       ret i32 %t3
}

For most targets, that means materializing two constants and then a select. e.g. On x86-64

movl    %esi, %eax
shrl    $18, %eax
testl   %edi, %edi
cmovne  %esi, %eax
ret

=>

xorl    %eax, %eax
testl   %edi, %edi
movl    $18, %ecx
cmovne  %eax, %ecx
movl    %esi, %eax
shrl    %cl, %eax
ret

Also, the optimizer and codegen can reason about shl / and / add, etc. by a constant. This optimization will hinder optimizations using ComputeMaskedBits.

llvm-svn: 68142
2009-03-31 20:42:45 +00:00
Devang Patel
7fa69ef109 Update call graph after inlining invoke.
Patch by Jay Foad.

llvm-svn: 68120
2009-03-31 17:36:12 +00:00
Devang Patel
ec65625744 Loop Index Split can eliminate a loop if it can determin if loop body is executed only once. There was a bug in determining IV based value of the iteration for which the loop body is executed. Fix it.
llvm-svn: 68071
2009-03-30 22:24:10 +00:00
Duncan Sands
e13276db7f Revert r67798: it breaks llvm-gcc bootstrap on x86-64-linux, presumably due to
a miscompilation.

make[4]: Entering directory `gcc-4.2.llvm-objects/x86_64-unknown-linux-gnu/libstdc++-v3/include'
if [ ! -d "./x86_64-unknown-linux-gnu/bits/stdtr1c++.h.gch" ]; then \
          mkdir -p ./x86_64-unknown-linux-gnu/bits/stdtr1c++.h.gch; \
        fi; \
        gcc-4.2.llvm-objects/./gcc/xgcc -shared-libgcc -Bgcc-4.2.llvm-objects/./gcc -nostdinc++ 
-Lgcc-4.2.llvm-objects/x86_64-unknown-linux-gnu/libstdc++-v3/src -Lgcc-4.2.llvm-objects/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs 
-B/usr/local/gnat-llvm/x86_64-unknown-linux-gnu/bin/ -B/usr/local/gnat-llvm/x86_64-unknown-linux-gnu/lib/ -isystem 
/usr/local/gnat-llvm/x86_64-unknown-linux-gnu/include -isystem /usr/local/gnat-llvm/x86_64-unknown-linux-gnu/sys-include -Winvalid-pch -Wno-deprecated -x 
c++-header -g -O2  -D_GNU_SOURCE -Igcc-4.2.llvm-objects/x86_64-unknown-linux-gnu/libstdc++-v3/include/x86_64-unknown-linux-gnu 
-Igcc-4.2.llvm-objects/x86_64-unknown-linux-gnu/libstdc++-v3/include -Igcc-4.2.llvm/libstdc++-v3/libsupc++ -O2 -g 
gcc-4.2.llvm/libstdc++-v3/include/precompiled/stdtr1c++.h -o x86_64-unknown-linux-gnu/bits/stdtr1c++.h.gch/O2g.gch
In file included from gcc-4.2.llvm-objects/x86_64-unknown-linux-gnu/libstdc++-v3/include/tr1/repeat.h:247,
                 from gcc-4.2.llvm-objects/x86_64-unknown-linux-gnu/libstdc++-v3/include/tr1/functional:1098,
                 from gcc-4.2.llvm/libstdc++-v3/include/precompiled/stdtr1c++.h:53:
gcc-4.2.llvm-objects/x86_64-unknown-linux-gnu/libstdc++-v3/include/tr1/functional_iterate.h:417: internal compiler error: in ggc_recalculate_in_use_p, at 
ggc-page.c:1602
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://llvm.org/bugs/> for instructions.
make[4]: *** [x86_64-unknown-linux-gnu/bits/stdtr1c++.h.gch/O2g.gch] Error 1

llvm-svn: 67839
2009-03-27 14:56:47 +00:00
Dale Johannesen
9fd8bb432f One more place to skip debug info.
llvm-svn: 67811
2009-03-27 01:13:37 +00:00
Devang Patel
a2211c26d7 While hoisting an instruction, update alias info set tracker.
llvm-svn: 67798
2009-03-26 23:48:52 +00:00
Dale Johannesen
03cedf1d8b Skip debug info one more place. (This one gets
called from llc, not opt, but it's an IR level
optimization nevertheless.)

llvm-svn: 67724
2009-03-26 01:15:07 +00:00
Devang Patel
8c31ea5290 Before deleting a basic block, give other loop passes a chance cleanup analysis values, related to the instructions in the basic block.
llvm-svn: 67719
2009-03-25 23:57:48 +00:00