[llvm] 81ac464 - [InstCombine] Support vectors in icmp of GEP fold
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 2 06:30:07 PST 2023
Author: Nikita Popov
Date: 2023-01-02T15:29:13+01:00
New Revision: 81ac46445b640ad48158ab84065858c873bc5b74
URL: https://github.com/llvm/llvm-project/commit/81ac46445b640ad48158ab84065858c873bc5b74
DIFF: https://github.com/llvm/llvm-project/commit/81ac46445b640ad48158ab84065858c873bc5b74.diff
LOG: [InstCombine] Support vectors in icmp of GEP fold
EmitGEPOffset() supports vector GEPs nowadays, so we don't need
any further code changes.
compare_gep_with_base_vector1 shows a weakness in folding the
resulting comparison if an index splat has to be performed.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/opaque-ptr.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 9801c727edde5..1c560c707e279 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -740,9 +740,7 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
RHS = RHS->stripPointerCasts();
Value *PtrBase = GEPLHS->getOperand(0);
- // FIXME: Support vector pointer GEPs.
- if (PtrBase == RHS && GEPLHS->isInBounds() &&
- !GEPLHS->getType()->isVectorTy()) {
+ if (PtrBase == RHS && GEPLHS->isInBounds()) {
// ((gep Ptr, OFFSET) cmp Ptr) ---> (OFFSET cmp 0).
Value *Offset = EmitGEPOffset(GEPLHS);
return new ICmpInst(ICmpInst::getSignedPredicate(Cond), Offset,
diff --git a/llvm/test/Transforms/InstCombine/opaque-ptr.ll b/llvm/test/Transforms/InstCombine/opaque-ptr.ll
index a1e67e5a914b0..da69f7dd3b2c1 100644
--- a/llvm/test/Transforms/InstCombine/opaque-ptr.ll
+++ b/llvm/test/Transforms/InstCombine/opaque-ptr.ll
@@ -334,8 +334,10 @@ define i1 @compare_gep_with_base(ptr %p, i64 %idx) {
define <2 x i1> @compare_gep_with_base_vector1(<2 x ptr> %p, i64 %idx) {
; CHECK-LABEL: @compare_gep_with_base_vector1(
-; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, <2 x ptr> [[P:%.*]], i64 [[IDX:%.*]]
-; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x ptr> [[GEP]], [[P]]
+; CHECK-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <2 x i64> poison, i64 [[IDX:%.*]], i64 0
+; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i64> [[DOTSPLATINSERT]], <i64 2, i64 0>
+; CHECK-NEXT: [[TMP2:%.*]] = icmp eq <2 x i64> [[TMP1]], zeroinitializer
+; CHECK-NEXT: [[C:%.*]] = shufflevector <2 x i1> [[TMP2]], <2 x i1> poison, <2 x i32> zeroinitializer
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%gep = getelementptr inbounds i32, <2 x ptr> %p, i64 %idx
@@ -345,8 +347,7 @@ define <2 x i1> @compare_gep_with_base_vector1(<2 x ptr> %p, i64 %idx) {
define <2 x i1> @compare_gep_with_base_vector2(<2 x ptr> %p, <2 x i64> %idx) {
; CHECK-LABEL: @compare_gep_with_base_vector2(
-; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, <2 x ptr> [[P:%.*]], <2 x i64> [[IDX:%.*]]
-; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x ptr> [[GEP]], [[P]]
+; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i64> [[IDX:%.*]], zeroinitializer
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%gep = getelementptr inbounds i32, <2 x ptr> %p, <2 x i64> %idx
More information about the llvm-commits
mailing list