[PATCH] Handle big index in getelementptr instruction

Paweł Bylica chfast at gmail.com
Tue Mar 10 13:19:19 PDT 2015


REPOSITORY
  rL LLVM

================
Comment at: lib/CodeGen/SelectionDAG/FastISel.cpp:521
@@ -520,3 +520,3 @@
         // N = N + Offset
-        TotalOffs +=
-            DL.getTypeAllocSize(Ty) * cast<ConstantInt>(CI)->getSExtValue();
+        auto I = CI->getValue().sextOrTrunc(sizeof(TotalOffs)*8).getSExtValue();
+        TotalOffs += DL.getTypeAllocSize(Ty) * I;
----------------
rnk wrote:
> rnk wrote:
> > Don't shadow the outer 'I' variable.
> This sizeof computation doesn't get PtrSize. LLVM is a cross compiler. You can compute it out of the loop.
I don't want a PtrSize, I want TotalOffs size in bits, because I'm going to add to that variable.

================
Comment at: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:3432-3442
@@ -3431,20 +3431,13 @@
       Ty = cast<SequentialType>(Ty)->getElementType();
+      auto PtrTy = DAG.getTargetLoweringInfo().getPointerTy(AS);
+      auto PtrSize = PtrTy.getSizeInBits();
+      auto ElementSize = APInt{PtrSize, DL->getTypeAllocSize(Ty)};
 
       // If this is a constant subscript, handle it quickly.
-      const TargetLowering &TLI = DAG.getTargetLoweringInfo();
-      if (const ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) {
-        if (CI->isZero()) continue;
-        uint64_t Offs =
-            DL->getTypeAllocSize(Ty)*cast<ConstantInt>(CI)->getSExtValue();
-        SDValue OffsVal;
-        EVT PTy = TLI.getPointerTy(AS);
-        unsigned PtrBits = PTy.getSizeInBits();
-        if (PtrBits < 64)
-          OffsVal = DAG.getNode(ISD::TRUNCATE, getCurSDLoc(), PTy,
-                                DAG.getConstant(Offs, MVT::i64));
-        else
-          OffsVal = DAG.getConstant(Offs, PTy);
-
-        N = DAG.getNode(ISD::ADD, getCurSDLoc(), N.getValueType(), N,
-                        OffsVal);
+      if (auto CI = dyn_cast<ConstantInt>(Idx)) {
+        if (CI->isZero())
+          continue;
+        auto Offs = ElementSize * CI->getValue().sextOrTrunc(PtrSize);
+        auto OffsVal = DAG.getConstant(Offs, PtrTy);
+        N = DAG.getNode(ISD::ADD, getCurSDLoc(), N.getValueType(), N, OffsVal);
         continue;
----------------
rnk wrote:
> Too much auto is bad for readability.
Ok, I will change that, but I don't agree. From my point as a newbie it's better to have auto. Let's look at PtrTy variable: .getPointerTy() method returns value of type MVT and I have no idea that that mean. Moreover, in previous version it was converted implicitly to EVT. I don't care what C++ compiler type PtrTy has, I know it represents a pointer type (the name informs about that) and I want to know its size and create a constant of that type.

http://reviews.llvm.org/D8219

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list