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

Chris Lattner clattner at apple.com
Tue Jun 24 11:15:29 PDT 2008


On Jun 7, 2008, at 1:52 AM, Evan Cheng wrote:
> Author: evancheng
> Date: Sat Jun  7 03:52:29 2008
> New Revision: 52073
>
> URL: http://llvm.org/viewvc/llvm-project?rev=52073&view=rev
> Log:
> Speculatively execute a block when the the block is the then part of  
> a triangle shape and it contains a single, side effect free, cheap  
> instruction. The branch is eliminated by adding a select  
> instruction. i.e.

Ok

> @@ -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.

> +  Instruction *I = BB1->begin();
> +  switch (I->getOpcode()) {
> +  default: return false;  // Not safe / profitable to hoist.
> +  case Instruction::Add:
> +  case Instruction::Sub:
> +  case Instruction::And:
> +  case Instruction::Or:
> +  case Instruction::Xor:
> +  case Instruction::Shl:
> +  case Instruction::LShr:
> +  case Instruction::AShr:
> +    if (I->getOperand(0)->getType()->isFPOrFPVector())
> +      return false;  // FP arithmetic might trap.
> +    break;   // These are all cheap and non-trapping instructions.
> +  }

Is this worthwhile to do for vector operations?

-Chris




More information about the llvm-commits mailing list