[llvm-commits] [llvm] r55085 - in /llvm/trunk: include/llvm/CodeGen/FastISel.h lib/CodeGen/SelectionDAG/FastISel.cpp lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Evan Cheng evan.cheng at apple.com
Wed Aug 20 18:21:10 PDT 2008


On Aug 20, 2008, at 5:00 PM, Dan Gohman wrote:
>
>
> HandleUnknown should be false here; the type of a GEP is a pointer,
> which shouldn't ever be unknown.

Yep. Fixed.

>
>
>>
>> +  MVT::SimpleValueType PtrVT = TLI.getPointerTy().getSimpleVT();
>
> PtrVT and VT will have the same value here. Can one of them be
> eliminated?

Fixed.

>
>
>>
>> +
>> +  for (GetElementPtrInst::op_iterator OI = I->op_begin()+1, E = I-
>>> op_end();
>> +       OI != E; ++OI) {
>> +    Value *Idx = *OI;
>> +    if (const StructType *StTy = dyn_cast<StructType>(Ty)) {
>> +      unsigned Field = cast<ConstantInt>(Idx)->getZExtValue();
>> +      if (Field) {
>> +        // N = N + Offset
>> +        uint64_t Offs = TD.getStructLayout(StTy)-
>>> getElementOffset(Field);
>> +        // FIXME: This can be optimized by combining the add with a
>> +        // subsequent one.
>> +        N = FastEmit_ri(VT.getSimpleVT(), ISD::ADD, N, Offs, PtrVT);
>> +        if (N == 0)
>> +          // Unhandled operand. Halt "fast" selection and bail.
>> +          return false;
>> +      }
>> +      Ty = StTy->getElementType(Field);
>> +    } else {
>> +      Ty = cast<SequentialType>(Ty)->getElementType();
>> +
>> +      // If this is a constant subscript, handle it quickly.
>> +      if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) {
>> +        if (CI->getZExtValue() == 0) continue;
>> +        uint64_t Offs =
>> +          TD.getABITypeSize(Ty)*cast<ConstantInt>(CI)-
>>> getSExtValue();
>> +        N = FastEmit_ri(VT.getSimpleVT(), ISD::ADD, N, Offs, PtrVT);
>> +        if (N == 0)
>> +          // Unhandled operand. Halt "fast" selection and bail.
>> +          return false;
>> +        continue;
>> +      }
>> +
>> +      // N = N + Idx * ElementSize;
>> +      uint64_t ElementSize = TD.getABITypeSize(Ty);
>> +      unsigned IdxN = ValueMap[Idx];
>> +      if (IdxN == 0)
>> +        // Unhandled operand. Halt "fast" selection and bail.
>> +        return false;
>> +
>> +      // If the index is smaller or larger than intptr_t, truncate
>> or extend
>> +      // it.
>> +      MVT IdxVT = MVT::getMVT(Idx->getType(), /*HandleUnknown=*/
>> true);
>
> Same as above with HandleUnknown.
>
>>
>> +      if (IdxVT.bitsLT(VT))
>> +        IdxN = FastEmit_r(VT.getSimpleVT(), ISD::SIGN_EXTEND, IdxN);
>> +      else if (IdxVT.bitsGT(VT))
>> +        IdxN = FastEmit_r(VT.getSimpleVT(), ISD::TRUNCATE, IdxN);
>> +      if (IdxN == 0)
>> +        // Unhandled operand. Halt "fast" selection and bail.
>> +        return false;
>> +
>> +      // FIXME: If multiple is power of two, turn it into a shift.
>> The
>> +      // optimization should be in FastEmit_ri?
>> +      IdxN = FastEmit_ri(VT.getSimpleVT(), ISD::MUL, IdxN,
>> +                         ElementSize, PtrVT);
>
> How would converting a multiply into a shift benefit compile time?

It doesn't. This would be a code quality optimization. We want to be  
fast but it doesn't mean generating poor code. :-) We can do some dag  
combiner type optimizations if they are cheap.

Evan

>
>
> Dan
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list