[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Nick Lewycky nicholas at mxc.ca
Fri Apr 27 20:44:18 PDT 2007


Chris Lattner wrote:
> +          if (OrigBase) {
> +            // If we were able to index down into an element, create the GEP
> +            // and bitcast the result.  This eliminates one bitcast, potentially
> +            // two.
> +            Instruction *NGEP = new GetElementPtrInst(OrigBase, &NewIndices[0],
> +                                                      NewIndices.size(), "");
> +            InsertNewInstBefore(NGEP, CI);
> +            NGEP->takeName(GEP);
> +            
> +            cerr << "\nZAP: " << *GEP->getOperand(0);
> +            cerr << "ZAP: " << *GEP;
> +            cerr << "ZAP: " << CI << "\n";
> +
> +            cerr << "NEW: " << *NGEP << "\n";
>   
How rude! ;-)
> +
> +            if (isa<BitCastInst>(CI))
> +              return new BitCastInst(NGEP, CI.getType());
> +            assert(isa<PtrToIntInst>(CI));
> +            return new PtrToIntInst(NGEP, CI.getType());
> +          }
> +        }
> +      }      
> +    }
>    }
>      
>    return commonCastTransforms(CI);
> @@ -7306,10 +7397,7 @@
>      if (isa<PointerType>(CI->getOperand(0)->getType()))
>        return GetKnownAlignment(CI->getOperand(0), TD);
>      return 0;
> -  } else if (isa<GetElementPtrInst>(V) ||
> -             (isa<ConstantExpr>(V) && 
> -              cast<ConstantExpr>(V)->getOpcode()==Instruction::GetElementPtr)) {
> -    User *GEPI = cast<User>(V);
> +  } else if (User *GEPI = dyn_castGetElementPtr(V)) {
>   
Did the email get mangled, or does it actually say that? cvsweb agrees 
with the email.
>      unsigned BaseAlignment = GetKnownAlignment(GEPI->getOperand(0), TD);
>      if (BaseAlignment == 0) return 0;
>      
> @@ -8107,7 +8195,7 @@
>  
>  Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
>    Value *PtrOp = GEP.getOperand(0);
> -  // Is it 'getelementptr %P, long 0'  or 'getelementptr %P'
> +  // Is it 'getelementptr %P, i32 0'  or 'getelementptr %P'
>    // If so, eliminate the noop.
>    if (GEP.getNumOperands() == 1)
>      return ReplaceInstUsesWith(GEP, PtrOp);
> @@ -8122,22 +8210,11 @@
>    if (GEP.getNumOperands() == 2 && HasZeroPointerIndex)
>      return ReplaceInstUsesWith(GEP, PtrOp);
>  
> -  // Keep track of whether all indices are zero constants integers.
> -  bool AllZeroIndices = true;
> -  
>    // Eliminate unneeded casts for indices.
>    bool MadeChange = false;
>    
>    gep_type_iterator GTI = gep_type_begin(GEP);
>    for (unsigned i = 1, e = GEP.getNumOperands(); i != e; ++i, ++GTI) {
> -    // Track whether this GEP has all zero indices, if so, it doesn't move the
> -    // input pointer, it just changes its type.
> -    if (AllZeroIndices) {
> -      if (ConstantInt *CI = dyn_cast<ConstantInt>(GEP.getOperand(i)))
> -        AllZeroIndices = CI->isZero();
> -      else
> -        AllZeroIndices = false;
> -    }
>      if (isa<SequentialType>(*GTI)) {
>        if (CastInst *CI = dyn_cast<CastInst>(GEP.getOperand(i))) {
>          if (CI->getOpcode() == Instruction::ZExt ||
> @@ -8173,7 +8250,7 @@
>    // If this GEP instruction doesn't move the pointer, and if the input operand
>    // is a bitcast of another pointer, just replace the GEP with a bitcast of the
>    // real input to the dest type.
> -  if (AllZeroIndices && isa<BitCastInst>(GEP.getOperand(0)))
> +  if (GEP.hasAllZeroIndices() && isa<BitCastInst>(GEP.getOperand(0)))
>      return new BitCastInst(cast<BitCastInst>(GEP.getOperand(0))->getOperand(0),
>                             GEP.getType());
>      
> @@ -8573,8 +8650,7 @@
>    }
>  
>    if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op))
> -    if (isa<ConstantPointerNull>(GEPI->getOperand(0)) ||
> -        isa<UndefValue>(GEPI->getOperand(0))) {
> +    if (isa<ConstantPointerNull>(GEPI->getOperand(0))) {
>        // Insert a new store to null instruction before the load to indicate
>        // that this code is not reachable.  We do this instead of inserting
>        // an unreachable instruction directly because we cannot modify the
>
>
>
>   



More information about the llvm-commits mailing list