summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Third time's a charm.Bill Wendling2008-11-101-60/+58
| | | | | | | The previous patches didn't match correctly. Also, we need to make sure that the conditional is the same before doing the transformation. llvm-svn: 58978
* Added support for the following definition of shufflevector Mon P Wang2008-11-101-17/+30
| | | | | | <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> llvm-svn: 58964
* Correction for the last patch. Should match the conditional in the first partBill Wendling2008-11-091-34/+42
| | | | | | of the select match, not the select instruction itself. llvm-svn: 58947
* The method of doing the matching with a 'select' instruction was wrong. TheBill Wendling2008-11-091-32/+39
| | | | | | | | | | | | | | | | | | original code was matching like this: if (match(A, m_Not(m_Value(B)))) B was already matched as a 'select' instruction. However, this isn't matching what we think it's matching. It would match B as a 'Value', so basically anything would match to it. In this case, a Constant matched. B was replaced with a constant representation. And then the wrong value would be used in the SelectInst::Create statement, causing a crash. After thinking on this for a moment, and after Nick L. told me how the pattern matching stuff was supposed to work, the solution was to match NOT an m_Value, but an m_Select. llvm-svn: 58946
* If the LHS of the FCMP is coming from a UIToFP instruction, then we don't wantBill Wendling2008-11-091-33/+88
| | | | | | | | | | | | | | | | | | | | | | | to generate signed ICMP instructions to replace the FCMP. This would violate the following: define i1 @test1(i32 %val) { %1 = uitofp i32 %val to double %2 = fcmp ole double %1, 0.000000e+00 ret i1 %2 } would be transformed into: define i1 @test1(i32 %val) { %1 = icmp slt i33 %val, 1 ret i1 %1 } which is obviously wrong. This patch modifes InstCombiner::FoldFCmp_IntToFP_Cst to handle when the LHS comes from UIToFP. llvm-svn: 58929
* Fixed scalarizing an extract subvector and prevent an infinite loopMon P Wang2008-11-061-0/+6
| | | | | | when simplify a vector. llvm-svn: 58820
* Fix demanded bits analysis with srem by negative number. Based on a patchNick Lewycky2008-11-021-3/+3
| | | | | | by Richard Osborne. llvm-svn: 58555
* Fix this recently moved code to use the correct type. CI is now aDan Gohman2008-11-021-2/+2
| | | | | | | ConstantInt, and SI is the original cast instruction. This fixes PR2996. llvm-svn: 58549
* Canonicalize sext(i1) to i1?-1:0, and update various instcombineDan Gohman2008-10-301-40/+91
| | | | | | optimizations accordingly. llvm-svn: 58457
* (A & sext(C)) | (B & ~sext(C) -> C ? A : BDan Gohman2008-10-281-0/+19
| | | | llvm-svn: 58351
* Teach instcombine's visitLoad to scan back several instructionsDan Gohman2008-10-151-10/+46
| | | | | | | | | | | | | | to find opportunities for store-to-load forwarding or load CSE, in the same way that visitStore scans back to do DSE. Also, define a new helper function for testing whether the addresses of two memory accesses are known to have the same value, and use it in both visitStore and visitLoad. These two changes allow instcombine to eliminate loads in code produced by front-ends that frequently emit obviously redundant addressing for memory references. llvm-svn: 57608
* Combine (fcmp cc0 x, y) | (fcmp cc1 x, y) into a single fcmp when possible.Evan Cheng2008-10-141-1/+41
| | | | llvm-svn: 57515
* - Somehow I forgot about one / une.Evan Cheng2008-10-141-9/+21
| | | | | | | - Renumber fcmp predicates to match their icmp counterparts. - Try swapping operands to expose more optimization opportunities. llvm-svn: 57513
* Optimize anding of two fcmp into a single fcmp if the operands are the same. ↵Evan Cheng2008-10-141-3/+111
| | | | | | | | | e.g. uno && ueq -> ueq ord && olt -> olt ord && ueq -> oeq llvm-svn: 57507
* Make InstructionCombining::getBitCastOperand() recognize GEP instructions andMatthijs Kooijman2008-10-131-3/+23
| | | | | | constant expression with all zero indices as being the same as a bitcast. llvm-svn: 57442
* Fix PR2697 by rewriting the '(X / pos) op neg' logic. This also changesChris Lattner2008-10-111-10/+15
| | | | | | | | a couple other cases for clarity, but shouldn't affect correctness. Patch by Eli Friedman! llvm-svn: 57387
* Add a "loses information" return value to APFloat::convertDale Johannesen2008-10-091-1/+3
| | | | | | | and APFloat::convertToInteger. Restore return value to IEEE754. Adjust all users accordingly. llvm-svn: 57329
* Add parentheses to avoid warnings in GCC 4.4.0,Chris Lattner2008-10-081-1/+1
| | | | | | patch by Samuel Tardieu! llvm-svn: 57288
* rewrite bswap matching to be more general, allowing arbitraryChris Lattner2008-10-051-77/+121
| | | | | | | | shifting and masking inside a bswap expr. This allows it to handle the cases from PR2842, which involve the intermediate 'or' expressions being shifted, not just the input value. llvm-svn: 57095
* fix a bug where the bswap matcher could match a case involvingChris Lattner2008-10-051-1/+4
| | | | | | ashr. It should only apply to lshr. llvm-svn: 57089
* Factorize code: remove variants of "strip offDuncan Sands2008-10-011-23/+1
| | | | | | | | | | | pointer bitcasts and GEP's", and centralize the logic in Value::getUnderlyingObject. The difference with stripPointerCasts is that stripPointerCasts only strips GEPs if all indices are zero, while getUnderlyingObject strips GEPs no matter what the indices are. llvm-svn: 56922
* Fix misoptimization of: xor i1 (icmp eq (X, C1), icmp s[lg]t (X, C2))Nick Lewycky2008-09-301-2/+3
| | | | llvm-svn: 56834
* Now Attributes are divided in three groupsDevang Patel2008-09-261-9/+17
| | | | | | | | | | | | | - return attributes - inreg, zext and sext - parameter attributes - function attributes - nounwind, readonly, readnone, noreturn Return attributes use 0 as the index. Function attributes use ~0U as the index. This patch requires corresponding changes in llvm-gcc and clang. llvm-svn: 56704
* Large mechanical patch.Devang Patel2008-09-251-32/+32
| | | | | | | | | | | | | | | s/ParamAttr/Attribute/g s/PAList/AttrList/g s/FnAttributeWithIndex/AttributeWithIndex/g s/FnAttr/Attribute/g This sets the stage - to implement function notes as function attributes and - to distinguish between function attributes and return value attributes. This requires corresponding changes in llvm-gcc and clang. llvm-svn: 56622
* s/ParamAttrsWithIndex/FnAttributeWithIndex/gDevang Patel2008-09-241-8/+8
| | | | llvm-svn: 56535
* s/ParameterAttributes/Attributes/gDevang Patel2008-09-231-8/+8
| | | | llvm-svn: 56513
* Improve instcombine's handling of integer min and max in two ways:Dan Gohman2008-09-161-29/+115
| | | | | | | | | | | | | | | | - Recognize expressions like "x > -1 ? x : 0" as min/max and turn them into expressions like "x < 0 ? 0 : x", which is easily recognizable as a min/max operation. - Refrain from folding expression like "y/2 < 1" to "y < 2" when the comparison is being used as part of a min or max idiom, like "y/2 < 1 ? 1 : y/2". In that case, the division has another use, so folding doesn't eliminate it, and obfuscates the min/max, making it harder to recognize as a min/max operation. These benefit ScalarEvolution, CodeGen, and anything else that wants to recognize integer min and max. llvm-svn: 56246
* On 64-bit targets, change 32-bit getelementptr indices to be 64-bitDan Gohman2008-09-111-1/+12
| | | | | | | getelementptr indices, inserting an explicit cast if necessary. This helps expose the sign-extension operation to other optimizations. llvm-svn: 56133
* Fix a vectorshuffle instcombine bug introduced by r55995.Dan Gohman2008-09-111-1/+4
| | | | | | Patch by Nicolas Capens! llvm-svn: 56129
* Fix a copy+paste bug that Duncan spotted. For severalDan Gohman2008-09-111-1/+1
| | | | | | | cases it was still getting lucky and detecting overflow but it was clearly incorrect. llvm-svn: 56113
* In my analysis for r56076 I missed the case where the originalDan Gohman2008-09-111-1/+2
| | | | | | multiplication overflows. llvm-svn: 56082
* Fix an icmp+sdiv optimization to check for and handle an overflowDan Gohman2008-09-101-1/+16
| | | | | | condition. This fixes PR2740. llvm-svn: 56076
* Fix a warning about comparing signed and unsigned values.Dan Gohman2008-09-101-1/+1
| | | | llvm-svn: 56040
* Make SimplifyDemandedVectorElts simplify vectors with multipleDan Gohman2008-09-091-34/+82
| | | | | | | | | | | | users, and teach it about shufflevector instructions. Also, fix a subtle bug in SimplifyDemandedVectorElts' insertelement code. This is a patch that was originally written by Eli Friedman, with some fixes and cleanup by me. llvm-svn: 55995
* Tidy up several unbeseeming casts from pointer to intptr_t.Dan Gohman2008-09-041-1/+1
| | | | llvm-svn: 55779
* Don't apply this transform to vectors. Fixes PR2756.Nick Lewycky2008-09-031-3/+4
| | | | llvm-svn: 55690
* Revert r54876 r54877 r54906 and r54907. Evan found that these caused a 20%Nick Lewycky2008-08-211-68/+22
| | | | | | slowdown in bzip2. llvm-svn: 55113
* Silence a compiler warning.Evan Cheng2008-08-201-1/+2
| | | | llvm-svn: 55087
* Fixed shuffle optimizations to handle non power of 2 vectorsMon P Wang2008-08-201-4/+4
| | | | llvm-svn: 55035
* Make this comment clearer. Instead of using an ambiguous ~ (not) on an icmpNick Lewycky2008-08-171-1/+1
| | | | | | predicate, swap the order of the operands. llvm-svn: 54907
* Consider the case where xor by -1 and xor by 128 have been combined already toNick Lewycky2008-08-171-1/+23
| | | | | | produce an xor by 127. llvm-svn: 54906
* I found a better place for this optz'n.Nick Lewycky2008-08-171-14/+10
| | | | llvm-svn: 54877
* Xor'ing both sides of icmp by sign-bit is equivalent to swapping signedness ofNick Lewycky2008-08-171-22/+50
| | | | | | | | the predicate. Also, make this optz'n apply in more cases where it's safe to do so. llvm-svn: 54876
* use smallvector instead of vector for a couple worklists. This speeds up ↵Chris Lattner2008-08-151-2/+2
| | | | | | | | instcombine by ~10% on some testcases. llvm-svn: 54811
* Fix a bogus srem rule - a negative value srem'd by a power-of-2Dan Gohman2008-08-131-3/+0
| | | | | | | can have a non-negative result; for example, -16%16 is 0. Also, clarify the related comments. This fixes PR2670. llvm-svn: 54767
* Implement support for simplifying vector comparisons by 0.0 and 1.0 like weChris Lattner2008-08-111-4/+12
| | | | | | | | | do for scalars. Patch contributed by Nicolas Capens This also generalizes the previous xforms to work on long double, now that isExactlyValue works for long double. llvm-svn: 54653
* Fix a shufflevector instcombine that was emitting invalid masks indicesDan Gohman2008-08-061-3/+5
| | | | | | when it meant to be emitting undef indices. llvm-svn: 54417
* optimize a common idiom generated by clang for bitfield access, PR2638.Chris Lattner2008-08-061-1/+31
| | | | llvm-svn: 54408
* Zap sitofp/fptoui pairs. In all cases when the sign difference Chris Lattner2008-08-061-16/+30
| | | | | | matters, the result is undefined anyway. llvm-svn: 54396
* Reinstate this optimization, but without the miscompile. Thanks to Bill forNick Lewycky2008-08-061-0/+15
| | | | | | tracking down that this was breaking llvm-gcc bootstrap on Linux. llvm-svn: 54394
OpenPOWER on IntegriCloud