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

Sander de Smalen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 16 10:24:14 PDT 2020


sdesmalen created this revision.
sdesmalen added reviewers: efriedma, ctetreau.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

Avoid transforming:

%0 = bitcast i8* %base to <vscale x 16 x i8>*
 %1 = getelementptr <vscale x 16 x i8>, <vscale x 16 x i8>* %0, i64 1

into:

%0 = getelementptr i8, i8* %base, i64 16
 %1 = bitcast i8* %0 to <vscale x 16 x i8>*


Repository:
  rG LLVM Github Monorepo

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,15 @@
   %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 <vscale x 16 x i8> @test_accumulate_constant_offset_vscale(<vscale x 16 x i1> %pg, i8* %base) {
+; CHECK-LABEL: @test_accumulate_constant_offset_vscale
+; 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
+; CHECK-NEXT:   ret <vscale x 16 x 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
+  ret <vscale x 16 x i8> %gep
+}
Index: llvm/lib/IR/Operator.cpp
===================================================================
--- llvm/lib/IR/Operator.cpp
+++ llvm/lib/IR/Operator.cpp
@@ -39,6 +39,11 @@
 
   for (gep_type_iterator GTI = gep_type_begin(this), GTE = gep_type_end(this);
        GTI != GTE; ++GTI) {
+    // Scalable vectors have are multiplied by a runtime constant.
+    if (auto *VecTy = dyn_cast<VectorType>(GTI.getIndexedType()))
+      if (VecTy->isScalable())
+        return false;
+
     ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand());
     if (!OpC)
       return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76236.250592.patch
Type: text/x-patch
Size: 1559 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200316/3999e591/attachment.bin>


More information about the llvm-commits mailing list