[llvm-commits] [llvm] r84936 - in /llvm/trunk: lib/Analysis/ConstantFolding.cpp test/Transforms/ConstProp/loads.ll

Duncan Sands baldrick at free.fr
Fri Oct 23 05:06:58 PDT 2009


Hi Chris,

> +  if (isa<ConstantAggregateZero>(C) || isa<UndefValue>(C))
> +    return true;

here you use that RawBytes is zero initialized, but that requirement
is not documented.

> +      CurPtr[i] = (unsigned char)(Val >> ByteOffset * 8);

You should probably bracket ByteOffset * 8 for weenies like me who
don't know C precedence rules.

> +  if (ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
> +    if (CFP->getType()->isDoubleTy()) {
> +      C = ConstantExpr::getBitCast(C, Type::getInt64Ty(C->getContext()));
> +      return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, TD);
> +    }
> +    if (CFP->getType()->isFloatTy()){
> +      C = ConstantExpr::getBitCast(C, Type::getInt32Ty(C->getContext()));
> +      return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, TD);
> +    }

Probably you should return false here.

> +  }

> +  GlobalVariable *GV = dyn_cast<GlobalVariable>(GVal);
> +  if (!GV || !GV->isConstant() || !GV->hasInitializer() ||
> +      !GV->hasDefinitiveInitializer() ||
> +      !GV->getInitializer()->getType()->isSized())
> +    return 0;

Testing hasDefinitiveInitializer also tests hasInitializer.

Ciao,

Duncan.



More information about the llvm-commits mailing list