[llvm-commits] [llvm] r138722 - in /llvm/trunk: lib/Analysis/ConstantFolding.cpp lib/Transforms/InstCombine/InstCombineCasts.cpp test/Transforms/InstCombine/cast.ll

Duncan Sands baldrick at free.fr
Sun Aug 28 05:07:21 PDT 2011


Hi Nadav,

> Bitcasts are transitive. Bitcast-Bitcast-X becomes Bitcast-X.

sadly this is not true because you are only allowed to bitcast an mmx type
to and from a vector type, but you can bitcast vector to and from integers
etc.

> +  // Bitcast of Bitcast can be done using a single cast.
> +  ConstantExpr *CE = dyn_cast<ConstantExpr>(C);
> +  if (CE&&  CE->getOpcode() == Instruction::BitCast) {
> +    return ConstantExpr::getBitCast(CE->getOperand(0), DestTy);
> +  }

No need for curly brackets {}.

> +  // Bitcasts are transitive.
> +  if (BitCastInst* BSrc = dyn_cast<BitCastInst>(Src)) {
> +    return CastInst::Create(Instruction::BitCast, BSrc->getOperand(0), DestTy);
> +  }

Likewise.  Also, this could be:
   if (isa<BitCastInst>(Src))
     return CastInst::Create(Instruction::BitCast, Src->getOperand(0), DestTy);
Also, shouldn't you create the cast using instcombine's builder?

Ciao, Duncan.



More information about the llvm-commits mailing list