[llvm] d222bab - [InstCombine] Handle GEP scalar/vector base mismatch (PR55363)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue May 10 02:26:51 PDT 2022


Author: Nikita Popov
Date: 2022-05-10T11:26:43+02:00
New Revision: d222bab6720ad8dbaf2a307956faf228918e10d2

URL: https://github.com/llvm/llvm-project/commit/d222bab6720ad8dbaf2a307956faf228918e10d2
DIFF: https://github.com/llvm/llvm-project/commit/d222bab6720ad8dbaf2a307956faf228918e10d2.diff

LOG: [InstCombine] Handle GEP scalar/vector base mismatch (PR55363)

30a12f3f6322399185fdceffe176152a58bb84ae switched the type check
to use the GEP result type rather than the GEP operand type.
However, the GEP result types may match even if the operand types
don't, in case GEPs with scalar/vector base and vector index
are compared.

Fixes https://github.com/llvm/llvm-project/issues/55363.

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 4cc377c930c1b..4511b661357b8 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -889,7 +889,8 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
     if (PtrBase != GEPRHS->getOperand(0)) {
       bool IndicesTheSame =
           GEPLHS->getNumOperands() == GEPRHS->getNumOperands() &&
-          GEPLHS->getType() == GEPRHS->getType() &&
+          GEPLHS->getPointerOperand()->getType() ==
+              GEPRHS->getPointerOperand()->getType() &&
           GEPLHS->getSourceElementType() == GEPRHS->getSourceElementType();
       if (IndicesTheSame)
         for (unsigned i = 1, e = GEPLHS->getNumOperands(); i != e; ++i)

diff  --git a/llvm/test/Transforms/InstCombine/opaque-ptr.ll b/llvm/test/Transforms/InstCombine/opaque-ptr.ll
index bb68bb9df5e36..c842dcb16c410 100644
--- a/llvm/test/Transforms/InstCombine/opaque-ptr.ll
+++ b/llvm/test/Transforms/InstCombine/opaque-ptr.ll
@@ -334,6 +334,19 @@ define i1 @compare_geps_same_indices_
diff erent_types(ptr %a, ptr %b, i64 %idx) {
   ret i1 %c
 }
 
+define <4 x i1> @compare_geps_same_indices_scalar_vector_base_mismatch(ptr %ptr, <4 x ptr> %ptrs) {
+; CHECK-LABEL: @compare_geps_same_indices_scalar_vector_base_mismatch(
+; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr i16, <4 x ptr> [[PTRS:%.*]], <4 x i64> <i64 1, i64 2, i64 3, i64 4>
+; CHECK-NEXT:    [[GEP2:%.*]] = getelementptr i16, ptr [[PTR:%.*]], <4 x i64> <i64 1, i64 2, i64 3, i64 4>
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq <4 x ptr> [[GEP1]], [[GEP2]]
+; CHECK-NEXT:    ret <4 x i1> [[CMP]]
+;
+  %gep1 = getelementptr i16, <4 x ptr> %ptrs, <4 x i64> <i64 1, i64 2, i64 3, i64 4>
+  %gep2 = getelementptr i16, ptr %ptr, <4 x i64> <i64 1, i64 2, i64 3, i64 4>
+  %cmp = icmp eq <4 x ptr> %gep1, %gep2
+  ret <4 x i1> %cmp
+}
+
 define ptr @indexed_compare(ptr %A, i64 %offset) {
 ; CHECK-LABEL: @indexed_compare(
 ; CHECK-NEXT:  entry:


        


More information about the llvm-commits mailing list