[PATCH] D76236: [InstCombine] GEPOperator::accumulateConstantOffset does not support scalable vectors

Sander de Smalen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 18 08:09:24 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGef64ba831194: [InstCombine] GEPOperator::accumulateConstantOffset does not support scalable… (authored by sdesmalen).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76236/new/

https://reviews.llvm.org/D76236

Files:
  llvm/lib/IR/Operator.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
@@ -134,3 +134,24 @@
   %gep = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* %asc, i64 %y, i64 %z
   ret i32 addrspace(3)* %gep
 }
+
+; 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
+  %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]]
+  %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
+}
Index: llvm/lib/IR/Operator.cpp
===================================================================
--- llvm/lib/IR/Operator.cpp
+++ llvm/lib/IR/Operator.cpp
@@ -45,6 +45,11 @@
     if (OpC->isZero())
       continue;
 
+    // Scalable vectors have are multiplied by a runtime constant.
+    if (auto *VecTy = dyn_cast<VectorType>(GTI.getIndexedType()))
+      if (VecTy->isScalable())
+        return false;
+
     // Handle a struct index, which adds its field offset to the pointer.
     if (StructType *STy = GTI.getStructTypeOrNull()) {
       unsigned ElementIdx = OpC->getZExtValue();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76236.251088.patch
Type: text/x-patch
Size: 1964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200318/96fd2af2/attachment.bin>


More information about the llvm-commits mailing list