forked from OSchip/llvm-project
[InstSimplify] Handle vector GEP when simplifying zero indices
If the base is a scalar and the index is a vector, we can't simplify, as this is effectively a splat operation.
This commit is contained in:
parent
d7645f4ef8
commit
02c2106002
|
@ -4499,7 +4499,8 @@ static Value *SimplifyGEPInst(Type *SrcTy, Value *Ptr,
|
|||
|
||||
// For opaque pointers an all-zero GEP is a no-op. For typed pointers,
|
||||
// it may be equivalent to a bitcast.
|
||||
if (Ptr->getType()->isOpaquePointerTy() &&
|
||||
if (Ptr->getType()->getScalarType()->isOpaquePointerTy() &&
|
||||
Ptr->getType() == GEPTy &&
|
||||
all_of(Indices, [](const auto *V) { return match(V, m_Zero()); }))
|
||||
return Ptr;
|
||||
|
||||
|
|
|
@ -26,3 +26,28 @@ define ptr @gep_non_zero_indices2(ptr %p) {
|
|||
%p2 = getelementptr { i64, i64 }, ptr %p, i64 1, i32 0
|
||||
ret ptr %p2
|
||||
}
|
||||
|
||||
define <2 x ptr> @scalar_base_vector_index(ptr %p) {
|
||||
; CHECK-LABEL: @scalar_base_vector_index(
|
||||
; CHECK-NEXT: [[G:%.*]] = getelementptr { i64, i64 }, ptr [[P:%.*]], <2 x i64> zeroinitializer, i32 0
|
||||
; CHECK-NEXT: ret <2 x ptr> [[G]]
|
||||
;
|
||||
%g = getelementptr { i64, i64 }, ptr %p, <2 x i64> zeroinitializer, i32 0
|
||||
ret <2 x ptr> %g
|
||||
}
|
||||
|
||||
define <2 x ptr> @vector_base_vector_index(<2 x ptr> %p) {
|
||||
; CHECK-LABEL: @vector_base_vector_index(
|
||||
; CHECK-NEXT: ret <2 x ptr> [[P:%.*]]
|
||||
;
|
||||
%g = getelementptr { i64, i64 }, <2 x ptr> %p, <2 x i64> zeroinitializer, i32 0
|
||||
ret <2 x ptr> %g
|
||||
}
|
||||
|
||||
define <2 x ptr> @vector_base_scalar_index(<2 x ptr> %p) {
|
||||
; CHECK-LABEL: @vector_base_scalar_index(
|
||||
; CHECK-NEXT: ret <2 x ptr> [[P:%.*]]
|
||||
;
|
||||
%g = getelementptr { i64, i64 }, <2 x ptr> %p, i64 0, i32 0
|
||||
ret <2 x ptr> %g
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue