[llvm] 4dd540d - [BasicAA] Add missing inbounds to tests (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 29 10:05:47 PDT 2021


Author: Nikita Popov
Date: 2021-10-29T19:05:39+02:00
New Revision: 4dd540d9c89810b5b41d633e136bf02f890113f0

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

LOG: [BasicAA] Add missing inbounds to tests (NFC)

Add missing inbounds to tests that are not correct without it due
to possibility of offset overflow.

inbounds: https://alive2.llvm.org/ce/z/LC8G9_
w/o inbounds: https://alive2.llvm.org/ce/z/ErrJVW

Added: 
    

Modified: 
    llvm/test/Analysis/BasicAA/returned.ll
    llvm/test/Analysis/BasicAA/struct-geps.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/BasicAA/returned.ll b/llvm/test/Analysis/BasicAA/returned.ll
index 1c158e4d1889..83f638a1a482 100644
--- a/llvm/test/Analysis/BasicAA/returned.ll
+++ b/llvm/test/Analysis/BasicAA/returned.ll
@@ -29,10 +29,10 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 ; CHECK-DAG: MustAlias: i32* %y, i80* %y_10
 
 define void @test_simple(%struct* %st, i64 %i, i64 %j, i64 %k) {
-  %x = getelementptr %struct, %struct* %st, i64 %i, i32 0
-  %y = getelementptr %struct, %struct* %st, i64 %j, i32 1
+  %x = getelementptr inbounds %struct, %struct* %st, i64 %i, i32 0
+  %y = getelementptr inbounds %struct, %struct* %st, i64 %j, i32 1
   %sta = call %struct* @func2(%struct* %st)
-  %z = getelementptr %struct, %struct* %sta, i64 %k, i32 2
+  %z = getelementptr inbounds %struct, %struct* %sta, i64 %k, i32 2
   %y_12 = bitcast i32* %y to %struct*
   %y_10 = bitcast i32* %y to i80*
   %ya = call i32* @func1(i32* %y)

diff  --git a/llvm/test/Analysis/BasicAA/struct-geps.ll b/llvm/test/Analysis/BasicAA/struct-geps.ll
index 698e9281e136..56fdd2b129b7 100644
--- a/llvm/test/Analysis/BasicAA/struct-geps.ll
+++ b/llvm/test/Analysis/BasicAA/struct-geps.ll
@@ -27,15 +27,24 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 ; CHECK-DAG: MustAlias: i32* %y, i80* %y_10
 
 define void @test_simple(%struct* %st, i64 %i, i64 %j, i64 %k) {
-  %x = getelementptr %struct, %struct* %st, i64 %i, i32 0
-  %y = getelementptr %struct, %struct* %st, i64 %j, i32 1
-  %z = getelementptr %struct, %struct* %st, i64 %k, i32 2
+  %x = getelementptr inbounds %struct, %struct* %st, i64 %i, i32 0
+  %y = getelementptr inbounds %struct, %struct* %st, i64 %j, i32 1
+  %z = getelementptr inbounds %struct, %struct* %st, i64 %k, i32 2
   %y_12 = bitcast i32* %y to %struct*
   %y_10 = bitcast i32* %y to i80*
   %y_8 = bitcast i32* %y to i64*
   ret void
 }
 
+; TODO: As the GEP is not inbounds, these pointers may alias due to overflow.
+; CHECK-LABEL: test_not_inbounds
+; CHECK-DAG: NoAlias: i32* %x, i32* %y
+define void @test_not_inbounds(%struct* %st, i64 %i, i64 %j, i64 %k) {
+  %x = getelementptr %struct, %struct* %st, i64 %i, i32 0
+  %y = getelementptr %struct, %struct* %st, i64 %j, i32 1
+  ret void
+}
+
 ; CHECK-LABEL: test_in_array
 
 ; CHECK-DAG: MayAlias: [1 x %struct]* %st, i32* %x
@@ -59,9 +68,9 @@ define void @test_simple(%struct* %st, i64 %i, i64 %j, i64 %k) {
 ; CHECK-DAG: MustAlias: i32* %y, i80* %y_10
 
 define void @test_in_array([1 x %struct]* %st, i64 %i, i64 %j, i64 %k, i64 %i1, i64 %j1, i64 %k1) {
-  %x = getelementptr [1 x %struct], [1 x %struct]* %st, i64 %i, i64 %i1, i32 0
-  %y = getelementptr [1 x %struct], [1 x %struct]* %st, i64 %j, i64 %j1, i32 1
-  %z = getelementptr [1 x %struct], [1 x %struct]* %st, i64 %k, i64 %k1, i32 2
+  %x = getelementptr inbounds [1 x %struct], [1 x %struct]* %st, i64 %i, i64 %i1, i32 0
+  %y = getelementptr inbounds [1 x %struct], [1 x %struct]* %st, i64 %j, i64 %j1, i32 1
+  %z = getelementptr inbounds [1 x %struct], [1 x %struct]* %st, i64 %k, i64 %k1, i32 2
   %y_12 = bitcast i32* %y to %struct*
   %y_10 = bitcast i32* %y to i80*
   %y_8 = bitcast i32* %y to i64*
@@ -91,9 +100,9 @@ define void @test_in_array([1 x %struct]* %st, i64 %i, i64 %j, i64 %k, i64 %i1,
 ; CHECK-DAG: MustAlias: i32* %y, i80* %y_10
 
 define void @test_in_3d_array([1 x [1 x [1 x %struct]]]* %st, i64 %i, i64 %j, i64 %k, i64 %i1, i64 %j1, i64 %k1, i64 %i2, i64 %j2, i64 %k2, i64 %i3, i64 %j3, i64 %k3) {
-  %x = getelementptr [1 x [1 x [1 x %struct]]], [1 x [1 x [1 x %struct]]]* %st, i64 %i, i64 %i1, i64 %i2, i64 %i3, i32 0
-  %y = getelementptr [1 x [1 x [1 x %struct]]], [1 x [1 x [1 x %struct]]]* %st, i64 %j, i64 %j1, i64 %j2, i64 %j3, i32 1
-  %z = getelementptr [1 x [1 x [1 x %struct]]], [1 x [1 x [1 x %struct]]]* %st, i64 %k, i64 %k1, i64 %k2, i64 %k3, i32 2
+  %x = getelementptr inbounds [1 x [1 x [1 x %struct]]], [1 x [1 x [1 x %struct]]]* %st, i64 %i, i64 %i1, i64 %i2, i64 %i3, i32 0
+  %y = getelementptr inbounds [1 x [1 x [1 x %struct]]], [1 x [1 x [1 x %struct]]]* %st, i64 %j, i64 %j1, i64 %j2, i64 %j3, i32 1
+  %z = getelementptr inbounds [1 x [1 x [1 x %struct]]], [1 x [1 x [1 x %struct]]]* %st, i64 %k, i64 %k1, i64 %k2, i64 %k3, i32 2
   %y_12 = bitcast i32* %y to %struct*
   %y_10 = bitcast i32* %y to i80*
   %y_8 = bitcast i32* %y to i64*
@@ -116,13 +125,13 @@ define void @test_in_3d_array([1 x [1 x [1 x %struct]]]* %st, i64 %i, i64 %j, i6
 ; CHECK-DAG: NoAlias: i32* %y2, i32* %z
 
 define void @test_same_underlying_object_same_indices(%struct* %st, i64 %i, i64 %j, i64 %k) {
-  %st2 = getelementptr %struct, %struct* %st, i32 10
-  %x2 = getelementptr %struct, %struct* %st2, i64 %i, i32 0
-  %y2 = getelementptr %struct, %struct* %st2, i64 %j, i32 1
-  %z2 = getelementptr %struct, %struct* %st2, i64 %k, i32 2
-  %x = getelementptr %struct, %struct* %st, i64 %i, i32 0
-  %y = getelementptr %struct, %struct* %st, i64 %j, i32 1
-  %z = getelementptr %struct, %struct* %st, i64 %k, i32 2
+  %st2 = getelementptr inbounds %struct, %struct* %st, i32 10
+  %x2 = getelementptr inbounds %struct, %struct* %st2, i64 %i, i32 0
+  %y2 = getelementptr inbounds %struct, %struct* %st2, i64 %j, i32 1
+  %z2 = getelementptr inbounds %struct, %struct* %st2, i64 %k, i32 2
+  %x = getelementptr inbounds %struct, %struct* %st, i64 %i, i32 0
+  %y = getelementptr inbounds %struct, %struct* %st, i64 %j, i32 1
+  %z = getelementptr inbounds %struct, %struct* %st, i64 %k, i32 2
   ret void
 }
 
@@ -142,13 +151,13 @@ define void @test_same_underlying_object_same_indices(%struct* %st, i64 %i, i64
 ; CHECK-DAG: NoAlias: i32* %y2, i32* %z
 
 define void @test_same_underlying_object_
diff erent_indices(%struct* %st, i64 %i1, i64 %j1, i64 %k1, i64 %i2, i64 %k2, i64 %j2) {
-  %st2 = getelementptr %struct, %struct* %st, i32 10
-  %x2 = getelementptr %struct, %struct* %st2, i64 %i2, i32 0
-  %y2 = getelementptr %struct, %struct* %st2, i64 %j2, i32 1
-  %z2 = getelementptr %struct, %struct* %st2, i64 %k2, i32 2
-  %x = getelementptr %struct, %struct* %st, i64 %i1, i32 0
-  %y = getelementptr %struct, %struct* %st, i64 %j1, i32 1
-  %z = getelementptr %struct, %struct* %st, i64 %k1, i32 2
+  %st2 = getelementptr inbounds %struct, %struct* %st, i32 10
+  %x2 = getelementptr inbounds %struct, %struct* %st2, i64 %i2, i32 0
+  %y2 = getelementptr inbounds %struct, %struct* %st2, i64 %j2, i32 1
+  %z2 = getelementptr inbounds %struct, %struct* %st2, i64 %k2, i32 2
+  %x = getelementptr inbounds %struct, %struct* %st, i64 %i1, i32 0
+  %y = getelementptr inbounds %struct, %struct* %st, i64 %j1, i32 1
+  %z = getelementptr inbounds %struct, %struct* %st, i64 %k1, i32 2
   ret void
 }
 
@@ -158,8 +167,8 @@ define void @test_same_underlying_object_
diff erent_indices(%struct* %st, i64 %i1
 ; CHECK-LABEL: test_struct_in_array
 ; CHECK-DAG: MustAlias: i32* %x, i32* %y
 define void @test_struct_in_array(%struct2* %st, i64 %i, i64 %j, i64 %k) {
-  %x = getelementptr %struct2, %struct2* %st, i32 0, i32 1, i32 1, i32 0
-  %y = getelementptr %struct2, %struct2* %st, i32 0, i32 0, i32 1, i32 1
+  %x = getelementptr inbounds %struct2, %struct2* %st, i32 0, i32 1, i32 1, i32 0
+  %y = getelementptr inbounds %struct2, %struct2* %st, i32 0, i32 0, i32 1, i32 1
   ret void
 }
 
@@ -167,7 +176,7 @@ define void @test_struct_in_array(%struct2* %st, i64 %i, i64 %j, i64 %k) {
 ; CHECK-LABEL: test_
diff erent_index_types
 ; CHECK: MustAlias: i16* %tmp1, i16* %tmp2
 define void @test_
diff erent_index_types([2 x i16]* %arr) {
-  %tmp1 = getelementptr [2 x i16], [2 x i16]* %arr, i16 0, i32 1
-  %tmp2 = getelementptr [2 x i16], [2 x i16]* %arr, i16 0, i16 1
+  %tmp1 = getelementptr inbounds [2 x i16], [2 x i16]* %arr, i16 0, i32 1
+  %tmp2 = getelementptr inbounds [2 x i16], [2 x i16]* %arr, i16 0, i16 1
   ret void
 }


        


More information about the llvm-commits mailing list