summaryrefslogtreecommitdiff
path: root/lib/Analysis/ConstantFolding.cpp
Commit message (Collapse)AuthorAge
...
* Revert 101465, it broke internal OpenGL testing.Eric Christopher2010-04-16
| | | | | | | | Probably the best way to know that all getOperand() calls have been handled is to replace that API instead of updating. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101579 91177308-0d34-0410-b5e6-96231b3b80d8
* reapply r101434Gabor Greif2010-04-16
| | | | | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101465 91177308-0d34-0410-b5e6-96231b3b80d8
* back out r101423 and r101397, they break llvm-gcc self-host on darwin10Gabor Greif2010-04-16
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101434 91177308-0d34-0410-b5e6-96231b3b80d8
* reapply r101364, which has been backed out in r101368Gabor Greif2010-04-15
| | | | | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101397 91177308-0d34-0410-b5e6-96231b3b80d8
* back out r101364, as it trips the linux nightlybot on some clang C++ testsGabor Greif2010-04-15
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101368 91177308-0d34-0410-b5e6-96231b3b80d8
* rotate CallInst operands, i.e. move callee to the backGabor Greif2010-04-15
| | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101364 91177308-0d34-0410-b5e6-96231b3b80d8
* Minor code simplification.Dan Gohman2010-04-12
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101009 91177308-0d34-0410-b5e6-96231b3b80d8
* FP16 constfoldingAnton Korobeynikov2010-03-19
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98911 91177308-0d34-0410-b5e6-96231b3b80d8
* Simplify this code.Dan Gohman2010-03-18
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98853 91177308-0d34-0410-b5e6-96231b3b80d8
* When constant folding GEP of GEP, do not crash if an index ofDuncan Sands2010-03-12
| | | | | | | the inner GEP is not a ConstantInt. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98359 91177308-0d34-0410-b5e6-96231b3b80d8
* Constant-fold GEP-of-GEP into a single GEP.Dan Gohman2010-03-10
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98178 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove the code which constant-folded ptrtoint(inttoptr(x)+c) toDan Gohman2010-02-23
| | | | | | | | | | | | getelementptr. Despite only doing so in the case where x is a known array object and c can be converted to an index within range, this could still be invalid if c is actually the address of an object allocated outside of LLVM. Also, SCEVExpander, the original motivation for this code, has since been improved to avoid inttoptr+ptroint in more cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96950 91177308-0d34-0410-b5e6-96231b3b80d8
* Canonicalize ConstantInts to the right operand of commutativeDan Gohman2010-02-22
| | | | | | | | | | | operators. The test difference is just due to the multiplication operands being commuted (and thus requiring a more elaborate match). In optimized code, that expression would be folded. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96816 91177308-0d34-0410-b5e6-96231b3b80d8
* Minor formatting cleanup.Dan Gohman2010-02-22
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96808 91177308-0d34-0410-b5e6-96231b3b80d8
* Fold bswap(undef) to undef.Dan Gohman2010-02-17
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96432 91177308-0d34-0410-b5e6-96231b3b80d8
* There are two ways of checking for a given type, for example isa<PointerType>(T)Duncan Sands2010-02-16
| | | | | | | | and T->isPointerTy(). Convert most instances of the first form to the second form. Requested by Chris. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96344 91177308-0d34-0410-b5e6-96231b3b80d8
* Uniformize the names of type predicates: rather than having isFloatTy andDuncan Sands2010-02-15
| | | | | | | isInteger, we now have isFloatTy and isIntegerTy. Requested by Chris! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96223 91177308-0d34-0410-b5e6-96231b3b80d8
* Add const qualifiers.Dan Gohman2010-02-08
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95582 91177308-0d34-0410-b5e6-96231b3b80d8
* Generalize target-independent folding rules for sizeof to handle moreDan Gohman2010-02-01
| | | | | | | | | | | | | | | | | | | | cases, and implement target-independent folding rules for alignof and offsetof. Also, reassociate reassociative operators when it leads to more folding. Generalize ScalarEvolution's isOffsetOf to recognize offsetof on arrays. Rename getAllocSizeExpr to getSizeOfExpr, and getFieldOffsetExpr to getOffsetOfExpr, for consistency with analagous ConstantExpr routines. Make the target-dependent folder promote GEP array indices to pointer-sized integers, to make implicit casting explicit and exposed to subsequent folding. And add a bunch of testcases for this new functionality, and a bunch of related existing functionality. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94987 91177308-0d34-0410-b5e6-96231b3b80d8
* fix PR5978 by peeling the loop so that we avoid shifting theChris Lattner2010-01-08
| | | | | | | | result int by 8 for the first byte. While normally harmless, if the result is smaller than a byte, this shift is invalid. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93018 91177308-0d34-0410-b5e6-96231b3b80d8
* constant fold nasty constant expressions formed by llvm-gcc,Chris Lattner2010-01-02
| | | | | | | wrapping up PR3351. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92410 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix PR5551 by not ignoring the top level constantexpr whenChris Lattner2009-12-04
| | | | | | | folding a load from constant. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90545 91177308-0d34-0410-b5e6-96231b3b80d8
* fix PR5673 by being more careful about pointers to functions.Chris Lattner2009-12-03
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90369 91177308-0d34-0410-b5e6-96231b3b80d8
* Teach ConstantFolding to do a better job when folding gep(bitcast).Nick Lewycky2009-11-29
| | | | | | | This permits the devirtualization of llvm.org/PR3100#c9 when compiled by clang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90099 91177308-0d34-0410-b5e6-96231b3b80d8
* Make ConstantFoldConstantExpression recursively visit the entireDan Gohman2009-11-23
| | | | | | | | | | | ConstantExpr, not just the top-level operator. This allows it to fold many more constants. Also, make GlobalOpt call ConstantFoldConstantExpression on GlobalVariable initializers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89659 91177308-0d34-0410-b5e6-96231b3b80d8
* fix ConstantFoldCompareInstOperands to take the LHS/RHS asChris Lattner2009-11-09
| | | | | | | individual operands instead of taking a temporary array git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86619 91177308-0d34-0410-b5e6-96231b3b80d8
* remove a bunch of extraneous LLVMContext argumentsChris Lattner2009-11-06
| | | | | | | from various APIs, addressing PR5325. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86231 91177308-0d34-0410-b5e6-96231b3b80d8
* Teach FoldBitCast to be able to handle bitcasts from (e.g.) i128 -> <4 x float>.Chris Lattner2009-10-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows us to simplify this: union vec2d { double e[2]; double v __attribute__((vector_size(16))); }; typedef union vec2d vec2d; static vec2d a={{1,2}}, b={{3,4}}; vec2d foo () { return (vec2d){ .v = a.v + b.v * (vec2d){{5,5}}.v }; } down to: define %0 @foo() nounwind ssp { entry: %mrv5 = insertvalue %0 undef, double 1.600000e+01, 0 ; <%0> [#uses=1] %mrv6 = insertvalue %0 %mrv5, double 2.200000e+01, 1 ; <%0> [#uses=1] ret %0 %mrv6 } instead of: define %0 @foo() nounwind ssp { entry: %mrv5 = insertvalue %0 undef, double extractelement (<2 x double> fadd (<2 x double> fmul (<2 x double> bitcast (<1 x i128> <i128 85174437667405312423031577302488055808> to <2 x double>), <2 x double> <double 3.000000e+00, double 4.000000e+00>), <2 x double> <double 1.000000e+00, double 2.000000e+00>), i32 0), 0 ; <%0> [#uses=1] %mrv6 = insertvalue %0 %mrv5, double extractelement (<2 x double> fadd (<2 x double> fmul (<2 x double> bitcast (<1 x i128> <i128 85174437667405312423031577302488055808> to <2 x double>), <2 x double> <double 3.000000e+00, double 4.000000e+00>), <2 x double> <double 1.000000e+00, double 2.000000e+00>), i32 1), 1 ; <%0> [#uses=1] ret %0 %mrv6 } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85040 91177308-0d34-0410-b5e6-96231b3b80d8
* move FoldBitCast earlier in the file, and use it instead of Chris Lattner2009-10-25
| | | | | | | ConstantExpr::getBitCast in various places. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85039 91177308-0d34-0410-b5e6-96231b3b80d8
* refactor FoldBitCast to reduce nesting and to always return a constantexprChris Lattner2009-10-25
| | | | | | | instead of returning null on failure. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85038 91177308-0d34-0410-b5e6-96231b3b80d8
* various cleanups suggested by DuncanChris Lattner2009-10-24
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84993 91177308-0d34-0410-b5e6-96231b3b80d8
* fix PR5287, a serious regression from my previous patches. Thanks toChris Lattner2009-10-24
| | | | | | | Duncan for the nice tiny testcase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84992 91177308-0d34-0410-b5e6-96231b3b80d8
* teach libanalysis to simplify vector loads with bitcast sources. ThisChris Lattner2009-10-23
| | | | | | | | | | | | | | | | | | | | | | | | implements something out of Target/README.txt producing: _foo: ## @foo movl 4(%esp), %eax movapd LCPI1_0, %xmm0 movapd %xmm0, (%eax) ret $4 instead of: _foo: ## @foo movl 4(%esp), %eax movapd _b, %xmm0 mulpd LCPI1_0, %xmm0 addpd _a, %xmm0 movapd %xmm0, (%eax) ret $4 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84942 91177308-0d34-0410-b5e6-96231b3b80d8
* enhance FoldReinterpretLoadFromConstPtr to handle loads of up to 32 Chris Lattner2009-10-23
| | | | | | | bytes (i256). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84941 91177308-0d34-0410-b5e6-96231b3b80d8
* teach libanalysis to fold int and fp loads from almost arbitraryChris Lattner2009-10-23
| | | | | | | | | | | | | | | | | | | | | non-type-safe constant initializers. This sort of thing happens quite a bit for 4-byte loads out of string constants, unions, bitfields, and an interesting endianness check from sqlite, which is something like this: const int sqlite3one = 1; # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) all of these macros now constant fold away. This implements PR3152 and is based on a patch started by Eli, but heavily modified and extended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84936 91177308-0d34-0410-b5e6-96231b3b80d8
* move another load optimization from instcombine -> libanalysis.Chris Lattner2009-10-22
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84841 91177308-0d34-0410-b5e6-96231b3b80d8
* move 'loading i32 from string' optimization from instcombineChris Lattner2009-10-22
| | | | | | | | to libanalysis. Instcombine shrinking... does this even make sense??? git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84840 91177308-0d34-0410-b5e6-96231b3b80d8
* Move some constant folding logic for loads out of instcombine intoChris Lattner2009-10-22
| | | | | | | | | | | Analysis/ConstantFolding.cpp. This doesn't change the behavior of instcombine but makes other clients of ConstantFoldInstruction able to handle loads. This was partially extracted from Eli's patch in PR3152. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84836 91177308-0d34-0410-b5e6-96231b3b80d8
* Extend ConstantFolding to understand signed overflow variantsEvan Phoenix2009-10-05
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83338 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove an unnnecessary LLVMContext argument inDan Gohman2009-10-05
| | | | | | | ConstantFoldLoadThroughGEPConstantExpr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83311 91177308-0d34-0410-b5e6-96231b3b80d8
* teach the optimizer how to constant fold uadd/usub intrinsics.Chris Lattner2009-10-05
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83295 91177308-0d34-0410-b5e6-96231b3b80d8
* simplify this code a bunch.Chris Lattner2009-10-05
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83294 91177308-0d34-0410-b5e6-96231b3b80d8
* code simplifications.Chris Lattner2009-10-05
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83292 91177308-0d34-0410-b5e6-96231b3b80d8
* simplify some codeChris Lattner2009-09-16
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81961 91177308-0d34-0410-b5e6-96231b3b80d8
* Teach lib/VMCore/ConstantFold.cpp how to set the inbounds keyword andDan Gohman2009-09-11
| | | | | | | | | | | | | | how to fold notionally-out-of-bounds array getelementptr indices instead of just doing these in lib/Analysis/ConstantFolding.cpp, because it can be done in a fairly general way without TargetData, and because not all constants are visited by lib/Analysis/ConstantFolding.cpp. This enables more constant folding. Also, set the "inbounds" flag when the getelementptr indices are one-past-the-end. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81483 91177308-0d34-0410-b5e6-96231b3b80d8
* Give these files top-level comments that describe the current code.Dan Gohman2009-09-10
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81473 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert 80959. It isn't sufficient to solve the full problem. And itDan Gohman2009-09-03
| | | | | | | introduced regressions in the Ocaml bindings tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80969 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove the API for creating ConstantExprs with the nsw, nuw, inbounds,Dan Gohman2009-09-03
| | | | | | | | | | | | | | | | and exact flags. Because ConstantExprs are uniqued, creating an expression with this flag causes all expressions with the same operands to have the same flag, which may not be safe. Add, sub, mul, and sdiv ConstantExprs are usually folded anyway, so the main interesting flag here is inbounds, and the constant folder already knows how to set the inbounds flag automatically in most cases, so there isn't an urgent need for the API support. This can be reconsidered in the future, but for now just removing these API bits eliminates a source of potential trouble with little downside. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80959 91177308-0d34-0410-b5e6-96231b3b80d8
* fix PR4848 an infinite loop when indexing down through a recursive gepChris Lattner2009-09-02
| | | | | | | | and we get the original pointer type. This doesn't mean that we're at the first pointer being indexed. Correct the predicate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80762 91177308-0d34-0410-b5e6-96231b3b80d8
* Don't assume that the operand of an inttoptr is an pointer-sized integer.Dan Gohman2009-08-21
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79651 91177308-0d34-0410-b5e6-96231b3b80d8