[llvm] 02c2106 - [InstSimplify] Handle vector GEP when simplifying zero indices
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 11 01:56:52 PST 2022
Author: Nikita Popov
Date: 2022-03-11T10:56:44+01:00
New Revision: 02c21060029cff4fdfd9eab3011a1fec6de2f9a0
URL: https://github.com/llvm/llvm-project/commit/02c21060029cff4fdfd9eab3011a1fec6de2f9a0
DIFF: https://github.com/llvm/llvm-project/commit/02c21060029cff4fdfd9eab3011a1fec6de2f9a0.diff
LOG: [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.
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/opaque-ptr.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 78850e4627c20..77d600ac5883f 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -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;
diff --git a/llvm/test/Transforms/InstSimplify/opaque-ptr.ll b/llvm/test/Transforms/InstSimplify/opaque-ptr.ll
index 902b7c9392d51..48e75ac186ec7 100644
--- a/llvm/test/Transforms/InstSimplify/opaque-ptr.ll
+++ b/llvm/test/Transforms/InstSimplify/opaque-ptr.ll
@@ -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
+}
More information about the llvm-commits
mailing list