Bill Wendling
a9ee09f4be
Revert r137655. There is some question about whether the 'landingpad'
...
instruction should be marked as potentially reading and/or writing memory.
llvm-svn: 137863
2011-08-17 20:36:44 +00:00
Bill Wendling
8ddfc09e7a
Use the getFirstInsertionPt() method instead of getFirstNonPHI + an 'isa<>'
...
check for a LandingPadInst.
llvm-svn: 137745
2011-08-16 20:45:24 +00:00
Bill Wendling
91d4e9edec
Don't sink the instruction to before a landingpad instruction.
...
llvm-svn: 137672
2011-08-15 22:53:05 +00:00
Eli Friedman
8bc586e770
Update instcombine for atomic load/store.
...
llvm-svn: 137664
2011-08-15 22:09:40 +00:00
Bill Wendling
e86965ee19
Duncan pointed out that the LandingPadInst might read memory. (It might also
...
write to memory.) Marking it as such makes some checks for immobility go away.
llvm-svn: 137655
2011-08-15 21:14:31 +00:00
Bill Wendling
dd94d3426b
Don't try to sink the landingpad instruction. It's immobile.
...
llvm-svn: 137629
2011-08-15 18:23:40 +00:00
Nick Lewycky
746e317953
This transform is not safe. Thanks to Eli for pointing that out!
...
llvm-svn: 137575
2011-08-14 04:51:49 +00:00
Nick Lewycky
ae13df60a6
Don't attempt to add 'nsw' when intermediate instructions had no such guarantee.
...
llvm-svn: 137572
2011-08-14 03:41:33 +00:00
Nick Lewycky
de49278c26
Teach instcombine to preserve the nsw bit by doing an after-the-fact analysis
...
when combining add and sub instructions. Patch by Pranav Bhandarkar!
llvm-svn: 137570
2011-08-14 01:45:19 +00:00
Nick Lewycky
d405b7e2ae
Small cleanups:
...
- use SmallVectorImpl& for the function argument.
- ignore the operands on the GEP, even if they aren't constant! Much as we
pretend the malloc succeeds, we pretend that malloc + whatever-you-GEP'd-by
is not null. It's magic!
llvm-svn: 136757
2011-08-03 01:11:40 +00:00
Nick Lewycky
50f4966ceb
Fix logical error when detecting lifetime intrinsics.
...
Don't replace a gep/bitcast with 'undef' because that will form a "free(undef)"
which in turn means "unreachable". What we wanted was a no-op. Instead, analyze
the whole tree and look for all the instructions we need to delete first, then
delete them second, not relying on the use_list to stay consistent.
llvm-svn: 136752
2011-08-03 00:43:35 +00:00
Nick Lewycky
e8ae02dfb9
Teach InstCombine that lifetime intrincs aren't a real user on the result of a
...
malloc call.
llvm-svn: 136732
2011-08-02 22:08:01 +00:00
Rafael Espindola
a3a44f3fc3
Add a small gep optimization I noticed was missing while reading some IL.
...
llvm-svn: 136585
2011-07-31 04:43:41 +00:00
Jay Foad
d1b7849d49
Convert GetElementPtrInst to use ArrayRef.
...
llvm-svn: 135904
2011-07-25 09:48:08 +00:00
Jay Foad
040dd82f44
Convert IRBuilder::CreateGEP and IRBuilder::CreateInBoundsGEP to use
...
ArrayRef.
llvm-svn: 135761
2011-07-22 08:16:57 +00:00
Jay Foad
b992a635fb
Convert SimplifyGEPInst to use ArrayRef.
...
llvm-svn: 135482
2011-07-19 15:07:52 +00:00
Frits van Bommel
717d7edd3e
Migrate LLVM and Clang to use the new makeArrayRef(...) functions where previously explicit non-default constructors were used.
...
Mostly mechanical with some manual reformatting.
llvm-svn: 135390
2011-07-18 12:00:32 +00:00
Chris Lattner
229907cd11
land David Blaikie's patch to de-constify Type, with a few tweaks.
...
llvm-svn: 135375
2011-07-18 04:54:35 +00:00
Jay Foad
57aa636794
Convert InsertValueInst and ExtractValueInst APIs to use ArrayRef.
...
llvm-svn: 135040
2011-07-13 10:26:04 +00:00
Rafael Espindola
403256763f
Don't duplicate the work done by a gep into a "bitcast" if the gep has
...
more than one use.
Fixes PR10322.
llvm-svn: 134883
2011-07-11 03:43:47 +00:00
Eli Friedman
35211c6091
Final step of instcombine debuginfo; switch a couple more places over to InsertNewInstWith, and use setDebugLoc for the cases which can't be easily handled by the automated mechanisms.
...
llvm-svn: 132167
2011-05-27 00:19:40 +00:00
Eli Friedman
68aab459ae
Make instcombine O(N) instead of O(N^2) in code where the same simplifiable constant is used many times.
...
Part of rdar://9471075.
llvm-svn: 131979
2011-05-24 18:52:07 +00:00
Eli Friedman
41e509a33d
More instcombine cleanup, towards improving debug line info.
...
llvm-svn: 131604
2011-05-18 23:58:37 +00:00
Eli Friedman
96254a0d53
Start trying to make InstCombine preserve more debug info. The idea here is to set the debug location on the IRBuilder, which will be then right location in most cases. This should magically give many transformations debug locations, and fixing places which are missing a debug location will usually just means changing the code creating it to use the IRBuilder.
...
As an example, the change to InstCombineCalls catches a common case where a call to a bitcast of a function is rewritten.
Chris, does this approach look reasonable?
llvm-svn: 131516
2011-05-18 01:28:27 +00:00
Eli Friedman
b9ed18f2cb
Use ReplaceInstUsesWith instead of replaceAllUsesWith where appropriate in instcombine.
...
llvm-svn: 131512
2011-05-18 00:32:01 +00:00
Duncan Sands
085ad3b81a
Stop trying to have instcombine preserve LCSSA form: this was not
...
effective in avoiding recomputation of LCSSA form; the widespread
use of instsimplify (which looks through phi nodes) means it was
not preserving LCSSA form anyway; and instcombine is no longer
scheduled in the middle of the loop passes so this doesn't matter
anymore.
llvm-svn: 130301
2011-04-27 10:55:12 +00:00
Nadav Rotem
a069c6ce05
InstCombine optimizes gep(bitcast(x)) even when the bitcasts casts away address
...
space info. We crash with an assert in this case. This change checks that the
address space of the bitcasted pointer is the same as the gep ptr.
llvm-svn: 128884
2011-04-05 14:29:52 +00:00
Jay Foad
52131344a2
Remove PHINode::reserveOperandSpace(). Instead, add a parameter to
...
PHINode::Create() giving the (known or expected) number of operands.
llvm-svn: 128537
2011-03-30 11:28:46 +00:00
Jay Foad
1c83965f5a
Make more use of PHINode::getNumIncomingValues().
...
llvm-svn: 128406
2011-03-28 13:03:10 +00:00
Devang Patel
aad34d882d
Try to not lose variable's debug info during instcombine.
...
This is done by lowering dbg.declare intrinsic into dbg.value intrinsic.
Radar 9143931.
llvm-svn: 127834
2011-03-17 22:18:16 +00:00
Devang Patel
8d53ac81ec
Do not forget DebugLoc!
...
llvm-svn: 125547
2011-02-15 02:02:30 +00:00
Dan Gohman
c6f0bda839
Conservatively, clear optional flags, such as nsw, when performing
...
reassociation. No testcase, because I wasn't able to create a testcase
which actually demonstrates a problem.
llvm-svn: 124713
2011-02-02 02:05:46 +00:00
Chris Lattner
b5e15d1907
fix PR9013, an infinite loop in instcombine.
...
llvm-svn: 123968
2011-01-21 05:29:50 +00:00
Chris Lattner
f4ca47bda8
update obsolete comment.
...
llvm-svn: 123965
2011-01-21 05:08:26 +00:00
Nick Lewycky
6a083cf820
Don't try to pull vector bitcasts that change the number of elements through
...
a select. A vector select is pairwise on each element so we'd need a new
condition with the right number of elements to select on. Fixes PR8994.
llvm-svn: 123963
2011-01-21 02:30:43 +00:00
Chris Lattner
adb1a233b1
remove a dead check, this was needed before we had an explicit veto on uses of phis.
...
llvm-svn: 123569
2011-01-16 05:37:55 +00:00
Chris Lattner
d55581ded8
enhance FoldOpIntoPhi in instcombine to try harder when a phi has
...
multiple uses. In some cases, all the uses are the same operation,
so instcombine can go ahead and promote the phi. In the testcase
this pushes an add out of the loop.
llvm-svn: 123568
2011-01-16 05:28:59 +00:00
Chris Lattner
ea7131a062
remove the AllowAggressive argument to FoldOpIntoPhi. It is forced to false in the
...
first line of the function because it isn't a good idea, even for compares.
llvm-svn: 123566
2011-01-16 05:14:26 +00:00
Chris Lattner
ff2e737714
more cleanups: use the IR builder.
...
llvm-svn: 123565
2011-01-16 05:08:00 +00:00
Chris Lattner
25ce280511
tidy up code.
...
llvm-svn: 123564
2011-01-16 04:37:29 +00:00
Duncan Sands
fbb9ac3cca
Add a generic expansion transform: A op (B op' C) -> (A op B) op' (A op C)
...
if both A op B and A op C simplify. This fires fairly often but doesn't
make that much difference. On gcc-as-one-file it removes two "and"s and
turns one branch into a select.
llvm-svn: 122399
2010-12-22 13:36:08 +00:00
Duncan Sands
3547d2ebd8
Add some statistics, good for understanding how much more powerful
...
instcombine is compared to instsimplify.
llvm-svn: 122397
2010-12-22 09:40:51 +00:00
Chris Lattner
4fb9dd4c74
fix an oversight caught by Frits!
...
llvm-svn: 122204
2010-12-19 23:24:04 +00:00
Chris Lattner
3e635d2e99
move a transformation to a more logical place, simplifying it.
...
llvm-svn: 122183
2010-12-19 19:43:52 +00:00
Frits van Bommel
28218aa8f1
Transform (extractvalue (load P), ...) to (load (gep P, 0, ...)) if the load has no other uses, shrinking the load.
...
llvm-svn: 120323
2010-11-29 21:56:20 +00:00
Duncan Sands
0488d564e1
Rename SimplifyDistributed to the more meaningfull name SimplifyByFactorizing.
...
llvm-svn: 120051
2010-11-23 20:42:39 +00:00
Duncan Sands
60813f96e0
Propagate LeftDistributes and RightDistributes into their only uses.
...
Stylistic improvement suggested by Frits van Bommel.
llvm-svn: 120026
2010-11-23 15:28:14 +00:00
Duncan Sands
22df741687
Fix typo pointed out by Frits van Bommel and Marius Wachtler.
...
llvm-svn: 120025
2010-11-23 15:25:34 +00:00
Duncan Sands
adc7771f18
Exploit distributive laws (eg: And distributes over Or, Mul over Add, etc) in a
...
fairly systematic way in instcombine. Some of these cases were already dealt
with, in which case I removed the existing code. The case of Add has a bunch of
funky logic which covers some of this plus a few variants (considers shifts to be
a form of multiplication), which I didn't touch. The simplification performed is:
A*B+A*C -> A*(B+C). The improvement is to do this in cases that were not already
handled [such as A*B-A*C -> A*(B-C), which was reported on the mailing list], and
also to do it more often by not checking for "only one use" if "B+C" simplifies.
llvm-svn: 120024
2010-11-23 14:23:47 +00:00
Duncan Sands
c133c54426
If a GEP index simply advances by multiples of a type of zero size,
...
then replace the index with zero.
llvm-svn: 119974
2010-11-22 16:32:50 +00:00
Duncan Sands
8a0f486e36
Move the "gep undef" -> "undef" transform from instcombine to
...
InstructionSimplify.
llvm-svn: 119970
2010-11-22 13:42:49 +00:00
Duncan Sands
641baf1646
Generalize the reassociation transform in SimplifyCommutative (now renamed to
...
SimplifyAssociativeOrCommutative) "(A op C1) op C2" -> "A op (C1 op C2)",
which previously was only done if C1 and C2 were constants, to occur whenever
"C1 op C2" simplifies (a la InstructionSimplify). Since the simplifying operand
combination can no longer be assumed to be the right-hand terms, consider all of
the possible permutations. When compiling "gcc as one big file", transform 2
(i.e. using right-hand operands) fires about 4000 times but it has to be said
that most of the time the simplifying operands are both constants. Transforms
3, 4 and 5 each fired once. Transform 6, which is an existing transform that
I didn't change, never fired. With this change, the testcase is now optimized
perfectly with one run of instcombine (previously it required instcombine +
reassociate + instcombine, and it may just have been luck that this worked).
llvm-svn: 119002
2010-11-13 15:10:37 +00:00
Benjamin Kramer
76229bc128
SmallVectorize.
...
llvm-svn: 117213
2010-10-23 17:10:24 +00:00
Owen Anderson
df7a4f2515
Now with fewer extraneous semicolons!
...
llvm-svn: 115996
2010-10-07 22:25:06 +00:00
Owen Anderson
f7ef5dfccc
Add initialization routines to InstCombine.
...
llvm-svn: 115965
2010-10-07 20:04:55 +00:00
Owen Anderson
a57b97e7e7
Fix batch of converting RegisterPass<> to INTIALIZE_PASS().
...
llvm-svn: 109045
2010-07-21 22:09:45 +00:00
Gabor Greif
0028cc6730
cache result of operator*
...
llvm-svn: 107972
2010-07-09 15:01:36 +00:00
Gabor Greif
75f6943c95
use ArgOperand API, also tighten the type of visitFree to make this work out smoothly
...
llvm-svn: 106736
2010-06-24 12:21:15 +00:00
Duncan Sands
f162eace49
Teach instCombine to remove malloc+free if malloc's only uses are comparisons
...
to null. Patch by Matti Niemenmaa.
llvm-svn: 104871
2010-05-27 19:09:06 +00:00
Eric Christopher
7258dcd77f
Revert 101465, it broke internal OpenGL testing.
...
Probably the best way to know that all getOperand() calls have been handled
is to replace that API instead of updating.
llvm-svn: 101579
2010-04-16 23:37:20 +00:00
Gabor Greif
f375520f7b
reapply r101434
...
with a fix for self-hosting
rotate CallInst operands, i.e. move callee to the back
of the operand array
the motivation for this patch are laid out in my mail to llvm-commits:
more efficient access to operands and callee, faster callgraph-construction,
smaller compiler binary
llvm-svn: 101465
2010-04-16 15:33:14 +00:00
Gabor Greif
403e9694f9
back out r101423 and r101397, they break llvm-gcc self-host on darwin10
...
llvm-svn: 101434
2010-04-16 01:16:20 +00:00
Gabor Greif
33ae80bff7
reapply r101364, which has been backed out in r101368
...
with a fix
rotate CallInst operands, i.e. move callee to the back
of the operand array
the motivation for this patch are laid out in my mail to llvm-commits:
more efficient access to operands and callee, faster callgraph-construction,
smaller compiler binary
llvm-svn: 101397
2010-04-15 20:51:13 +00:00
Gabor Greif
9fd00c7d25
back out r101364, as it trips the linux nightlybot on some clang C++ tests
...
llvm-svn: 101368
2010-04-15 12:46:56 +00:00
Gabor Greif
aafd209632
rotate CallInst operands, i.e. move callee to the back
...
of the operand array
the motivation for this patch are laid out in my mail to llvm-commits:
more efficient access to operands and callee, faster callgraph-construction,
smaller compiler binary
llvm-svn: 101364
2010-04-15 10:49:53 +00:00
Duncan Sands
19d0b47b1f
There are two ways of checking for a given type, for example isa<PointerType>(T)
...
and T->isPointerTy(). Convert most instances of the first form to the second form.
Requested by Chris.
llvm-svn: 96344
2010-02-16 11:11:14 +00:00
Duncan Sands
9dff9bec31
Uniformize the names of type predicates: rather than having isFloatTy and
...
isInteger, we now have isFloatTy and isIntegerTy. Requested by Chris!
llvm-svn: 96223
2010-02-15 16:12:20 +00:00
Chris Lattner
35d3b9dcd0
teach ComputeNumSignBits to look through PHI nodes.
...
llvm-svn: 92964
2010-01-07 23:44:37 +00:00
Benjamin Kramer
d2564e3afb
Move remaining stuff to the isInteger predicate.
...
llvm-svn: 92771
2010-01-05 21:05:54 +00:00
Benjamin Kramer
a81a6dff0d
Convert a ton of simple integer type equality tests to the new predicate.
...
llvm-svn: 92760
2010-01-05 20:07:06 +00:00
Dan Gohman
28943873e6
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
Chris Lattner
223812d547
prune some #includes.
...
llvm-svn: 92712
2010-01-05 07:54:43 +00:00
Chris Lattner
0a8191ee88
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
ed41b14f54
missed file with previous commit.
...
llvm-svn: 92710
2010-01-05 07:45:02 +00:00
Chris Lattner
e903f38b4d
eliminate getBitCastOperand and simplify some over-complex inbounds stuff.
...
llvm-svn: 92708
2010-01-05 07:42:10 +00:00
Chris Lattner
7a9e47ac4b
split call handling out to InstCombineCalls.cpp
...
llvm-svn: 92707
2010-01-05 07:32:13 +00:00
Chris Lattner
9da1cb243b
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
85e65e58ac
this inline function moved to addsub
...
llvm-svn: 92705
2010-01-05 07:20:54 +00:00
Chris Lattner
82aa888e8c
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
c7de92ae15
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
c6493f070e
eliminate AssociativeOpt and its last uses.
...
llvm-svn: 92697
2010-01-05 07:01:16 +00:00
Chris Lattner
94694c7f0b
inline the FoldICmpLogical functor.
...
llvm-svn: 92695
2010-01-05 06:59:49 +00:00
Chris Lattner
98d48a0b76
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
39b063bf37
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
dc054bf39a
split mul/div/rem instructions out to their own file.
...
llvm-svn: 92689
2010-01-05 06:09:35 +00:00
Chris Lattner
8f771cb78f
split select out to its own file.
...
llvm-svn: 92687
2010-01-05 06:03:12 +00:00
Chris Lattner
a65e2f7304
split out load/store/alloca.
...
llvm-svn: 92685
2010-01-05 05:57:49 +00:00
Chris Lattner
ec97a90221
split vector stuff out to InstCombineVectorOps.cpp
...
llvm-svn: 92683
2010-01-05 05:36:20 +00:00
Chris Lattner
de1feded32
split PHI node stuff out to InstCombinePHI.cpp
...
llvm-svn: 92682
2010-01-05 05:31:55 +00:00
Devang Patel
be94f23992
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
Chris Lattner
2cb08e69b1
silence a bogus 'might be used uninit' warning from GCC.
...
llvm-svn: 92494
2010-01-04 18:48:26 +00:00
Chris Lattner
59d95743c8
move some more cast-related stuff
...
llvm-svn: 92471
2010-01-04 07:59:07 +00:00
Chris Lattner
92be2adba6
move the [Can]EvaluateInDifferentType functions out to InstCombineCasts.cpp
...
llvm-svn: 92469
2010-01-04 07:54:59 +00:00
Chris Lattner
2b295a0eba
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
2188e40e4c
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
7e0449172c
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
35522b7465
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
b8906bda13
remove a ton of unneeded LLVMContext stuff.
...
llvm-svn: 92462
2010-01-04 07:02:48 +00:00
Chris Lattner
66c2e54bcd
move InstCombineWorklist out to its own header.
...
llvm-svn: 92461
2010-01-04 06:30:00 +00:00
Chris Lattner
c0e6640d3a
move instcombine to its own library, it's past time.
...
llvm-svn: 92459
2010-01-04 06:23:24 +00:00