[llvm] ef64ba8 - [InstCombine] GEPOperator::accumulateConstantOffset does not support scalable vectors
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 18 07:59:14 PDT 2020
Author: Sander de Smalen
Date: 2020-03-18T14:58:46Z
New Revision: ef64ba831194c7deac8882a325ea9bea64eb612a
URL: https://github.com/llvm/llvm-project/commit/ef64ba831194c7deac8882a325ea9bea64eb612a
DIFF: https://github.com/llvm/llvm-project/commit/ef64ba831194c7deac8882a325ea9bea64eb612a.diff
LOG: [InstCombine] GEPOperator::accumulateConstantOffset does not support scalable vectors
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>*
Reviewers: efriedma, ctetreau
Reviewed By: efriedma
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76236
Added:
Modified:
llvm/lib/IR/Operator.cpp
llvm/test/Transforms/InstCombine/gep-vector.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/Operator.cpp b/llvm/lib/IR/Operator.cpp
index 8ba68674d50e..54b7d56e6353 100644
--- a/llvm/lib/IR/Operator.cpp
+++ b/llvm/lib/IR/Operator.cpp
@@ -45,6 +45,11 @@ bool GEPOperator::accumulateConstantOffset(const DataLayout &DL,
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();
diff --git a/llvm/test/Transforms/InstCombine/gep-vector.ll b/llvm/test/Transforms/InstCombine/gep-vector.ll
index 432da0aed2dc..83b8697c3b28 100644
--- a/llvm/test/Transforms/InstCombine/gep-vector.ll
+++ b/llvm/test/Transforms/InstCombine/gep-vector.ll
@@ -134,3 +134,24 @@ define i32 addrspace(3)* @inbounds_bitcast_vec_to_array_addrspace_matching_alloc
%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
+}
More information about the llvm-commits
mailing list