summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix InstCombine/2004-08-10-BoolSetCC.ll, a bug that is miscompilingChris Lattner2004-08-111-22/+21
| | | | | | | 176.gcc. Note that this is apparently not the only bug miscompiling gcc though. :( llvm-svn: 15639
* Fix InstCombine/2004-08-09-RemInfLoop.llxChris Lattner2004-08-091-1/+1
| | | | | | This should go into the 1.3 branch llvm-svn: 15593
* Stop using getValues().Alkis Evlogimenos2004-08-041-2/+2
| | | | llvm-svn: 15487
* Fix a regression in InstCombine/xor.llChris Lattner2004-08-011-2/+2
| | | | llvm-svn: 15410
* Fix De Morgan's name.Misha Brukman2004-07-301-2/+2
| | | | llvm-svn: 15343
* Start using the PatternMatcher a bit.Chris Lattner2004-07-301-112/+88
| | | | llvm-svn: 15342
* This change fixed a bug in the function visitMul. The prior versionRobert Bocchino2004-07-271-3/+3
| | | | | | | | | | | | | | | assumed that a constant on the RHS of a multiplication was either an IntConstant or an FPConstant. It checked for an IntConstant and then, if it did not find one, did a hard cast to an FPConstant. That code would crash if the RHS were a ConstantExpr that was neither an IntConstant nor an FPConstant. This version replaces the hard cast with a dyn_cast. It performs the same way for IntConstants and FPConstants but does nothing, instead of crashing, for constant expressions. The regression test for this change is 2004-07-27-ConstantExprMul.ll. llvm-svn: 15291
* Make the create...() functions for some of these passes return a FunctionPass *.Brian Gaeke2004-07-271-1/+1
| | | | llvm-svn: 15276
* * Further cleanup.Chris Lattner2004-07-211-9/+27
| | | | | | | | | | | * Test for whether bits are shifted out during the optzn. If so, the fold is illegal, though it can be handled explicitly for setne/seteq This fixes the miscompilation of 254.gap last night, which was a latent bug exposed by other optimizer improvements. llvm-svn: 15085
* Make cast-cast code a bit more defensiveChris Lattner2004-07-211-32/+42
| | | | | | "simplify" a bit of code for comparison/and folding llvm-svn: 15082
* Remove special casing of pointers and treat them generically as integers ofChris Lattner2004-07-211-8/+5
| | | | | | the appopriate size. This gives us the ability to eliminate int -> ptr -> int llvm-svn: 15063
* Implement Transforms/InstCombine/IntPtrCast.llChris Lattner2004-07-201-11/+16
| | | | llvm-svn: 15029
* Implement InstCombine/GEPIdxCanon.llChris Lattner2004-07-201-1/+10
| | | | llvm-svn: 15024
* Rewrite cast->cast elimination code completely based on the information weChris Lattner2004-07-201-43/+53
| | | | | | | | actually care about. Someday when the cast instruction is gone, we can do better here, but this will do for now. This implements instcombine/cast.ll:test17/18 as well. llvm-svn: 15018
* Minor cleanup, no functionality changeChris Lattner2004-07-181-7/+2
| | | | llvm-svn: 14972
* Delete a no-op loop.Reid Spencer2004-07-181-9/+0
| | | | llvm-svn: 14965
* bug 122:Reid Spencer2004-07-181-16/+13
| | | | | | | | - Replace ConstantPointerRef usage with GlobalValue usage - Minimize redundant isa<GlobalValue> usage - Correct isa<Constant> for GlobalValue subclass llvm-svn: 14950
* Factor some code to handle "load (constantexpr cast foo)" just likeChris Lattner2004-07-131-20/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "load (cast foo)". This allows us to compile C++ code like this: class Bclass { public: virtual int operator()() { return 666; } }; class Dclass: public Bclass { public: virtual int operator()() { return 667; } } ; int main(int argc, char** argv) { Dclass x; return x(); } Into this: int %main(int %argc, sbyte** %argv) { entry: call void %__main( ) ret int 667 } Instead of this: int %main(int %argc, sbyte** %argv) { entry: %x = alloca "struct.std::bad_typeid" ; <"struct.std::bad_typeid"*> [#uses=3] call void %__main( ) %tmp.1.i.i = getelementptr "struct.std::bad_typeid"* %x, uint 0, uint 0, uint 0 ; <int (...)***> [#uses=1] store int (...)** getelementptr ([3 x int (...)*]* %vtable for Bclass, int 0, long 2), int (...)*** %tmp.1.i.i %tmp.3.i = getelementptr "struct.std::bad_typeid"* %x, int 0, uint 0, uint 0 ; <int (...)***> [#uses=1] store int (...)** getelementptr ([3 x int (...)*]* %vtable for Dclass, int 0, long 2), int (...)*** %tmp.3.i %tmp.5 = load int ("struct.std::bad_typeid"*)** cast (int (...)** getelementptr ([3 x int (...)*]* %vtable for Dclass, int 0, long 2) to int ("struct.std::bad_typeid"*)**) ; <int ("struct.std::bad_typeid"*)*> [#uses=1] %tmp.6 = call int %tmp.5( "struct.std::bad_typeid"* %x ) ; <int> [#uses=1] ret int %tmp.6 ret int 0 } In order words, we now resolve the virtual function call. llvm-svn: 14783
* Check to make sure types are sized before calling getTypeSize on them.Chris Lattner2004-07-061-13/+15
| | | | llvm-svn: 14649
* Implement rem.ll:test3Chris Lattner2004-07-061-0/+18
| | | | llvm-svn: 14640
* Fix a minor bug where we would go into infinite loops on some constantsChris Lattner2004-07-061-1/+2
| | | | llvm-svn: 14638
* Implement InstCombine/sub.ll:test15: X % -Y === X % YChris Lattner2004-07-061-2/+9
| | | | | | | Also, remove X % -1 = 0, because it's not true for unsigneds, and the signed case is superceeded by this new handling. llvm-svn: 14637
* Implement add.ll:test22, a common case in MSIL filesChris Lattner2004-07-031-0/+18
| | | | llvm-svn: 14587
* Do not call getTypeSize on a type that has no sizeChris Lattner2004-07-021-1/+2
| | | | llvm-svn: 14584
* Implement InstCombine/add.ll:test21Chris Lattner2004-06-271-1/+6
| | | | llvm-svn: 14443
* Implement Transforms/InstCombine/and.ll:test17, a common case thatChris Lattner2004-06-181-3/+15
| | | | | | occurs due to unordered comparison macros in math.h llvm-svn: 14221
* Rename Type::PrimitiveID to TypeId and ::getPrimitiveID() to ::getTypeID()Chris Lattner2004-06-171-29/+5
| | | | | | Delete two functions that are now methods on the Type class llvm-svn: 14200
* Fix a bug in my checkin from last night that caused miscompilations ofChris Lattner2004-06-101-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 186.crafty, fhourstones and 132.ijpeg. Bugpoint makes really nasty miscompilations embarassingly easy to find. It narrowed it down to the instcombiner and this testcase (from fhourstones): bool %l7153_l4706_htstat_loopentry_2E_4_no_exit_2E_4(int* %i, [32 x int]* %works, int* %tmp.98.out) { newFuncRoot: %tmp.96 = load int* %i ; <int> [#uses=1] %tmp.97 = getelementptr [32 x int]* %works, long 0, int %tmp.96 ; <int*> [#uses=1] %tmp.98 = load int* %tmp.97 ; <int> [#uses=2] %tmp.99 = load int* %i ; <int> [#uses=1] %tmp.100 = and int %tmp.99, 7 ; <int> [#uses=1] %tmp.101 = seteq int %tmp.100, 7 ; <bool> [#uses=2] %tmp.102 = cast bool %tmp.101 to int ; <int> [#uses=0] br bool %tmp.101, label %codeRepl4.exitStub, label %codeRepl3.exitStub codeRepl4.exitStub: ; preds = %newFuncRoot store int %tmp.98, int* %tmp.98.out ret bool true codeRepl3.exitStub: ; preds = %newFuncRoot store int %tmp.98, int* %tmp.98.out ret bool false } ... which only has one combination performed on it: $ llvm-as < t.ll | opt -instcombine -debug | llvm-dis IC: Old = %tmp.101 = seteq int %tmp.100, 7 ; <bool> [#uses=1] New = setne int %tmp.100, 0 ; <bool>:<badref> [#uses=0] IC: MOD = br bool %tmp.101, label %codeRepl3.exitStub, label %codeRepl4.exitStub IC: MOD = %tmp.97 = getelementptr [32 x int]* %works, uint 0, int %tmp.96 ; <int*> [#uses=1] It doesn't get much better than this. :) llvm-svn: 14109
* More minor cleanupsChris Lattner2004-06-101-11/+8
| | | | llvm-svn: 14108
* Eliminate many occurrances of Instruction::Chris Lattner2004-06-101-134/+112
| | | | llvm-svn: 14107
* Implement InstCombine/select.ll:test15*Chris Lattner2004-06-091-40/+90
| | | | llvm-svn: 14095
* Be more careful about the order we put stuff onto the worklist. This allow ↵Chris Lattner2004-06-091-19/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | us to collapse this: bool %le(int %A, int %B) { %c1 = setgt int %A, %B %tmp = select bool %c1, int 1, int 0 %c2 = setlt int %A, %B %result = select bool %c2, int -1, int %tmp %c3 = setle int %result, 0 ret bool %c3 } into: bool %le(int %A, int %B) { %c3 = setle int %A, %B ; <bool> [#uses=1] ret bool %c3 } which is handy, because the Java FE makes these sequences all over the place. This is tested as: test/Regression/Transforms/InstCombine/JavaCompare.ll llvm-svn: 14086
* Implement select.ll:test14*Chris Lattner2004-06-091-35/+59
| | | | llvm-svn: 14083
* Fix InstCombine/load.ll & PR347.Chris Lattner2004-05-271-12/+24
| | | | | | | | | | This code hadn't been updated after the "structs with more than 256 elements" related changes to the GEP instruction. Also it was not handling the ConstantAggregateZero class. Now it does! llvm-svn: 13834
* Implement InstCombine:shift.ll:test16, which turns (X >> C1) & C2 != C3Chris Lattner2004-05-251-0/+35
| | | | | | | | | | into (X & (C2 << C1)) != (C3 << C1), where the shift may be either left or right and the compare may be any one. This triggers 1546 times in 176.gcc alone, as it is a common pattern that occurs for bitfield accesses. llvm-svn: 13740
* Implement instcombine/cast.ll:test16:Chris Lattner2004-05-251-0/+5
| | | | | | Canonicalize cast X to bool into a setne instruction llvm-svn: 13736
* This was not meant to be committedChris Lattner2004-05-131-7/+0
| | | | llvm-svn: 13565
* Fix a nasty bug that caused us to unroll EXTREMELY large loops due to overflowChris Lattner2004-05-131-0/+7
| | | | | | | | | | | | | | | | | | | | in the size calculation. This is not something you want to see: Loop Unroll: F[main] Loop %no_exit Loop Size = 2 Trip Count = 2147483648 - UNROLLING! The problem was that 2*2147483648 == 0. Now we get: Loop Unroll: F[main] Loop %no_exit Loop Size = 2 Trip Count = 2147483648 - TOO LARGE: 4294967296>100 Thanks to some anonymous person playing with the demo page that repeatedly caused zion to go into swapping land. That's one way to ensure you'll get a quick bugfix. :) Testcase here: Transforms/LoopUnroll/2004-05-13-DontUnrollTooMuch.ll llvm-svn: 13564
* Fix stupid bug in my checkin yesterdayChris Lattner2004-05-081-2/+1
| | | | llvm-svn: 13429
* Implement folding of GEP's like:Chris Lattner2004-05-071-53/+43
| | | | | | | | | %tmp.0 = getelementptr [50 x sbyte]* %ar, uint 0, int 5 ; <sbyte*> [#uses=2] %tmp.7 = getelementptr sbyte* %tmp.0, int 8 ; <sbyte*> [#uses=1] together. This patch actually allows us to simplify and generalize the code. llvm-svn: 13415
* Fix PR336: The instcombine pass asserts when visiting load instructionChris Lattner2004-05-071-2/+3
| | | | llvm-svn: 13400
* Minor efficiency tweak, suggested by Patrick MeredithChris Lattner2004-05-041-4/+4
| | | | llvm-svn: 13341
* Make sure to reprocess instructions used by deleted instructions to avoidChris Lattner2004-05-011-5/+12
| | | | | | missing opportunities for combination. llvm-svn: 13309
* Make sure the instruction combiner doesn't lose track of instructionsChris Lattner2004-05-011-3/+6
| | | | | | when replacing them, missing the opportunity to do simplifications llvm-svn: 13308
* Fix a major pessimization in the instcombiner. If an allocation instructionChris Lattner2004-04-301-1/+1
| | | | | | | | | | | | | | | is only used by a cast, and the casted type is the same size as the original allocation, it would eliminate the cast by folding it into the allocation. Unfortunately, it was placing the new allocation instruction right before the cast, which could pull (for example) alloca instructions into the body of a function. This turns statically allocatable allocas into expensive dynamically allocated allocas, which is bad bad bad. This fixes the problem by placing the new allocation instruction at the same place the old one was, duh. :) llvm-svn: 13289
* Changes to fix up the inst_iterator to pass to boost iterator checks. ThisChris Lattner2004-04-271-1/+4
| | | | | | patch was graciously contributed by Vladimir Prus. llvm-svn: 13185
* Instcombine X/-1 --> 0-XChris Lattner2004-04-261-1/+5
| | | | llvm-svn: 13172
* Fix a HUGE pessimization on X86. The indvars pass was taking thisChris Lattner2004-04-171-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (familiar) function: int _strlen(const char *str) { int len = 0; while (*str++) len++; return len; } And transforming it to use a ulong induction variable, because the type of the pointer index was left as a constant long. This is obviously very bad. The fix is to shrink long constants in getelementptr instructions to intptr_t, making the indvars pass insert a uint induction variable, which is much more efficient. Here's the before code for this function: int %_strlen(sbyte* %str) { entry: %tmp.13 = load sbyte* %str ; <sbyte> [#uses=1] %tmp.24 = seteq sbyte %tmp.13, 0 ; <bool> [#uses=1] br bool %tmp.24, label %loopexit, label %no_exit no_exit: ; preds = %entry, %no_exit *** %indvar = phi uint [ %indvar.next, %no_exit ], [ 0, %entry ] ; <uint> [#uses=2] *** %indvar = phi ulong [ %indvar.next, %no_exit ], [ 0, %entry ] ; <ulong> [#uses=2] %indvar1 = cast ulong %indvar to uint ; <uint> [#uses=1] %inc.02.sum = add uint %indvar1, 1 ; <uint> [#uses=1] %inc.0.0 = getelementptr sbyte* %str, uint %inc.02.sum ; <sbyte*> [#uses=1] %tmp.1 = load sbyte* %inc.0.0 ; <sbyte> [#uses=1] %tmp.2 = seteq sbyte %tmp.1, 0 ; <bool> [#uses=1] %indvar.next = add ulong %indvar, 1 ; <ulong> [#uses=1] %indvar.next = add uint %indvar, 1 ; <uint> [#uses=1] br bool %tmp.2, label %loopexit.loopexit, label %no_exit loopexit.loopexit: ; preds = %no_exit %indvar = cast uint %indvar to int ; <int> [#uses=1] %inc.1 = add int %indvar, 1 ; <int> [#uses=1] ret int %inc.1 loopexit: ; preds = %entry ret int 0 } Here's the after code: int %_strlen(sbyte* %str) { entry: %inc.02 = getelementptr sbyte* %str, uint 1 ; <sbyte*> [#uses=1] %tmp.13 = load sbyte* %str ; <sbyte> [#uses=1] %tmp.24 = seteq sbyte %tmp.13, 0 ; <bool> [#uses=1] br bool %tmp.24, label %loopexit, label %no_exit no_exit: ; preds = %entry, %no_exit *** %indvar = phi uint [ %indvar.next, %no_exit ], [ 0, %entry ] ; <uint> [#uses=3] %indvar = cast uint %indvar to int ; <int> [#uses=1] %inc.0.0 = getelementptr sbyte* %inc.02, uint %indvar ; <sbyte*> [#uses=1] %inc.1 = add int %indvar, 1 ; <int> [#uses=1] %tmp.1 = load sbyte* %inc.0.0 ; <sbyte> [#uses=1] %tmp.2 = seteq sbyte %tmp.1, 0 ; <bool> [#uses=1] %indvar.next = add uint %indvar, 1 ; <uint> [#uses=1] br bool %tmp.2, label %loopexit, label %no_exit loopexit: ; preds = %entry, %no_exit %len.0.1 = phi int [ 0, %entry ], [ %inc.1, %no_exit ] ; <int> [#uses=1] ret int %len.0.1 } llvm-svn: 13016
* Fix some really nasty dominance bugs that were exposed by my patch toChris Lattner2004-04-161-29/+12
| | | | | | make the verifier more strict. This fixes building zlib llvm-svn: 13002
* ADd a trivial instcombine: load null -> nullChris Lattner2004-04-141-2/+5
| | | | llvm-svn: 12940
OpenPOWER on IntegriCloud