Skip to content

Commit ef64ba8

Browse files
committed
[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
1 parent c218664 commit ef64ba8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

llvm/lib/IR/Operator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ bool GEPOperator::accumulateConstantOffset(const DataLayout &DL,
4545
if (OpC->isZero())
4646
continue;
4747

48+
// Scalable vectors have are multiplied by a runtime constant.
49+
if (auto *VecTy = dyn_cast<VectorType>(GTI.getIndexedType()))
50+
if (VecTy->isScalable())
51+
return false;
52+
4853
// Handle a struct index, which adds its field offset to the pointer.
4954
if (StructType *STy = GTI.getStructTypeOrNull()) {
5055
unsigned ElementIdx = OpC->getZExtValue();

llvm/test/Transforms/InstCombine/gep-vector.ll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,24 @@ define i32 addrspace(3)* @inbounds_bitcast_vec_to_array_addrspace_matching_alloc
134134
%gep = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* %asc, i64 %y, i64 %z
135135
ret i32 addrspace(3)* %gep
136136
}
137+
138+
; Negative test - avoid doing bitcast on i8*, because '16' should be scaled by 'vscale'.
139+
140+
define i8* @test_accumulate_constant_offset_vscale_nonzero(<vscale x 16 x i1> %pg, i8* %base) {
141+
; CHECK-LABEL: @test_accumulate_constant_offset_vscale_nonzero
142+
; CHECK-NEXT: %bc = bitcast i8* %base to <vscale x 16 x i8>*
143+
; CHECK-NEXT: %gep = getelementptr <vscale x 16 x i8>, <vscale x 16 x i8>* %bc, i64 1, i64 4
144+
; CHECK-NEXT: ret i8* %gep
145+
%bc = bitcast i8* %base to <vscale x 16 x i8>*
146+
%gep = getelementptr <vscale x 16 x i8>, <vscale x 16 x i8>* %bc, i64 1, i64 4
147+
ret i8* %gep
148+
}
149+
150+
define i8* @test_accumulate_constant_offset_vscale_zero(<vscale x 16 x i1> %pg, i8* %base) {
151+
; CHECK-LABEL: @test_accumulate_constant_offset_vscale_zero
152+
; CHECK-NEXT: %[[RES:.*]] = getelementptr i8, i8* %base, i64 4
153+
; CHECK-NEXT: ret i8* %[[RES]]
154+
%bc = bitcast i8* %base to <vscale x 16 x i8>*
155+
%gep = getelementptr <vscale x 16 x i8>, <vscale x 16 x i8>* %bc, i64 0, i64 4
156+
ret i8* %gep
157+
}

0 commit comments

Comments
 (0)