[Beignet] [PATCH v2 2/2] GBE: optimize GEP constant offset calculation.

Zhigang Gong zhigang.gong at intel.com
Mon Dec 1 22:42:30 PST 2014


If the type is array or vector, we do not need to iterate each element.
We can compute it directly.

v2:
Use more generic SequentialType and StructType to identify whether
we can compute the offset directly.

Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
 backend/src/llvm/llvm_passes.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp
index 24ad9d0..ff9ab76 100644
--- a/backend/src/llvm/llvm_passes.cpp
+++ b/backend/src/llvm/llvm_passes.cpp
@@ -275,7 +275,7 @@ namespace gbe
     Value* currentAddrInst = 
       new PtrToIntInst(parentPointer, IntegerType::get(GEPInst->getContext(), ptrSize), "", GEPInst);
 
-    uint32_t constantOffset = 0;
+    int32_t constantOffset = 0;
 
     for(uint32_t op=1; op<GEPInst->getNumOperands(); ++op)
     {
@@ -286,15 +286,17 @@ namespace gbe
         int32_t offset = 0;
         TypeIndex = ConstOP->getZExtValue();
         int32_t step = TypeIndex > 0 ? 1 : -1;
-        if (op == 1) {
+        SequentialType * seqType = dyn_cast<SequentialType>(CompTy);
+        if (seqType != NULL) {
           if (TypeIndex != 0) {
-            Type *elementType = (cast<PointerType>(parentPointer->getType()))->getElementType();
+            Type *elementType = seqType->getElementType();
             uint32_t elementSize = getTypeByteSize(unit, elementType);
             uint32_t align = getAlignmentByte(unit, elementType);
             elementSize += getPadding(elementSize, align);
             offset += elementSize * TypeIndex;
           }
         } else {
+          GBE_ASSERT(CompTy->isStructTy());
           for(int32_t ty_i=0; ty_i != TypeIndex; ty_i += step)
           {
             Type* elementType = CompTy->getTypeAtIndex(ty_i);
-- 
1.8.3.2



More information about the Beignet mailing list