[llvm-commits] [llvm] r52073 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/SpeculativeExec.ll

Dan Gohman gohman at apple.com
Tue Jun 24 12:05:38 PDT 2008


On Jun 24, 2008, at 11:15 AM, Chris Lattner wrote:

> On Jun 7, 2008, at 1:52 AM, Evan Cheng wrote:
>>
>> @@ -955,6 +955,109 @@
>> +static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock  
>> *BB1) {
>> +  // Only speculatively execution a single instruction (not
>> counting the
>> +  // terminator) for now.
>> +  if (BB1->size() != 2)
>> +    return false;
>
> This is O(n) for a check that should be O(1).  Can you do something
> (admittedly gross) like this:
>
> BasicBlock::iterator I = BB1->begin();
> ++I; // must have at least a terminator
> if (I == BB1->end()) return false; // only one inst
> ++I;
> if (I != BB1->end()) return false; // more than 2 insts.

Less gross would a helper function for this. It might not be
unlike Value::hasNUsesOrMore.

Dan




More information about the llvm-commits mailing list