[PATCH] D28013: [LLParser] Reader vector GEP ConsantExpr correctly

Michael Kuperstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 21 10:40:27 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL290261: [LLParser] Parse vector GEP constant expression correctly (authored by mkuper).

Changed prior to commit:
  https://reviews.llvm.org/D28013?vs=82244&id=82247#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28013

Files:
  llvm/trunk/lib/AsmParser/LLParser.cpp
  llvm/trunk/test/Assembler/getelementptr_vec_ce.ll
  llvm/trunk/test/Assembler/getelementptr_vec_ce2.ll


Index: llvm/trunk/test/Assembler/getelementptr_vec_ce2.ll
===================================================================
--- llvm/trunk/test/Assembler/getelementptr_vec_ce2.ll
+++ llvm/trunk/test/Assembler/getelementptr_vec_ce2.ll
@@ -0,0 +1,8 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+ at G = global [4 x [4 x i32]] zeroinitializer
+
+; CHECK: getelementptr vector index has a wrong number of elements
+define <4 x i32*> @foo() {
+  ret <4 x i32*> getelementptr ([4 x [4 x i32]], [4 x [4 x i32]]* @G, i32 0, <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <8 x i32> zeroinitializer)
+}
Index: llvm/trunk/test/Assembler/getelementptr_vec_ce.ll
===================================================================
--- llvm/trunk/test/Assembler/getelementptr_vec_ce.ll
+++ llvm/trunk/test/Assembler/getelementptr_vec_ce.ll
@@ -0,0 +1,9 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+ at G = global [4 x i32] zeroinitializer
+
+; CHECK-LABEL: @foo
+; CHECK: ret <4 x i32*> getelementptr ([4 x i32], [4 x i32]* @G, <4 x i32> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>)
+define <4 x i32*> @foo() {
+  ret <4 x i32*> getelementptr ([4 x i32], [4 x i32]* @G, i32 0, <4 x i32> <i32 0, i32 1, i32 2, i32 3>)
+}
Index: llvm/trunk/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp
+++ llvm/trunk/lib/AsmParser/LLParser.cpp
@@ -3193,20 +3193,23 @@
             ExplicitTypeLoc,
             "explicit pointee type doesn't match operand's pointee type");
 
+      unsigned GEPWidth =
+          BaseType->isVectorTy() ? BaseType->getVectorNumElements() : 0;
+
       ArrayRef<Constant *> Indices(Elts.begin() + 1, Elts.end());
       for (Constant *Val : Indices) {
         Type *ValTy = Val->getType();
         if (!ValTy->getScalarType()->isIntegerTy())
           return Error(ID.Loc, "getelementptr index must be an integer");
-        if (ValTy->isVectorTy() != BaseType->isVectorTy())
-          return Error(ID.Loc, "getelementptr index type missmatch");
         if (ValTy->isVectorTy()) {
           unsigned ValNumEl = ValTy->getVectorNumElements();
-          unsigned PtrNumEl = BaseType->getVectorNumElements();
-          if (ValNumEl != PtrNumEl)
+          if (GEPWidth && (ValNumEl != GEPWidth))
             return Error(
                 ID.Loc,
                 "getelementptr vector index has a wrong number of elements");
+          // GEPWidth may have been unknown because the base is a scalar,
+          // but it is known now.
+          GEPWidth = ValNumEl;
         }
       }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28013.82247.patch
Type: text/x-patch
Size: 2602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161221/7df15885/attachment.bin>


More information about the llvm-commits mailing list