summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ConstantFolding.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Teach FoldBitCast to be able to handle bitcasts from (e.g.) i128 -> <4 x float>.Chris Lattner2009-10-251-4/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 } llvm-svn: 85040
* move FoldBitCast earlier in the file, and use it instead of Chris Lattner2009-10-251-132/+132
| | | | | | ConstantExpr::getBitCast in various places. llvm-svn: 85039
* refactor FoldBitCast to reduce nesting and to always return a constantexprChris Lattner2009-10-251-104/+109
| | | | | | instead of returning null on failure. No functionality change. llvm-svn: 85038
* various cleanups suggested by DuncanChris Lattner2009-10-241-3/+5
| | | | llvm-svn: 84993
* fix PR5287, a serious regression from my previous patches. Thanks toChris Lattner2009-10-241-0/+1
| | | | | | Duncan for the nice tiny testcase. llvm-svn: 84992
* teach libanalysis to simplify vector loads with bitcast sources. ThisChris Lattner2009-10-231-7/+13
| | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 84942
* enhance FoldReinterpretLoadFromConstPtr to handle loads of up to 32 Chris Lattner2009-10-231-6/+8
| | | | | | bytes (i256). llvm-svn: 84941
* teach libanalysis to fold int and fp loads from almost arbitraryChris Lattner2009-10-231-8/+185
| | | | | | | | | | | | | | | | | | | 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. llvm-svn: 84936
* move another load optimization from instcombine -> libanalysis.Chris Lattner2009-10-221-34/+48
| | | | llvm-svn: 84841
* move 'loading i32 from string' optimization from instcombineChris Lattner2009-10-221-6/+35
| | | | | | | to libanalysis. Instcombine shrinking... does this even make sense??? llvm-svn: 84840
* Move some constant folding logic for loads out of instcombine intoChris Lattner2009-10-221-0/+35
| | | | | | | | | 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. llvm-svn: 84836
* Extend ConstantFolding to understand signed overflow variantsEvan Phoenix2009-10-051-0/+24
| | | | llvm-svn: 83338
* Remove an unnnecessary LLVMContext argument inDan Gohman2009-10-051-2/+1
| | | | | | ConstantFoldLoadThroughGEPConstantExpr. llvm-svn: 83311
* teach the optimizer how to constant fold uadd/usub intrinsics.Chris Lattner2009-10-051-1/+29
| | | | llvm-svn: 83295
* simplify this code a bunch.Chris Lattner2009-10-051-14/+14
| | | | llvm-svn: 83294
* code simplifications.Chris Lattner2009-10-051-16/+25
| | | | llvm-svn: 83292
* simplify some codeChris Lattner2009-09-161-6/+5
| | | | llvm-svn: 81961
* Teach lib/VMCore/ConstantFold.cpp how to set the inbounds keyword andDan Gohman2009-09-111-6/+2
| | | | | | | | | | | | | 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. llvm-svn: 81483
* Give these files top-level comments that describe the current code.Dan Gohman2009-09-101-3/+7
| | | | llvm-svn: 81473
* Revert 80959. It isn't sufficient to solve the full problem. And itDan Gohman2009-09-031-12/+6
| | | | | | introduced regressions in the Ocaml bindings tests. llvm-svn: 80969
* Remove the API for creating ConstantExprs with the nsw, nuw, inbounds,Dan Gohman2009-09-031-6/+12
| | | | | | | | | | | | | | | 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. llvm-svn: 80959
* fix PR4848 an infinite loop when indexing down through a recursive gepChris Lattner2009-09-021-1/+1
| | | | | | | and we get the original pointer type. This doesn't mean that we're at the first pointer being indexed. Correct the predicate. llvm-svn: 80762
* Don't assume that the operand of an inttoptr is an pointer-sized integer.Dan Gohman2009-08-211-1/+3
| | | | llvm-svn: 79651
* Change getelementptr folding to use APInt instead of uint64_t forDan Gohman2009-08-211-11/+15
| | | | | | | offset computations. This fixes a truncation bug on targets that don't have 64-bit pointers. llvm-svn: 79639
* Various comment and whitespace cleanups.Dan Gohman2009-08-201-1/+1
| | | | llvm-svn: 79533
* Fix a bug in the over-index constant folding. When over-indexing anDan Gohman2009-08-191-8/+24
| | | | | | | | array member of a struct, it's possible to land in an arbitrary position inside that struct, such that attempting to find further getelementptr indices will fail. In such cases, folding cannot be done. llvm-svn: 79485
* Canonicalize indices in a constantexpr GEP. If Indices exceed theDan Gohman2009-08-191-4/+48
| | | | | | | | static extents of the static array type, it causes GlobalOpt and other passes to be more conservative. This canonicalization also allows the constant folder to add "inbounds" to GEPs. llvm-svn: 79440
* Push LLVMContexts through the IntegerType APIs.Owen Anderson2009-08-131-14/+17
| | | | llvm-svn: 78948
* Move a few more APIs back to 2.5 forms. The only remaining ones left to ↵Owen Anderson2009-07-311-9/+9
| | | | | | | | change back are metadata related, which I'm waiting on to avoid conflicting with Devang. llvm-svn: 77721
* Move more code back to 2.5 APIs.Owen Anderson2009-07-301-4/+4
| | | | llvm-svn: 77635
* Move types back to the 2.5 API.Owen Anderson2009-07-291-4/+4
| | | | llvm-svn: 77516
* Move ConstantExpr to 2.5 API.Owen Anderson2009-07-291-26/+26
| | | | llvm-svn: 77494
* Return ConstantVector to 2.5 API.Owen Anderson2009-07-281-1/+1
| | | | llvm-svn: 77366
* Move ConstantFP construction back to the 2.5-ish API.Owen Anderson2009-07-271-6/+6
| | | | llvm-svn: 77247
* Remove Value::getNameLenDaniel Dunbar2009-07-261-78/+44
| | | | llvm-svn: 77148
* Revert the ConstantInt constructors back to their 2.5 forms where possible, ↵Owen Anderson2009-07-241-10/+10
| | | | | | thanks to contexts-on-types. More to come. llvm-svn: 77011
* Get rid of the Pass+Context magic.Owen Anderson2009-07-221-71/+71
| | | | llvm-svn: 76702
* llvm_unreachable->llvm_unreachable(0), LLVM_UNREACHABLE->llvm_unreachable.Torok Edwin2009-07-141-3/+3
| | | | | | | | | This adds location info for all llvm_unreachable calls (which is a macro now) in !NDEBUG builds. In NDEBUG builds location info and the message is off (it only prints "UREACHABLE executed"). llvm-svn: 75640
* assert(0) -> LLVM_UNREACHABLE.Torok Edwin2009-07-111-3/+4
| | | | | | | | | Make llvm_unreachable take an optional string, thus moving the cerr<< out of line. LLVM_UNREACHABLE is now a simple wrapper that makes the message go away for NDEBUG builds. llvm-svn: 75379
* Remove the vicmp and vfcmp instructions. Because we never had a release withNick Lewycky2009-07-081-2/+0
| | | | | | | these instructions, no autoupgrade or backwards compatibility support is provided. llvm-svn: 74991
* "LLVMContext* " --> "LLVMContext *"Owen Anderson2009-07-061-11/+11
| | | | llvm-svn: 74878
* Thread LLVMContext through the constant folding APIs, which touches a lot of ↵Owen Anderson2009-07-061-102/+120
| | | | | | files. llvm-svn: 74844
* Support vector casts in more places, fixing a variety of assertionDan Gohman2009-06-151-2/+2
| | | | | | | | | | | | | | | 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
* Change ConstantFoldConstantExpression to accept a nullDan Gohman2009-06-021-2/+0
| | | | | | | | | | | TargetData pointer. The only thing it's used for are calls to ConstantFoldCompareInstOperands and ConstantFoldInstOperands, which both already accept a null TargetData pointer. This makes ConstantFoldConstantExpression easier to use in clients where TargetData is optional. llvm-svn: 72741
* Use v.data() instead of &v[0] when SmallVector v might be empty.Jay Foad2009-05-211-5/+5
| | | | llvm-svn: 72210
* Rename PaddedSize to AllocSize, in the hope that thisDuncan Sands2009-05-091-3/+3
| | | | | | | will make it more obvious what it represents, and stop it being confused with the StoreSize. llvm-svn: 71349
* Revert 71165. It did more than just revert 71158 and it introducedDan Gohman2009-05-071-4/+36
| | | | | | several regressions. The problem due to 71158 is now fixed. llvm-svn: 71176
* Temporarily revert r71158. It was causing a failure during a full bootstrap:Bill Wendling2009-05-071-36/+4
| | | | | | | | | | | | | | | | | | | | | checking for bcopy... no checking for getc_unlocked... Assertion failed: (0 && "Unknown SCEV kind!"), function operator(), file /Volumes/Sandbox/Buildbot/llvm/full-llvm/build/llvmCore.roots/llvmCore~obj/src/lib/Analysis/ScalarEvolution.cpp, line 511. /Volumes/Sandbox/Buildbot/llvm/full-llvm/build/llvmgcc42.roots/llvmgcc42~obj/src/libdecnumber/decUtility.c:360: internal compiler error: Abort trap Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://developer.apple.com/bugreporter> for instructions. make[4]: *** [decUtility.o] Error 1 make[4]: *** Waiting for unfinished jobs.... Assertion failed: (0 && "Unknown SCEV kind!"), function operator(), file /Volumes/Sandbox/Buildbot/llvm/full-llvm/build/llvmCore.roots/llvmCore~obj/src/lib/Analysis/ScalarEvolution.cpp, line 511. /Volumes/Sandbox/Buildbot/llvm/full-llvm/build/llvmgcc42.roots/llvmgcc42~obj/src/libdecnumber/decNumber.c:5591: internal compiler error: Abort trap Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://developer.apple.com/bugreporter> for instructions. make[4]: *** [decNumber.o] Error 1 make[3]: *** [all-stage2-libdecnumber] Error 2 make[3]: *** Waiting for unfinished jobs.... llvm-svn: 71165
* Constant-fold ptrtoint+add+inttoptr to gep when the pointer is anDan Gohman2009-05-071-4/+36
| | | | | | | array and the add is within range. This helps simplify expressions expanded by ScalarEvolutionExpander. llvm-svn: 71158
* use higher level APIs.Chris Lattner2009-04-031-8/+6
| | | | llvm-svn: 68351
OpenPOWER on IntegriCloud