[PATCH] D82375: [SVE] Fix bug in DataLayout::getIndexType

David Sherwood via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 23 06:21:54 PDT 2020


david-arm created this revision.
david-arm added reviewers: sdesmalen, ctetreau, kmclaughlin.
Herald added subscribers: llvm-commits, psnobl, arphaman, rkruppe, hiraditya, tschuett.
Herald added a reviewer: efriedma.
Herald added a project: LLVM.

We were previously assuming all vectors of indices were fixed
length, which is not true. I've added a new test that exposes
this code path.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82375

Files:
  llvm/lib/IR/DataLayout.cpp
  llvm/test/Transforms/InstCombine/gep-vector.ll


Index: llvm/test/Transforms/InstCombine/gep-vector.ll
===================================================================
--- llvm/test/Transforms/InstCombine/gep-vector.ll
+++ llvm/test/Transforms/InstCombine/gep-vector.ll
@@ -138,20 +138,36 @@
 ; Negative test - avoid doing bitcast on i8*, because '16' should be scaled by 'vscale'.
 
 define i8* @test_accumulate_constant_offset_vscale_nonzero(<vscale x 16 x i1> %pg, i8* %base) {
-; CHECK-LABEL: @test_accumulate_constant_offset_vscale_nonzero
-; CHECK-NEXT:   %bc = bitcast i8* %base to <vscale x 16 x i8>*
-; CHECK-NEXT:   %gep = getelementptr <vscale x 16 x i8>, <vscale x 16 x i8>* %bc, i64 1, i64 4
-; CHECK-NEXT:   ret i8* %gep
+; CHECK-LABEL: @test_accumulate_constant_offset_vscale_nonzero(
+; CHECK-NEXT:    [[BC:%.*]] = bitcast i8* [[BASE:%.*]] to <vscale x 16 x i8>*
+; CHECK-NEXT:    [[GEP:%.*]] = getelementptr <vscale x 16 x i8>, <vscale x 16 x i8>* [[BC]], i64 1, i64 4
+; CHECK-NEXT:    ret i8* [[GEP]]
+;
   %bc = bitcast i8* %base to <vscale x 16 x i8>*
   %gep = getelementptr <vscale x 16 x i8>, <vscale x 16 x i8>* %bc, i64 1, i64 4
   ret i8* %gep
 }
 
 define i8* @test_accumulate_constant_offset_vscale_zero(<vscale x 16 x i1> %pg, i8* %base) {
-; CHECK-LABEL: @test_accumulate_constant_offset_vscale_zero
-; CHECK-NEXT:   %[[RES:.*]] = getelementptr i8, i8* %base, i64 4
-; CHECK-NEXT:   ret i8* %[[RES]]
+; CHECK-LABEL: @test_accumulate_constant_offset_vscale_zero(
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr i8, i8* [[BASE:%.*]], i64 4
+; CHECK-NEXT:    ret i8* [[TMP1]]
+;
   %bc = bitcast i8* %base to <vscale x 16 x i8>*
   %gep = getelementptr <vscale x 16 x i8>, <vscale x 16 x i8>* %bc, i64 0, i64 4
   ret i8* %gep
 }
+
+ at GLOBAL = internal global i32 zeroinitializer
+
+define i32* @gep_cvbase_w_cv_idx(<vscale x 2 x i32*> %base, i64 %raw_addr) {
+; CHECK-LABEL: @gep_cvbase_w_cv_idx(
+; CHECK-NEXT:    ret i32* extractelement (<vscale x 2 x i32*> shufflevector (<vscale x 2 x i32*> insertelement (<vscale x 2 x i32*> undef, i32* @GLOBAL, i32 0), <vscale x 2 x i32*> undef, <vscale x 2 x i32> zeroinitializer), i32 0)
+;
+  %ins1 = insertelement <vscale x 2 x i32*> undef, i32* @GLOBAL, i32 0
+  %splat1 = shufflevector <vscale x 2 x i32*> %ins1, <vscale x 2 x i32*> undef, <vscale x 2 x i32> zeroinitializer
+  %gep = getelementptr i32, <vscale x 2 x i32*> %splat1, <vscale x 2 x i64> zeroinitializer
+  %ee = extractelement <vscale x 2 x i32*> %gep, i32 0
+  ret i32* %ee
+}
+
Index: llvm/lib/IR/DataLayout.cpp
===================================================================
--- llvm/lib/IR/DataLayout.cpp
+++ llvm/lib/IR/DataLayout.cpp
@@ -814,7 +814,7 @@
   unsigned NumBits = getIndexTypeSizeInBits(Ty);
   IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
   if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
-    return FixedVectorType::get(IntTy, VecTy->getNumElements());
+    return VectorType::get(IntTy, VecTy);
   return IntTy;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82375.272695.patch
Type: text/x-patch
Size: 2959 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200623/e7c95cab/attachment.bin>


More information about the llvm-commits mailing list