summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix an unused variable warning in release builds.Craig Topper2015-05-231-0/+1
| | | | llvm-svn: 238094
* Use range-based for loops. NFC.Craig Topper2015-05-231-76/+36
| | | | llvm-svn: 238093
* Extend EarlyCSE to handle basic cases from JumpThreading and CVPPhilip Reames2015-05-223-21/+46
| | | | | | | | | | | | | | This patch extends EarlyCSE to take advantage of the information that a controlling branch gives us about the value of a Value within this and dominated basic blocks. If the current block has a single predecessor with a controlling branch, we can infer what the branch condition must have been to execute this block. The actual change to support this is downright simple because EarlyCSE's existing scoped hash table logic deals with most of the complexity around merging. The patch actually implements two optimizations. 1) The first is analogous to JumpThreading in that it enables EarlyCSE's CSE handling to fold branches which are exactly redundant due to a previous branch to branches on constants. (It doesn't actually replace the branch or change the CFG.) This is pretty clearly a win since it enables substantial CFG simplification before we start trying to inline. 2) The second is analogous to CVP in that it exploits the knowledge gained to replace dominated *uses* of the original value. EarlyCSE does not otherwise reason about specific uses, so this is the more arguable one. It does enable further simplication and constant folding within the rest of the visit by EarlyCSE. In both cases, the added code only handles the easy dominance based case of each optimization. The general case is deferred to the existing passes. Differential Revision: http://reviews.llvm.org/D9763 llvm-svn: 238071
* [InstCombine] Don't eagerly propagate nsw for A*B+A*C => A*(B+C)David Majnemer2015-05-221-3/+16
| | | | | | | | | | | | | | | | InstCombine transforms A *nsw B +nsw A *nsw C to A *nsw (B + C). This is incorrect -- e.g. if A = -1, B = 1, C = INT_SMAX. Then nothing in the LHS overflows, but the multiplication in RHS overflows. We need to first make sure that we won't multiple by INT_SMAX + 1. Test case `add_of_mul` contributed by Sanjoy Das. This fixes PR23635. Differential Revision: http://reviews.llvm.org/D9629 llvm-svn: 238066
* [Unroll] Separate the logic for testing each iteration of the loop,Chandler Carruth2015-05-221-106/+111
| | | | | | | | | | | | | | | | | | accumulating estimated cost, and other loop-centric logic from the logic used to analyze instructions in a particular iteration. This makes the visitor very narrow in scope -- all it does is visit instructions, update a map of simplified values, and return whether it is able to optimize away a particular instruction. The two cost metrics are now returned as an optional struct. When the optional is left unengaged, there is no information about the unrolled cost of the loop, when it is engaged the cost metrics are available to run against the thresholds. No functionality changed. llvm-svn: 238033
* [InstSimplify] Handle some overflow intrinsics in InstSimplifyDavid Majnemer2015-05-222-12/+6
| | | | | | | | | This change does a few things: - Move some InstCombine transforms to InstSimplify - Run SimplifyCall from within InstCombine::visitCallInst - Teach InstSimplify to fold [us]mul_with_overflow(X, undef) to 0. llvm-svn: 237995
* [Unroll] Replace a hand-wavy FIXME with a FIXME that explains the actualChandler Carruth2015-05-221-1/+6
| | | | | | | problem instead of suggesting doing something that is trivial to do but incorrect given the current design of the libraries. llvm-svn: 237994
* [Unroll] Extract the logic for caching SCEV-modeled GEPs with theirChandler Carruth2015-05-221-67/+81
| | | | | | | | | | | | | | | | | | | simplified model for use simulating each iteration into a separate helper function that just returns the cache. Building this cache had nothing to do with the rest of the unroll analysis and so this removes an unnecessary coupling, etc. It should also make it easier to think about the concept of providing fast cached access to basic SCEV models as an orthogonal concept to the overall unroll simulation. I'd really like to see this kind of caching logic folded into SCEV itself, it seems weird for us to provide it at this layer rather than making repeated queries into SCEV fast all on their own. No functionality changed. llvm-svn: 237993
* [Unroll] Refactor the accumulation of optimized instruction costs intoChandler Carruth2015-05-221-9/+10
| | | | | | | | | | | | a single location. This reduces code duplication a bit and will also pave the way for a better separation between the visitation algorithm and the unroll analysis. No functionality changed. llvm-svn: 237990
* [LICM] Sinking doesn't involve the preheaderPhilip Reames2015-05-221-5/+11
| | | | | | PR23608 pointed out that using the preheader to gain a context instruction isn't always legal because a loop might not have a preheader. When looking into that, I realized that using the preheader to determine legality for sinking is questionable at best. Given no test covers that case and the original commit didn't seem to intend it, I restructured the code to only ask context sensative queries for hoising of loads and stores. This is effectively a partial revert of 237593. llvm-svn: 237985
* MergedLoadStoreMotion preserves MemoryDependenceAnalysis, it does not ↵Daniel Berlin2015-05-221-2/+2
| | | | | | | | require it. (It already was coded assuming it can sometimes be null, so no other changes are necessary) llvm-svn: 237978
* [NaryReassoc] reassociate GEP for CSEJingyue Wu2015-05-211-21/+245
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: x = &a[i]; y = &a[i + j]; => y = x + j; along with some refactoring work such as extracting method findClosestMatchingDominator. Depends on D9786 which provides the ScalarEvolution::getGEPExpr interface. Test Plan: nary-gep.ll Reviewers: meheff, broune Reviewed By: broune Subscribers: jholewinski, llvm-commits Differential Revision: http://reviews.llvm.org/D9802 llvm-svn: 237971
* [InstCombine] X - 0 is equal to X, not undefDavid Majnemer2015-05-211-27/+21
| | | | | | | | | A refactoring made @llvm.ssub.with.overflow.i32(i32 %X, i32 0) transform into undef instead of %X. This fixes PR23624. llvm-svn: 237968
* [LoopDistribute] Remove a layer of pointer indirection.Benjamin Kramer2015-05-211-41/+32
| | | | | | | Just store InstPartitions directly into the std::list. No functional change intended. llvm-svn: 237930
* [RewriteStatepointsForGC] Fix debug assertion during derivable pointer ↵Igor Laevsky2015-05-211-6/+6
| | | | | | | | | | rematerialization Correct assertion would be that there is no other uses from chain we are currently cloning. It is ok to have other uses of values not from this chain. Differential Revision: http://reviews.llvm.org/D9882 llvm-svn: 237899
* [MemCpyOpt] Do move the memset, but look at its dest's dependencies.Ahmed Bougacha2015-05-211-1/+8
| | | | | | | | | In effect a partial revert of r237858, which was a dumb shortcut. Looking at the dependencies of the destination should be the proper fix: if the new memset would depend on anything other than itself, the transformation isn't correct. llvm-svn: 237874
* [MemCpyOpt] Pass Instruction to IRBuilder, no need for NextNode. NFC.Ahmed Bougacha2015-05-211-2/+2
| | | | | | We're erasing the instructions anyway. llvm-svn: 237861
* [MemCpyOpt] Don't move the memset when optimizing memset+memcpy.Ahmed Bougacha2015-05-201-1/+1
| | | | | | | | | | | | Fixes PR23599, another miscompile introduced by r235232: when there is another dependency on the destination of the created memset (i.e., the part of the original destination that the memcpy doesn't depend on) between the memcpy and the original memset, we would insert the created memset after the memcpy, and thus after the other dependency. Instead, insert the created memset right after the old one. llvm-svn: 237858
* Reapply r237539 with a fix for the Chromium build.James Molloy2015-05-205-7/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make sure if we're truncating a constant that would then be sign extended that the sign extension of the truncated constant is the same as the original constant. > Canonicalize min/max expressions correctly. > > This patch introduces a canonical form for min/max idioms where one operand > is extended or truncated. This often happens when the other operand is a > constant. For example: > > %1 = icmp slt i32 %a, i32 0 > %2 = sext i32 %a to i64 > %3 = select i1 %1, i64 %2, i64 0 > > Would now be canonicalized into: > > %1 = icmp slt i32 %a, i32 0 > %2 = select i1 %1, i32 %a, i32 0 > %3 = sext i32 %2 to i64 > > This builds upon a patch posted by David Majenemer > (https://www.marc.info/?l=llvm-commits&m=143008038714141&w=2). That pass > passively stopped instcombine from ruining canonical patterns. This > patch additionally actively makes instcombine canonicalize too. > > Canonicalization of expressions involving a change in type from int->fp > or fp->int are not yet implemented. llvm-svn: 237821
* Change Function::getIntrinsicID() to return an Intrinsic::ID. NFC.Pete Cooper2015-05-204-6/+6
| | | | | | | | Now that Intrinsic::ID is a typed enum, we can forward declare it and so return it from this method. This updates all users which were either using an unsigned to store it, or had a now unnecessary cast. llvm-svn: 237810
* Silencing a -Wsign-compare warning; NFC.Aaron Ballman2015-05-201-1/+1
| | | | llvm-svn: 237794
* Add a GCStrategy for CoreCLRSwaroop Sridhar2015-05-202-5/+14
| | | | | | | | | | | | | | This change adds a new GC strategy for supporting the CoreCLR runtime. This strategy is currently identical to Statepoint-example GC, but is necessary for several upcoming changes specific to CoreCLR, such as: 1. Base-pointers not explicitly reported for interior pointers 2. Different format for stack-map encoding 3. Location of Safe-point polls: polls are only needed before loop-back edges and before tail-calls (not needed at function-entry) 4. Runtime specific handshake between calls to managed/unmanaged functions. llvm-svn: 237753
* [PlaceSafepoints] Stop special casing some intrinsicsPhilip Reames2015-05-191-17/+36
| | | | | | We were special casing a handful of intrinsics as not needing a safepoint before them. After running into another valid case - memset - I took a closer look and realized that almost no intrinsics need to have a safepoint poll before them. Restructure the code to make that apparent so that we stop hitting these bugs. The only intrinsics which need a safepoint poll before them are ones which can run arbitrary code. llvm-svn: 237744
* Revert r237539: "Reapply r237520 with another fix for infinite looping"Hans Wennborg2015-05-195-63/+7
| | | | | | This caused PR23583. llvm-svn: 237739
* [Speculation] NFC: more header commentsJingyue Wu2015-05-191-0/+9
| | | | | | explaining how it differs from SpeculativeExecuteBB in SimplifyCFG. llvm-svn: 237724
* [RewriteStatepointsForGC] Fix up naming in "relocationViaAlloca" and run it ↵Igor Laevsky2015-05-191-56/+56
| | | | | | | | through clang-format. Differential Revision: http://reviews.llvm.org/D9774 llvm-svn: 237703
* Remove the InstructionSimplifierPass immediately after InstructionCombiningPass.Wei Mi2015-05-191-4/+0
| | | | | | | | | | InstructionCombiningPass was added after LoopUnrollPass in r237395. Because InstructionCombiningPass is strictly more powerful than InstructionSimplifierPass, remove the unnecessary InstructionSimplifierPass. Differential Revision: http://reviews.llvm.org/D9838 llvm-svn: 237702
* [RewriteStatepointsForGC] For some values (like gep's and bitcasts) it's ↵Igor Laevsky2015-05-191-6/+278
| | | | | | | | cheaper to clone them after statepoint than to emit proper relocates for them. This change implements this logic. There is alredy similar optimization in CodeGenPrepare, but doing so during RewriteStatepointsForGC allows to capture more opprtunities such as relocates in loops and longer instruction chains. Differential Revision: http://reviews.llvm.org/D9774 llvm-svn: 237701
* Simplify IRBuilder::CreateCall* by using ArrayRef+initializer_list/braced ↵David Blaikie2015-05-1815-153/+158
| | | | | | init only llvm-svn: 237624
* [PlaceSafepoints] Assertion on that gc_result can not have preceding phis ↵Chen Li2015-05-181-2/+2
| | | | | | | | | | | | | | | | should only apply to invoke statepoint Summary: When PlaceSafepoints pass replaces old return result with gc_result from statepoint, it asserts that gc_result can not have preceding phis in its parent block. This is only true on invoke statepoint, which terminates the block and puts its result at the beginning of the normal successor block. Call statepoint does not terminate the block and thus its result is in the same block with it. There should be no restriction on whether there are phis or not. Reviewers: reames, igor-laevsky Reviewed By: igor-laevsky Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9803 llvm-svn: 237597
* Exploit dereferenceable_or_null attribute in LICM passSanjoy Das2015-05-181-13/+15
| | | | | | | | | | | | | | | | | | | | Summary: Allow hoisting of loads from values marked with dereferenceable_or_null attribute. For values marked with the attribute perform context-sensitive analysis to determine whether it's known-non-null or not. Patch by Artur Pilipenko! Reviewers: hfinkel, sanjoy, reames Reviewed By: reames Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9253 llvm-svn: 237593
* [ScalarEvolution] refactor: extract interface getGEPExprJingyue Wu2015-05-181-15/+18
| | | | | | | | | | | | | | | | | | Summary: This allows other passes (such as SLSR) to compute the SCEV expression for an imaginary GEP. Test Plan: no regression Reviewers: atrick, sanjoy Reviewed By: sanjoy Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9786 llvm-svn: 237589
* indvars cruft: don't replace phi nodes for no reason.Andrew Trick2015-05-181-10/+0
| | | | | | | | | Don't replace a phi with an identical phi. This was done long ago to "preserve" IVUsers analysis. The code has already called SE->forgetValue(PN) so I see no purpose in creating a new value for the phi. llvm-svn: 237587
* SimplifyIV comments and dead argument cleanup.Andrew Trick2015-05-182-7/+5
| | | | | | Remove crufty comments. IVUsers hasn't been used here for a long time. llvm-svn: 237586
* Reapply r237520 with another fix for infinite loopingJames Molloy2015-05-175-7/+63
| | | | | | | | | SimplifyDemandedBits was "simplifying" a constant by removing just sign bits. This caused a canonicalization race between different parts of instcombine. Fix and regression test added - third time lucky? llvm-svn: 237539
* Revert commits r237521 and r237520.James Molloy2015-05-164-56/+7
| | | | | | | | The AArch64 LNT bot is unhappy - I've found that the problem is in SimpliftDemandedBits, but that's going to require another code review so reverting in the meantime. llvm-svn: 237528
* Move Pass into anonymous namespace. NFC.Benjamin Kramer2015-05-161-0/+2
| | | | llvm-svn: 237526
* Reapply r237453 with a fix for the test timeouts.James Molloy2015-05-164-7/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The test timeouts were due to instcombine fighting itself. Regression test added. Original log message: Canonicalize min/max expressions correctly. This patch introduces a canonical form for min/max idioms where one operand is extended or truncated. This often happens when the other operand is a constant. For example: %1 = icmp slt i32 %a, i32 0 %2 = sext i32 %a to i64 %3 = select i1 %1, i64 %2, i64 0 Would now be canonicalized into: %1 = icmp slt i32 %a, i32 0 %2 = select i1 %1, i32 %a, i32 0 %3 = sext i32 %2 to i64 This builds upon a patch posted by David Majenemer (https://www.marc.info/?l=llvm-commits&m=143008038714141&w=2). That pass passively stopped instcombine from ruining canonical patterns. This patch additionally actively makes instcombine canonicalize too. Canonicalization of expressions involving a change in type from int->fp or fp->int are not yet implemented. llvm-svn: 237520
* [MemCpyOpt] Turn memcpy from just-memset'd source into memset.Ahmed Bougacha2015-05-161-1/+45
| | | | | | | | | | | | | | | | | | | There's no point in copying around constants, so, when all else fails, we can still transform memcpy of memset into two independent memsets. To quote the example, we can turn: memset(dst1, c, dst1_size); memcpy(dst2, dst1, dst2_size); into: memset(dst1, c, dst1_size); memset(dst2, c, dst2_size); When dst2_size <= dst1_size. Like r235232 for copy constructors, this can occur in move constructors. Differential Revision: http://reviews.llvm.org/D9682 llvm-svn: 237506
* [MemCpyOpt] Remove dead argument. NFC.Ahmed Bougacha2015-05-161-6/+4
| | | | llvm-svn: 237503
* [NFC] remove an extra new lineJingyue Wu2015-05-151-1/+0
| | | | llvm-svn: 237462
* Add a speculative execution passJingyue Wu2015-05-154-0/+235
| | | | | | | | | | | | | | | | | | | | | | | Summary: This is a pass for speculative execution of instructions for simple if-then (triangle) control flow. It's aimed at GPUs, but could perhaps be used in other contexts. Enabling this pass gives us a 1.0% geomean improvement on Google benchmark suites, with one benchmark improving 33%. Credit goes to Jingyue Wu for writing an earlier version of this pass. Patched by Bjarke Roune. Test Plan: This patch adds a set of tests in test/Transforms/SpeculativeExecution/spec.ll The pass is controlled by a flag which defaults to having the pass not run. Reviewers: eliben, dberlin, meheff, jingyue, hfinkel Reviewed By: jingyue, hfinkel Subscribers: majnemer, jholewinski, llvm-commits Differential Revision: http://reviews.llvm.org/D9360 llvm-svn: 237459
* Revert "Canonicalize min/max expressions correctly."James Molloy2015-05-153-47/+7
| | | | | | | This reverts r237453 - it was causing timeouts on some bots. Reverting while I investigate (it's probably InstCombine fighting itself...) llvm-svn: 237458
* [SLSR] handle (B | i) * SJingyue Wu2015-05-151-3/+21
| | | | | | | | | | | | | | | | Summary: Consider (B | i) * S as (B + i) * S if B and i have no bits set in common. Test Plan: @or in slsr-mul.ll Reviewers: broune, meheff Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9788 llvm-svn: 237456
* Canonicalize min/max expressions correctly.James Molloy2015-05-153-7/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch introduces a canonical form for min/max idioms where one operand is extended or truncated. This often happens when the other operand is a constant. For example: %1 = icmp slt i32 %a, i32 0 %2 = sext i32 %a to i64 %3 = select i1 %1, i64 %2, i64 0 Would now be canonicalized into: %1 = icmp slt i32 %a, i32 0 %2 = select i1 %1, i32 %a, i32 0 %3 = sext i32 %2 to i64 This builds upon a patch posted by David Majenemer (https://www.marc.info/?l=llvm-commits&m=143008038714141&w=2). That pass passively stopped instcombine from ruining canonical patterns. This patch additionally actively makes instcombine canonicalize too. Canonicalization of expressions involving a change in type from int->fp or fp->int are not yet implemented. llvm-svn: 237453
* [PlaceSafepoints] Fix a bug that came in with rL236672.Sanjoy Das2015-05-151-0/+2
| | | | | | | | Transfer the calling convention from the invoke being replaced by PlaceStatepoints to the new invoke to gc.statepoint created. Add a test case that would have caught this issue. llvm-svn: 237414
* [PlaceSafepoints] Fix a bug that came in with rL236672.Sanjoy Das2015-05-151-1/+1
| | | | | | | | | rL236672 would generate all invoke statepoints with deopt args set to a list containing the single element "0", instead of an empty list. Also add a test case that would have caught this. llvm-svn: 237413
* [ValueTracking] refactor: extract method haveNoCommonBitsSetJingyue Wu2015-05-142-71/+47
| | | | | | | | | | | | | | | | | | | | | Summary: Extract method haveNoCommonBitsSet so that we don't have to duplicate this logic in InstCombine and SeparateConstOffsetFromGEP. This patch also makes SeparateConstOffsetFromGEP more precise by passing DominatorTree to computeKnownBits. Test Plan: value-tracking-domtree.ll that tests ValueTracking indeed leverages dominating conditions Reviewers: broune, meheff, majnemer Reviewed By: majnemer Subscribers: jholewinski, llvm-commits Differential Revision: http://reviews.llvm.org/D9734 llvm-svn: 237407
* Add another InstCombine pass after LoopUnroll.Wei Mi2015-05-141-0/+3
| | | | | | | | This is to cleanup some redundency generated by LoopUnroll pass. Such redundency may not be cleaned up by existing passes after LoopUnroll. Differential Revision: http://reviews.llvm.org/D9777 llvm-svn: 237395
* Don't rely on implicit pointerness of 'auto'. Davide Italiano2015-05-141-1/+1
| | | | | | | This ends up being a copy. Pointy hat to me. Reported by: dexonsmith, dblaikie llvm-svn: 237394
OpenPOWER on IntegriCloud