use ArgOperand API

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106740 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Gabor Greif
2010-06-24 12:58:35 +00:00
parent 3e84e2e90f
commit cea7ac7c01

View File

@ -154,8 +154,8 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
// an i64 load+store, here because this improves the odds that the source or // an i64 load+store, here because this improves the odds that the source or
// dest address will be promotable. See if we can find a better type than the // dest address will be promotable. See if we can find a better type than the
// integer datatype. // integer datatype.
Value *StrippedDest = MI->getOperand(1)->stripPointerCasts(); Value *StrippedDest = MI->getArgOperand(0)->stripPointerCasts();
if (StrippedDest != MI->getOperand(1)) { if (StrippedDest != MI->getArgOperand(0)) {
const Type *SrcETy = cast<PointerType>(StrippedDest->getType()) const Type *SrcETy = cast<PointerType>(StrippedDest->getType())
->getElementType(); ->getElementType();
if (TD && SrcETy->isSized() && TD->getTypeStoreSize(SrcETy) == Size) { if (TD && SrcETy->isSized() && TD->getTypeStoreSize(SrcETy) == Size) {
@ -324,10 +324,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
if (!TD) break; if (!TD) break;
const Type *ReturnTy = CI.getType(); const Type *ReturnTy = CI.getType();
bool Min = (cast<ConstantInt>(II->getOperand(2))->getZExtValue() == 1); bool Min = (cast<ConstantInt>(II->getArgOperand(1))->getZExtValue() == 1);
// Get to the real allocated thing and offset as fast as possible. // Get to the real allocated thing and offset as fast as possible.
Value *Op1 = II->getOperand(1)->stripPointerCasts(); Value *Op1 = II->getArgOperand(0)->stripPointerCasts();
// If we've stripped down to a single global variable that we // If we've stripped down to a single global variable that we
// can know the size of then just return that. // can know the size of then just return that.
@ -395,7 +395,6 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
Constant *RetVal = ConstantInt::get(ReturnTy, Size-Offset); Constant *RetVal = ConstantInt::get(ReturnTy, Size-Offset);
return ReplaceInstUsesWith(CI, RetVal); return ReplaceInstUsesWith(CI, RetVal);
} }
// Do not return "I don't know" here. Later optimization passes could // Do not return "I don't know" here. Later optimization passes could
@ -404,45 +403,45 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
} }
case Intrinsic::bswap: case Intrinsic::bswap:
// bswap(bswap(x)) -> x // bswap(bswap(x)) -> x
if (IntrinsicInst *Operand = dyn_cast<IntrinsicInst>(II->getOperand(1))) if (IntrinsicInst *Operand = dyn_cast<IntrinsicInst>(II->getArgOperand(0)))
if (Operand->getIntrinsicID() == Intrinsic::bswap) if (Operand->getIntrinsicID() == Intrinsic::bswap)
return ReplaceInstUsesWith(CI, Operand->getOperand(1)); return ReplaceInstUsesWith(CI, Operand->getArgOperand(0));
// bswap(trunc(bswap(x))) -> trunc(lshr(x, c)) // bswap(trunc(bswap(x))) -> trunc(lshr(x, c))
if (TruncInst *TI = dyn_cast<TruncInst>(II->getOperand(1))) { if (TruncInst *TI = dyn_cast<TruncInst>(II->getArgOperand(0))) {
if (IntrinsicInst *Operand = dyn_cast<IntrinsicInst>(TI->getOperand(0))) if (IntrinsicInst *Operand = dyn_cast<IntrinsicInst>(TI->getOperand(0)))
if (Operand->getIntrinsicID() == Intrinsic::bswap) { if (Operand->getIntrinsicID() == Intrinsic::bswap) {
unsigned C = Operand->getType()->getPrimitiveSizeInBits() - unsigned C = Operand->getType()->getPrimitiveSizeInBits() -
TI->getType()->getPrimitiveSizeInBits(); TI->getType()->getPrimitiveSizeInBits();
Value *CV = ConstantInt::get(Operand->getType(), C); Value *CV = ConstantInt::get(Operand->getType(), C);
Value *V = Builder->CreateLShr(Operand->getOperand(1), CV); Value *V = Builder->CreateLShr(Operand->getArgOperand(0), CV);
return new TruncInst(V, TI->getType()); return new TruncInst(V, TI->getType());
} }
} }
break; break;
case Intrinsic::powi: case Intrinsic::powi:
if (ConstantInt *Power = dyn_cast<ConstantInt>(II->getOperand(2))) { if (ConstantInt *Power = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
// powi(x, 0) -> 1.0 // powi(x, 0) -> 1.0
if (Power->isZero()) if (Power->isZero())
return ReplaceInstUsesWith(CI, ConstantFP::get(CI.getType(), 1.0)); return ReplaceInstUsesWith(CI, ConstantFP::get(CI.getType(), 1.0));
// powi(x, 1) -> x // powi(x, 1) -> x
if (Power->isOne()) if (Power->isOne())
return ReplaceInstUsesWith(CI, II->getOperand(1)); return ReplaceInstUsesWith(CI, II->getArgOperand(0));
// powi(x, -1) -> 1/x // powi(x, -1) -> 1/x
if (Power->isAllOnesValue()) if (Power->isAllOnesValue())
return BinaryOperator::CreateFDiv(ConstantFP::get(CI.getType(), 1.0), return BinaryOperator::CreateFDiv(ConstantFP::get(CI.getType(), 1.0),
II->getOperand(1)); II->getArgOperand(0));
} }
break; break;
case Intrinsic::cttz: { case Intrinsic::cttz: {
// If all bits below the first known one are known zero, // If all bits below the first known one are known zero,
// this value is constant. // this value is constant.
const IntegerType *IT = cast<IntegerType>(II->getOperand(1)->getType()); const IntegerType *IT = cast<IntegerType>(II->getArgOperand(0)->getType());
uint32_t BitWidth = IT->getBitWidth(); uint32_t BitWidth = IT->getBitWidth();
APInt KnownZero(BitWidth, 0); APInt KnownZero(BitWidth, 0);
APInt KnownOne(BitWidth, 0); APInt KnownOne(BitWidth, 0);
ComputeMaskedBits(II->getOperand(1), APInt::getAllOnesValue(BitWidth), ComputeMaskedBits(II->getArgOperand(0), APInt::getAllOnesValue(BitWidth),
KnownZero, KnownOne); KnownZero, KnownOne);
unsigned TrailingZeros = KnownOne.countTrailingZeros(); unsigned TrailingZeros = KnownOne.countTrailingZeros();
APInt Mask(APInt::getLowBitsSet(BitWidth, TrailingZeros)); APInt Mask(APInt::getLowBitsSet(BitWidth, TrailingZeros));
@ -455,11 +454,11 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
case Intrinsic::ctlz: { case Intrinsic::ctlz: {
// If all bits above the first known one are known zero, // If all bits above the first known one are known zero,
// this value is constant. // this value is constant.
const IntegerType *IT = cast<IntegerType>(II->getOperand(1)->getType()); const IntegerType *IT = cast<IntegerType>(II->getArgOperand(0)->getType());
uint32_t BitWidth = IT->getBitWidth(); uint32_t BitWidth = IT->getBitWidth();
APInt KnownZero(BitWidth, 0); APInt KnownZero(BitWidth, 0);
APInt KnownOne(BitWidth, 0); APInt KnownOne(BitWidth, 0);
ComputeMaskedBits(II->getOperand(1), APInt::getAllOnesValue(BitWidth), ComputeMaskedBits(II->getArgOperand(0), APInt::getAllOnesValue(BitWidth),
KnownZero, KnownOne); KnownZero, KnownOne);
unsigned LeadingZeros = KnownOne.countLeadingZeros(); unsigned LeadingZeros = KnownOne.countLeadingZeros();
APInt Mask(APInt::getHighBitsSet(BitWidth, LeadingZeros)); APInt Mask(APInt::getHighBitsSet(BitWidth, LeadingZeros));
@ -470,8 +469,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
} }
break; break;
case Intrinsic::uadd_with_overflow: { case Intrinsic::uadd_with_overflow: {
Value *LHS = II->getOperand(1), *RHS = II->getOperand(2); Value *LHS = II->getArgOperand(0), *RHS = II->getArgOperand(1);
const IntegerType *IT = cast<IntegerType>(II->getOperand(1)->getType()); const IntegerType *IT = cast<IntegerType>(II->getArgOperand(0)->getType());
uint32_t BitWidth = IT->getBitWidth(); uint32_t BitWidth = IT->getBitWidth();
APInt Mask = APInt::getSignBit(BitWidth); APInt Mask = APInt::getSignBit(BitWidth);
APInt LHSKnownZero(BitWidth, 0); APInt LHSKnownZero(BitWidth, 0);
@ -535,7 +534,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
ConstantInt::getFalse(II->getContext()) ConstantInt::getFalse(II->getContext())
}; };
Constant *Struct = ConstantStruct::get(II->getContext(), V, 2, false); Constant *Struct = ConstantStruct::get(II->getContext(), V, 2, false);
return InsertValueInst::Create(Struct, II->getOperand(1), 0); return InsertValueInst::Create(Struct, II->getArgOperand(0), 0);
} }
} }
break; break;
@ -582,11 +581,11 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
// X * 1 -> {X, false} // X * 1 -> {X, false}
if (RHSI->equalsInt(1)) { if (RHSI->equalsInt(1)) {
Constant *V[] = { Constant *V[] = {
UndefValue::get(II->getOperand(1)->getType()), UndefValue::get(II->getArgOperand(0)->getType()),
ConstantInt::getFalse(II->getContext()) ConstantInt::getFalse(II->getContext())
}; };
Constant *Struct = ConstantStruct::get(II->getContext(), V, 2, false); Constant *Struct = ConstantStruct::get(II->getContext(), V, 2, false);
return InsertValueInst::Create(Struct, II->getOperand(1), 0); return InsertValueInst::Create(Struct, II->getArgOperand(0), 0);
} }
} }
break; break;
@ -597,8 +596,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
case Intrinsic::x86_sse2_loadu_dq: case Intrinsic::x86_sse2_loadu_dq:
// Turn PPC lvx -> load if the pointer is known aligned. // Turn PPC lvx -> load if the pointer is known aligned.
// Turn X86 loadups -> load if the pointer is known aligned. // Turn X86 loadups -> load if the pointer is known aligned.
if (GetOrEnforceKnownAlignment(II->getOperand(1), 16) >= 16) { if (GetOrEnforceKnownAlignment(II->getArgOperand(0), 16) >= 16) {
Value *Ptr = Builder->CreateBitCast(II->getOperand(1), Value *Ptr = Builder->CreateBitCast(II->getArgOperand(0),
PointerType::getUnqual(II->getType())); PointerType::getUnqual(II->getType()));
return new LoadInst(Ptr); return new LoadInst(Ptr);
} }
@ -642,7 +641,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
case Intrinsic::ppc_altivec_vperm: case Intrinsic::ppc_altivec_vperm:
// Turn vperm(V1,V2,mask) -> shuffle(V1,V2,mask) if mask is a constant. // Turn vperm(V1,V2,mask) -> shuffle(V1,V2,mask) if mask is a constant.
if (ConstantVector *Mask = dyn_cast<ConstantVector>(II->getOperand(3))) { if (ConstantVector *Mask = dyn_cast<ConstantVector>(II->getArgOperand(2))) {
assert(Mask->getNumOperands() == 16 && "Bad type for intrinsic!"); assert(Mask->getNumOperands() == 16 && "Bad type for intrinsic!");
// Check that all of the elements are integer constants or undefs. // Check that all of the elements are integer constants or undefs.
@ -657,8 +656,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
if (AllEltsOk) { if (AllEltsOk) {
// Cast the input vectors to byte vectors. // Cast the input vectors to byte vectors.
Value *Op0 = Builder->CreateBitCast(II->getOperand(1), Mask->getType()); Value *Op0 = Builder->CreateBitCast(II->getArgOperand(0), Mask->getType());
Value *Op1 = Builder->CreateBitCast(II->getOperand(2), Mask->getType()); Value *Op1 = Builder->CreateBitCast(II->getArgOperand(1), Mask->getType());
Value *Result = UndefValue::get(Op0->getType()); Value *Result = UndefValue::get(Op0->getType());
// Only extract each element once. // Only extract each element once.
@ -691,7 +690,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
case Intrinsic::stackrestore: { case Intrinsic::stackrestore: {
// If the save is right next to the restore, remove the restore. This can // If the save is right next to the restore, remove the restore. This can
// happen when variable allocas are DCE'd. // happen when variable allocas are DCE'd.
if (IntrinsicInst *SS = dyn_cast<IntrinsicInst>(II->getOperand(1))) { if (IntrinsicInst *SS = dyn_cast<IntrinsicInst>(II->getArgOperand(0))) {
if (SS->getIntrinsicID() == Intrinsic::stacksave) { if (SS->getIntrinsicID() == Intrinsic::stacksave) {
BasicBlock::iterator BI = SS; BasicBlock::iterator BI = SS;
if (&*++BI == II) if (&*++BI == II)
@ -848,7 +847,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
UndefValue::get(Type::getInt1PtrTy(Callee->getContext())), UndefValue::get(Type::getInt1PtrTy(Callee->getContext())),
CS.getInstruction()); CS.getInstruction());
// If CS dues not return void then replaceAllUsesWith undef. // If CS does not return void then replaceAllUsesWith undef.
// This allows ValueHandlers and custom metadata to adjust itself. // This allows ValueHandlers and custom metadata to adjust itself.
if (!CS.getInstruction()->getType()->isVoidTy()) if (!CS.getInstruction()->getType()->isVoidTy())
CS.getInstruction()-> CS.getInstruction()->
@ -1142,7 +1141,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) {
IntrinsicInst *Tramp = IntrinsicInst *Tramp =
cast<IntrinsicInst>(cast<BitCastInst>(Callee)->getOperand(0)); cast<IntrinsicInst>(cast<BitCastInst>(Callee)->getOperand(0));
Function *NestF = cast<Function>(Tramp->getOperand(2)->stripPointerCasts()); Function *NestF = cast<Function>(Tramp->getArgOperand(1)->stripPointerCasts());
const PointerType *NestFPTy = cast<PointerType>(NestF->getType()); const PointerType *NestFPTy = cast<PointerType>(NestF->getType());
const FunctionType *NestFTy = cast<FunctionType>(NestFPTy->getElementType()); const FunctionType *NestFTy = cast<FunctionType>(NestFPTy->getElementType());
@ -1183,7 +1182,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) {
do { do {
if (Idx == NestIdx) { if (Idx == NestIdx) {
// Add the chain argument and attributes. // Add the chain argument and attributes.
Value *NestVal = Tramp->getOperand(3); Value *NestVal = Tramp->getArgOperand(2);
if (NestVal->getType() != NestTy) if (NestVal->getType() != NestTy)
NestVal = new BitCastInst(NestVal, NestTy, "nest", Caller); NestVal = new BitCastInst(NestVal, NestTy, "nest", Caller);
NewArgs.push_back(NestVal); NewArgs.push_back(NestVal);