summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Commit message (Collapse)AuthorAgeFilesLines
* factor new code out to a SimplifyBranchOnICmpChain helper function.Chris Lattner2010-12-131-77/+91
| | | | llvm-svn: 121681
* enhance the "change or icmp's into switch" xform to handle one value in an Chris Lattner2010-12-131-3/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 'or sequence' that it doesn't understand. This allows us to optimize something insane like this: int crud (unsigned char c, unsigned x) { if(((((((((( (int) c <= 32 || (int) c == 46) || (int) c == 44) || (int) c == 58) || (int) c == 59) || (int) c == 60) || (int) c == 62) || (int) c == 34) || (int) c == 92) || (int) c == 39) != 0) foo(); } into: define i32 @crud(i8 zeroext %c, i32 %x) nounwind ssp noredzone { entry: %cmp = icmp ult i8 %c, 33 br i1 %cmp, label %if.then, label %switch.early.test switch.early.test: ; preds = %entry switch i8 %c, label %if.end [ i8 39, label %if.then i8 44, label %if.then i8 58, label %if.then i8 59, label %if.then i8 60, label %if.then i8 62, label %if.then i8 46, label %if.then i8 92, label %if.then i8 34, label %if.then ] by pulling the < comparison out ahead of the newly formed switch. llvm-svn: 121680
* merge two very similar functions into one that has a bool argument.Chris Lattner2010-12-131-47/+26
| | | | llvm-svn: 121678
* don't bother handling non-canonical icmp'sChris Lattner2010-12-131-11/+9
| | | | llvm-svn: 121676
* inline a function, making the result much simpler.Chris Lattner2010-12-131-27/+11
| | | | llvm-svn: 121675
* Fix my previous patch to handle a degenerate case that the llvm-gccChris Lattner2010-12-131-0/+16
| | | | | | bootstrap buildbot tripped over. llvm-svn: 121674
* convert some methods to be static functionsChris Lattner2010-12-131-25/+23
| | | | llvm-svn: 121673
* zap two more std::sorts.Chris Lattner2010-12-131-2/+2
| | | | llvm-svn: 121672
* fix a fairly serious oversight with switch formation fromChris Lattner2010-12-131-1/+97
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | or'd conditions. Previously we'd compile something like this: int crud (unsigned char c) { return c == 62 || c == 34 || c == 92; } into: switch i8 %c, label %lor.rhs [ i8 62, label %lor.end i8 34, label %lor.end ] lor.rhs: ; preds = %entry %cmp8 = icmp eq i8 %c, 92 br label %lor.end lor.end: ; preds = %entry, %entry, %lor.rhs %0 = phi i1 [ true, %entry ], [ %cmp8, %lor.rhs ], [ true, %entry ] %lor.ext = zext i1 %0 to i32 ret i32 %lor.ext which failed to merge the compare-with-92 into the switch. With this patch we simplify this all the way to: switch i8 %c, label %lor.rhs [ i8 62, label %lor.end i8 34, label %lor.end i8 92, label %lor.end ] lor.rhs: ; preds = %entry br label %lor.end lor.end: ; preds = %entry, %entry, %entry, %lor.rhs %0 = phi i1 [ true, %entry ], [ false, %lor.rhs ], [ true, %entry ], [ true, %entry ] %lor.ext = zext i1 %0 to i32 ret i32 %lor.ext which is much better for codegen's switch lowering stuff. This kicks in 33 times on 176.gcc (for example) cutting 103 instructions off the generated code. llvm-svn: 121671
* convert an std::sort to array_pod_sort.Chris Lattner2010-12-131-2/+8
| | | | llvm-svn: 121669
* move the "br (X == 0 | X == 1), T, F" -> switch optimization to a newChris Lattner2010-12-131-57/+56
| | | | | | | | | | | location in simplifycfg. In the old days, SimplifyCFG was never run on the entry block, so we had to scan over all preds of the BB passed into simplifycfg to do this xform, now we can just check blocks ending with a condbranch. This avoids a scan over all preds of every simplified block, which should be a significant compile-time perf win on functions with lots of edges. No functionality change. llvm-svn: 121668
* reduce indentation and generally simplify code, no functionality change.Chris Lattner2010-12-131-333/+309
| | | | llvm-svn: 121667
* use getFirstNonPHIOrDbg to simplify this code.Chris Lattner2010-12-131-9/+5
| | | | llvm-svn: 121664
* Teach SimplifyCFG to turnFrits van Bommel2010-12-051-2/+72
| | | | | | | | | (indirectbr (select cond, blockaddress(@fn, BlockA), blockaddress(@fn, BlockB))) into (br cond, BlockA, BlockB). llvm-svn: 120943
* Fix PR8445: a block with no predecessors may be the entry block, in which caseDuncan Sands2010-10-241-12/+10
| | | | | | | | | it isn't unreachable and should not be zapped. The check for the entry block was missing in one case: a block containing a unwind instruction. While there, do some small cleanups: "M" is not a great name for a Function* (it would be more appropriate for a Module*), change it to "Fn"; use Fn in more places. llvm-svn: 117224
* Instead, teach SimplifyCFG to trim non-address-taken blocks fromDan Gohman2010-08-161-2/+3
| | | | | | indirectbr destination lists. llvm-svn: 111122
* Teach SimplifyCFG how to simplify indirectbr instructions.Dan Gohman2010-08-141-13/+40
| | | | | | | | | | | - Eliminate redundant successors. - Convert an indirectbr with one successor into a direct branch. Also, generalize SimplifyCFG to be able to be run on a function entry block. It knows quite a few simplifications which are applicable to the entry block, and it only needs a few checks to avoid trouble with the entry block. llvm-svn: 111060
* pass dereferenced iterator to dyn_castGabor Greif2010-07-221-1/+1
| | | | llvm-svn: 109098
* Remove unneeded check, and correct style.Owen Anderson2010-07-151-3/+2
| | | | llvm-svn: 108427
* Extend SimplifyCFG's common-destination folding heuristic to allow a singleOwen Anderson2010-07-141-5/+67
| | | | | | | | | | "bonus" instruction to be speculatively executed. Add a heuristic to ensure we're not tripping up out-of-order execution by checking that this bonus instruction only uses values that were already guaranteed to be available. This allows us to eliminate the short circuit in (x&1)&&(x&2). llvm-svn: 108351
* cache dereferenced iteratorsGabor Greif2010-07-121-4/+6
| | | | llvm-svn: 108133
* cache result of operator*Gabor Greif2010-07-091-2/+3
| | | | llvm-svn: 107974
* Fix a grammaro.Dan Gohman2010-03-301-1/+1
| | | | llvm-svn: 99917
* fix two cases where the arguments were extracted from the wrong range out of ↵Gabor Greif2010-03-301-3/+3
| | | | | | | | the InvokeInst spotted by baldrick -- thanks\! llvm-svn: 99914
* Make returns more consistent with others.Bill Wendling2010-03-141-2/+2
| | | | llvm-svn: 98490
* There are two ways of checking for a given type, for example isa<PointerType>(T)Duncan Sands2010-02-161-5/+5
| | | | | | | and T->isPointerTy(). Convert most instances of the first form to the second form. Requested by Chris. llvm-svn: 96344
* Uniformize the names of type predicates: rather than having isFloatTy andDuncan Sands2010-02-151-1/+1
| | | | | | isInteger, we now have isFloatTy and isIntegerTy. Requested by Chris! llvm-svn: 96223
* Teach SimplifyCFG about magic pointer constants.Jakob Stoklund Olesen2010-02-051-33/+111
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Weird code sometimes uses pointer constants other than null. This patch teaches SimplifyCFG to build switch instructions in those cases. Code like this: void f(const char *x) { if (!x) puts("null"); else if ((uintptr_t)x == 1) puts("one"); else if (x == (char*)2 || x == (char*)3) puts("two"); else if ((intptr_t)x == 4) puts("four"); else puts(x); } Now becomes a switch: define void @f(i8* %x) nounwind ssp { entry: %magicptr23 = ptrtoint i8* %x to i64 ; <i64> [#uses=1] switch i64 %magicptr23, label %if.else16 [ i64 0, label %if.then i64 1, label %if.then2 i64 2, label %if.then9 i64 3, label %if.then9 i64 4, label %if.then14 ] Note that LLVM's own DenseMap uses magic pointers. llvm-svn: 95439
* Convert a ton of simple integer type equality tests to the new predicate.Benjamin Kramer2010-01-051-1/+1
| | | | llvm-svn: 92760
* Avoid going through the LLVMContext for type equality where it's safe to ↵Benjamin Kramer2010-01-051-1/+1
| | | | | | dereference the type pointer. llvm-svn: 92726
* Change errs() to dbgs().David Greene2010-01-051-13/+13
| | | | llvm-svn: 92604
* Remove dead debug info intrinsics.Devang Patel2010-01-051-7/+0
| | | | | | | | | | Intrinsic::dbg_stoppoint Intrinsic::dbg_region_start Intrinsic::dbg_region_end Intrinsic::dbg_func_start AutoUpgrade simply ignores these intrinsics now. llvm-svn: 92557
* Move EliminateDuplicatePHINodes() from SimplifyCFG.cpp to Local.cppJim Grosbach2009-12-021-63/+0
| | | | llvm-svn: 90324
* Make EliminateDuplicatePHINodes() available as a utility functionJim Grosbach2009-11-191-1/+1
| | | | llvm-svn: 89297
* refactor TryToSimplifyUncondBranchFromEmptyBlock out of SimplifyCFG.Chris Lattner2009-11-101-164/+2
| | | | llvm-svn: 86666
* remove a bunch of extraneous LLVMContext argumentsChris Lattner2009-11-061-1/+1
| | | | | | from various APIs, addressing PR5325. llvm-svn: 86231
* Add a comment about a missed opportunity.Dan Gohman2009-10-301-0/+5
| | | | llvm-svn: 85635
* Teach SimplifyCFG how to eliminate duplicate PHI nodes within a block.Dan Gohman2009-10-301-0/+61
| | | | | | | This reduces codesize on a variety of codes by 1-2% on x86-64. It also helps clean up after SSAUpdater. llvm-svn: 85626
* change simplifycfg to not duplicate 'unwind' instructions. HopefullyChris Lattner2009-10-131-12/+5
| | | | | | | this will increase the likelihood of common code getting sunk towards the unwind. llvm-svn: 83996
* Instruction::clone does not need to take an LLVMContext&. Remove that andNick Lewycky2009-09-271-7/+5
| | | | | | update all the callers. llvm-svn: 82889
* Rename Instruction::isIdenticalTo to Instruction::isIdenticalToWhenDefined,Dan Gohman2009-08-251-2/+4
| | | | | | | | | | | | | | | | and introduce a new Instruction::isIdenticalTo which tests for full identity, including the SubclassOptionalData flags. Also, fix the Instruction::clone implementations to preserve the SubclassOptionalData flags. Finally, teach several optimizations how to handle SubclassOptionalData correctly, given these changes. This fixes the counterintuitive behavior of isIdenticalTo not comparing the full value, and clone not returning an identical clone, as well as some subtle bugs that could be caused by these. Thanks to Nick Lewycky for reporting this, and for an initial patch! llvm-svn: 80038
* Fix -Asserts warnings.Daniel Dunbar2009-08-231-0/+3
| | | | llvm-svn: 79849
* eliminate the "Value" printing methods that print to a std::ostream.Chris Lattner2009-08-231-21/+20
| | | | | | This required converting a bunch of stuff off DOUT and other cleanups. llvm-svn: 79819
* Fix for PR3016: detect the tricky case, where there are Eli Friedman2009-08-161-59/+37
| | | | | | | | | | | | | | | | unfoldable references to a PHI node in the block being folded, and disable the transformation in that case. The correct transformation of such PHI nodes depends on whether BB dominates Succ, and dominance is expensive to compute here. (Alternatively, it's possible to check whether any uses are live, but that's also essentially a dominance calculation. Another alternative is to use reg2mem, but it probably isn't a good idea to use that in simplifycfg.) Also, remove some incorrect code from CanPropagatePredecessorsForPHIs which is made unnecessary with this patch: it didn't consider the case where a PHI node in BB has multiple uses. llvm-svn: 79174
* Push LLVMContexts through the IntegerType APIs.Owen Anderson2009-08-131-13/+17
| | | | llvm-svn: 78948
* Remove a bunch more now-unnecessary Context arguments.Dan Gohman2009-08-121-6/+4
| | | | llvm-svn: 78809
* Move more code back to 2.5 APIs.Owen Anderson2009-07-301-3/+1
| | | | llvm-svn: 77635
* Remove Value::getName{Start,End}, the last of the old Name APIs.Daniel Dunbar2009-07-261-12/+12
| | | | llvm-svn: 77152
* More migration to raw_ostream, the water has dried up around the iostream hole.Daniel Dunbar2009-07-251-2/+3
| | | | | | | | | | - Some clients which used DOUT have moved to DEBUG. We are deprecating the "magic" DOUT behavior which avoided calling printing functions when the statement was disabled. In addition to being unnecessary magic, it had the downside of leaving code in -Asserts builds, and of hiding potentially unnecessary computations. llvm-svn: 77019
* Revert the ConstantInt constructors back to their 2.5 forms where possible, ↵Owen Anderson2009-07-241-2/+2
| | | | | | thanks to contexts-on-types. More to come. llvm-svn: 77011
OpenPOWER on IntegriCloud