[InstCombine] Add tests for icmp of vector GEP (NFC)
authorNikita Popov <npopov@redhat.com>
Mon, 2 Jan 2023 14:17:34 +0000 (15:17 +0100)
committerNikita Popov <npopov@redhat.com>
Mon, 2 Jan 2023 14:18:19 +0000 (15:18 +0100)
These show up as regressions with opaque pointers.

llvm/test/Transforms/InstCombine/opaque-ptr.ll

index 2bfbeb5..a1e67e5 100644 (file)
@@ -322,6 +322,38 @@ define i1 @compare_geps_same_indices_different_types(ptr %a, ptr %b, i64 %idx) {
   ret i1 %c
 }
 
+define i1 @compare_gep_with_base(ptr %p, i64 %idx) {
+; CHECK-LABEL: @compare_gep_with_base(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq i64 [[IDX:%.*]], 0
+; CHECK-NEXT:    ret i1 [[C]]
+;
+  %gep = getelementptr inbounds i32, ptr %p, i64 %idx
+  %c = icmp eq ptr %gep, %p
+  ret i1 %c
+}
+
+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:    ret <2 x i1> [[C]]
+;
+  %gep = getelementptr inbounds i32, <2 x ptr> %p, i64 %idx
+  %c = icmp eq <2 x ptr> %gep, %p
+  ret <2 x i1> %c
+}
+
+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:    ret <2 x i1> [[C]]
+;
+  %gep = getelementptr inbounds i32, <2 x ptr> %p, <2 x i64> %idx
+  %c = icmp eq <2 x ptr> %gep, %p
+  ret <2 x 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>